-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCLedTask.cpp
99 lines (72 loc) · 1.49 KB
/
CLedTask.cpp
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
/* A stm32duino eventloop
* Copyright (c) 2018 Andrew Goh
* Provided as-is, No warranties of any kind, Use at your own risk
* License: MIT
*/
#include "CLedTask.h"
#include <Arduino.h>
#include "../eventloop/ASyncWait.h"
#include "../eventloop/util.h"
#include "../mainloop.h"
CLedTask::CLedTask(void) {
state = LedState::Init;
hWaitLed = 0;
// duration for 1/2 period i.e. on or off
// 1 seconds initially
ledduration = 1000;
}
CLedTask::~CLedTask() {
}
bool CLedTask::handleEvent(Event& event) {
switch(event.event) {
case EventID::AppStart:
setup();
break;
case EventID::LedTaskLedOn:
ledon();
break;
case EventID::LedTaskLedOff:
ledoff();
break;
case EventID::LedTaskFaster:
faster();
break;
case EventID::LedTaskSlower:
slower();
break;
case EventID::LedTaskShowMem:
printmem();
break;
default:
break;
}
return true;
}
void CLedTask::setup() {
ledon();
}
void CLedTask::ledon() {
Event event;
digitalWrite(BOARD_LED_PIN, HIGH);
event.handle_id = EHandleID::LedTask;
event.event = EventID::LedTaskLedOff;
WaitMgr.await(ledduration,event,false);
}
void CLedTask::ledoff() {
Event event;
digitalWrite(BOARD_LED_PIN, LOW);
event.handle_id = EHandleID::LedTask;
event.event = EventID::LedTaskLedOn;
WaitMgr.await(ledduration,event,false);
}
void CLedTask::faster() {
ledduration /= 2;
}
void CLedTask::slower() {
ledduration *= 2;
}
void CLedTask::printmem() {
Serial.print(F("FreeStack:"));
Serial.println(FreeStack());
}
CLedTask LedTask;