27
27
#include " BlinkTask.h"
28
28
#include " SoftTimer.h"
29
29
30
+ #define BLINK_STATE_OFF 0
31
+ #define BLINK_STATE_ON 1
32
+ #define BLINK_STATE_WAIT 2
33
+
30
34
void BlinkTask::init (byte outPin, unsigned long onMs, unsigned long offMs, byte count, unsigned long delayMs) {
31
35
this ->onMs = onMs;
32
36
this ->offMs = offMs;
@@ -58,7 +62,7 @@ BlinkTask::BlinkTask(byte outPin, unsigned long onMs, unsigned long offMs, byte
58
62
}
59
63
60
64
void BlinkTask::start () {
61
- this ->_state = STATE_OFF ;
65
+ this ->_state = BLINK_STATE_OFF ;
62
66
this ->_counter = 0 ;
63
67
this ->setPeriodMs (0 );
64
68
SoftTimer.add (this );
@@ -76,15 +80,15 @@ void BlinkTask::stop() {
76
80
77
81
void BlinkTask::stepState (Task* task) {
78
82
BlinkTask* bt = (BlinkTask*)task;
79
- if (bt->_state == STATE_ON ) {
83
+ if (bt->_state == BLINK_STATE_ON ) {
80
84
// -- Turn off.
81
85
if (bt->onLevel == HIGH) {
82
86
*bt->_portRegister &= ~bt->_bitMask ;
83
87
} else {
84
88
*bt->_portRegister |= bt->_bitMask ;
85
89
}
86
90
bt->_counter += 1 ;
87
- bt->_state = STATE_OFF ;
91
+ bt->_state = BLINK_STATE_OFF ;
88
92
bt->setPeriodMs (bt->offMs );
89
93
}
90
94
else {
@@ -95,7 +99,7 @@ void BlinkTask::stepState(Task* task) {
95
99
} else {
96
100
*bt->_portRegister &= ~bt->_bitMask ;
97
101
}
98
- bt->_state = STATE_ON ;
102
+ bt->_state = BLINK_STATE_ON ;
99
103
bt->setPeriodMs (bt->onMs );
100
104
}
101
105
if ((bt->count > 0 ) && (bt->_counter >= bt->count )) {
@@ -104,7 +108,7 @@ void BlinkTask::stepState(Task* task) {
104
108
105
109
if (bt->delayMs > 0 ) {
106
110
// -- delay was defined.
107
- bt->_state = STATE_WAIT ;
111
+ bt->_state = BLINK_STATE_WAIT ;
108
112
bt->setPeriodMs (bt->delayMs );
109
113
} else {
110
114
bt->stop ();
0 commit comments