-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlights.cpp
More file actions
177 lines (161 loc) · 5.49 KB
/
lights.cpp
File metadata and controls
177 lines (161 loc) · 5.49 KB
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
//////////////////////////////////////////////////////////////////////////////
// Model: fsa_eos.qm
// File: ./lights.cpp
//
// This file has been generated automatically by QP Modeler (QM).
// DO NOT EDIT THIS FILE MANUALLY.
//
// Please visit www.state-machine.com/qm for more information.
//////////////////////////////////////////////////////////////////////////////
#include "qp_port.h"
#include "bsp.h"
#include "fsa.h"
Q_DEFINE_THIS_FILE
#define LED_IDLE_PER_TIME BSP_TICKS_PER_SEC*2 //idle LED period time
#define LED_IDLE_ON_TIME BSP_TICKS_PER_SEC/50 //idle LED on time
#if LED_IDLE_ON_TIME < 2
# error LED Idle On Time: BSP_TICKS_PER_SEC too small
#endif
#define LED_ERR_PER_TIME BSP_TICKS_PER_SEC/5 //error LED period time
#define LED_ERR_ON_TIME BSP_TICKS_PER_SEC/10 //error LED on time
#define LED_WORKING_FLASH_TIME BSP_TICKS_PER_SEC/20
#define LED_WORKING_FLASH_CNT 1
//Lights class
// $(AOs::Lights) ............................................................
/// LED control
class Lights : public QActive {
private:
QTimeEvt led_per_timeout;
QTimeEvt led_on_timeout;
/// LED flash counter
uint8_t led_flash_cnt;
uint8_t period_time;
uint8_t on_time;
QTimeEvt led_work_timeout;
public:
Lights() : QActive((QStateHandler)&Lights::initial), led_per_timeout(LED_PER_TIMEOUT_SIG), led_on_timeout(LED_ON_TIMEOUT_SIG), led_work_timeout(LED_WORK_TIMEOUT_SIG) {
}
protected:
static QState initial(Lights *me, QEvent const *e);
static QState Blinker(Lights *me, QEvent const *e);
static QState led_periodic(Lights *me, QEvent const *e);
static QState led_working(Lights *me, QEvent const *e);
};
//Local objects
static Lights l_Lights;
//Global objects
QActive * const AO_Lights = &l_Lights;
//Lights class definition
// $(AOs::Lights) ............................................................
// $(AOs::Lights::Statechart) ................................................
// @(/2/2/7/0)
QState Lights::initial(Lights *me, QEvent const *e) {
return Q_TRAN(&Lights::Blinker);
}
// $(AOs::Lights::Statechart::Blinker) .......................................
QState Lights::Blinker(Lights *me, QEvent const *e) {
switch (e->sig) {
// @(/2/2/7/1)
case Q_ENTRY_SIG: {
//Notify(PSTR("Blinker entry\r\n"));
return Q_HANDLED();
}
// @(/2/2/7/1)
case Q_EXIT_SIG: {
//Notify(PSTR("Blinker exit\r\n"));
return Q_HANDLED();
}
// @(/2/2/7/1/0)
case LED_IDLE_SIG: {
me->period_time = LED_IDLE_PER_TIME;
me->on_time = LED_IDLE_ON_TIME;
return Q_TRAN(&Lights::led_periodic);
}
// @(/2/2/7/1/1)
case LED_WORKING_SIG: {
return Q_TRAN(&Lights::led_working);
}
// @(/2/2/7/1/2)
case LED_ERROR_SIG: {
me->period_time = LED_ERR_PER_TIME;
me->on_time = LED_ERR_ON_TIME;
return Q_TRAN(&Lights::led_periodic);
}
}
return Q_SUPER(&QHsm::top);
}
// $(AOs::Lights::Statechart::Blinker::led_periodic) .........................
QState Lights::led_periodic(Lights *me, QEvent const *e) {
switch (e->sig) {
// @(/2/2/7/1/3)
case Q_ENTRY_SIG: {
//Notify(PSTR("AO_Lights: LED Periodic Entry\r\n"));
LED_ON();
me->led_per_timeout.disarm();
me->led_on_timeout.disarm();
me->led_per_timeout.postIn(me, me->period_time);
me->led_on_timeout.postIn(me, me->on_time);
return Q_HANDLED();
}
// @(/2/2/7/1/3)
case Q_EXIT_SIG: {
//Notify(PSTR("AO_Lights: LED Periodic Exit\r\n"));
return Q_HANDLED();
}
// @(/2/2/7/1/3/0)
case LED_PER_TIMEOUT_SIG: {
LED_ON();
me->led_on_timeout.postIn(me, me->on_time);
me->led_per_timeout.postIn(me, me->period_time);
return Q_HANDLED();
}
// @(/2/2/7/1/3/1)
case LED_ON_TIMEOUT_SIG: {
LED_OFF();
return Q_HANDLED();
}
}
return Q_SUPER(&Lights::Blinker);
}
// $(AOs::Lights::Statechart::led_working) ...................................
QState Lights::led_working(Lights *me, QEvent const *e) {
switch (e->sig) {
// @(/2/2/7/2)
case Q_ENTRY_SIG: {
//Notify(PSTR("AO_Lights: LED Working Entry\r\n"));
me->led_work_timeout.postEvery(me, LED_WORKING_FLASH_TIME);
me->led_flash_cnt = LED_WORKING_FLASH_CNT*2 + 1;
return Q_HANDLED();
}
// @(/2/2/7/2)
case Q_EXIT_SIG: {
//Notify(PSTR("AO_Lights: LED Working Exit\r\n"));
me->led_work_timeout.disarm();
return Q_HANDLED();
}
// @(/2/2/7/2/0)
case LED_WORK_TIMEOUT_SIG: {
// @(/2/2/7/2/0/0)
if (me->led_flash_cnt != 0) {
--me->led_flash_cnt;
// @(/2/2/7/2/0/0/0)
if ((me->led_flash_cnt & 1 ) == 0) {
LED_ON();
return Q_HANDLED();
}
// @(/2/2/7/2/0/0/1)
else {
LED_OFF();
return Q_HANDLED();
}
}
// @(/2/2/7/2/0/1)
else {
LED_OFF();
//return Q_TRAN(me->led_history); //transition to history
return Q_TRAN(&Lights::led_periodic);
}
}
}
return Q_SUPER(&QHsm::top);
}