-
Notifications
You must be signed in to change notification settings - Fork 0
/
Light.h
193 lines (133 loc) · 6.22 KB
/
Light.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <Arduino.h>
#ifndef LIGHT_H_
#define LIGHT_H_
/* types of digitOUT devices */
#define DIGITOUT_ONOFF 0 /* Upon activation it changes the state of the output pin from on to off or vice-versa */
#define DIGITOUT_TIMER 1 /* Upon activation it changes the state of the output pin to on for an amount of time, after that it goes to off */
#define DIGITOUT_SIMPLE_HEAT 2 /* simple heat device, the output value is synced 1 to 1 with input value, unless override flag is set, then output changes based on ARiF commands */
#define DIGITOUT_COUNTER 4 /* the device is of type counter - it will count the state of the input changes to UP */
#define DIGITOUT_UNK 100 /* value to indicated failed/unreadable value */
/* other default values */
/* default timer for timer type lights (in seconds) */
#define DIGITOUT_DEFAULT_TIMER 30000
/* default central control setting */
#define DIGITOUT_CENTRAL_CTRL_ENABLE 1
#define DIGITOUT_CENTRAL_CTRL_DISABLE 0
#define DIGITOUT_CENTRAL_CTRL_UNK 100
/* central control light delay */
#define DIGITOUT_CENTRAL_CTRL_DELAY 200
/* counter type device default timer */
#define DIGITOUT_SWITCH_COUNTER_DEF_TIMER 60000
/* types of switches */
#define DIGITOUT_SWITCH_PRESS_HOLD 0 /* the value indicates that the switch is of type press-and-hold, so the value of the output must change immediately upon pressure */
#define DIGITOUT_SWITCH_PRESS_RELEASE 1 /* here the value indicates the switch is of type press-and-release, so the value of the output must change upon release of the switch (DEFAULT) */
#define DIGITOUT_SWITCH_HEAT_OVERRIDE_ON 2 /* The control of the simple heat output is based on the ARiF commands, the input pin is ignored */
#define DIGITOUT_SWITCH_HEAT_OVERRIDE_OFF 3 /* The control of the simple heat output is based on the input pin, (low to low, high to high) */
#define DIGITOUT_SWITCH_HEAT_TEMP_SENSOR 4 /* The control of the simple heat output is based on the temperature sensor */
#define DIGITOUT_SWITCH_COUNTER_UP 5 /* the input type for counter type */
/* values fro the overrideFlag variable */
#define DIGITOUT_OVERRIDE_OFF 0
#define DIGITOUT_OVERRIDE_ON 1
/* values for the ctrlON flag */
#define DIGITOUT_CTRLON_OFF 0
#define DIGITOUT_CTRLON_ON 1
class Light {
/* types definitions */
typedef struct t {
unsigned long tStart;
unsigned long tTimeout;
bool executed;
};
private:
/* Device type */
byte type;
/* timer value for DIGITOUT_TIMER type */
//unsigned long timer;
t onTimer;
/* ID of the device */
byte lightID;
/* vars holds the number of the input and output pins */
byte inPin;
byte outPin;
/* value used to track the input pin state */
byte inPinState;
/* value used to store the press-hold state of the pin */
bool inPinPressed;
/* value used to store the output state in a variable */
byte outPinState;
/* holds timer for button pressing - for measurement for how long the physical button is held pressed */
t buttonHold;
/* time needed to measure minimum time the button must be held to change it's state. Only for DIGITOUT_SWITCH_PRESS_HOLD */
t buttonPressHold;
/* functions to control time based execution */
bool Light::timeCheck(struct t *t );
void Light::timeRun(struct t *t);
/* holds state of device just being toggled */
bool justToggled;
static byte centralControlEnabled;
/* variable holding information if the switch is of type press-release or press-hold */
byte inputType;
/* override flag, used only for the DIGITOUT_SIMPLE_HEAT device type */
byte overrideFlag;
/* variable indicating if the devic is subject to ctrlON operation */
byte ctrlON;
/* counter for storing counting value of "ticks" */
unsigned long counter;
public:
static byte low;
static byte high;
/* Contructor takes lightID where the value cannot exceed the available in/out pins. */
Light();
/* Initialization function for the constructor */
void init(byte shadeID, byte type);
/* sets the light type */
void Light::setType(byte type);
/* returns the light type */
byte Light::getType();
/* sets the timer */
void Light::setTimer(unsigned long timer);
/* gets the timer value */
unsigned long Light::getTimer();
/* set the pin input type to press and hold - change of state on the moment of press */
void Light::setInputTypeHold();
/* set the pin input type to press and release - change of state on the moment of release */
void Light::setInputTypeRelease();
/* get the type of input pins mechanics */
byte Light::getInputType();
/* get devID value */
byte Light::getDevID();
/* function to check if the physical button was pressed - it can also detect a press-hold event */
byte Light::isPressed();
/* set the light to ON */
void Light::setON();
/* set the light to OFF */
void Light::setOFF();
/* toggle the light */
void Light::toggle();
/* returns true if the light has just been turned ON */
bool Light::justTurnedON();
/* returns true if the light has just been turned OFF */
bool Light::justTurnedOFF();
/* return true if the light is ON and false if it is OFF */
bool Light::getStatus();
/* reset the light device - this function supposed to be executed only when the mode is changed from lights to something else */
void Light::reset();
/* enables ctrlON for a device */
void Light::setCtrlONEnabled();
/* disables ctrlON for a device */
void Light::setCtrlONDisabled();
/* gets ctrlON value of a device */
byte Light::getCtrlON();
/* enable Central Control of the lights */
static void enableCentralCtrl();
/* disable Central Control of the lights */
static void disableCentralCtrl();
/* get the state of the Central Control of the lights */
static byte getCentralCtrl();
void Light::setInputTypeSimpleHeatOverrideOn();
void Light::setInputTypeSimpleHeatOverrideOff();
void Light::setInputTypeSimpleHeatTempSensor();
/* return the current counter value and reset the counter */
unsigned long Light::getCounterAndReset();
};
#endif