-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathled_blink.cpp
More file actions
55 lines (44 loc) · 1.16 KB
/
led_blink.cpp
File metadata and controls
55 lines (44 loc) · 1.16 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
#include <ch.h>
#include <hal.h>
#include "stdutil.h"
#include "led_blink.hpp"
#include <stdnoreturn.h>
#ifdef TRACE
#include <strings.h>
#endif
LedBlink ledBlink(LINE_LED_GREEN, 800, 0, 200);
uint8_t LedBlink::indexer = 0;
void LedBlink::launchThread(void)
{
chThdCreateStatic(waBlinker, sizeof(waBlinker), NORMALPRIO,
[] (void *arg) {
const LedBlink *led = static_cast<LedBlink *>(arg);
led->thdBlinkLed();
},
(void *) this);
}
_Noreturn void LedBlink::thdBlinkLed (void) const
{
// const LedBlink *ledBlink = (LedBlink *) arg;
// give uniq name to threads if several leds are used
#ifdef TRACE
*(index(name, '#')) = indexer++;
chRegSetThreadName (name);
#endif
while (true) {
for (uint32_t i=0; i< seq1Flashes; i++) {
palToggleLine(ledLine);
chThdSleepMilliseconds(msBetweenFlashes);
}
palClearLine(ledLine);
if (msBetweenSeq1Seq2) {
chThdSleepMilliseconds(msBetweenSeq1Seq2);
for (uint32_t i=0; i< seq2Flashes; i++) {
palToggleLine(ledLine);
chThdSleepMilliseconds(msBetweenFlashes);
}
palClearLine(ledLine);
}
chThdSleepMilliseconds(msBetweenSeqs);
}
}