Skip to content

Commit a61e87f

Browse files
authored
Merge pull request #36 from bcmi-labs/led_feedback
LED feedback implementation
2 parents b4155bc + 36beb7b commit a61e87f

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

envie/target_init.cpp

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,54 @@ volatile uint8_t ledKeepValue = 0;
3030
volatile uint8_t ledTargetValue = 20;
3131
volatile int8_t ledDirection = 1;
3232
volatile int divisor = 0;
33+
34+
DigitalOut green(PK_6, 1);
35+
DigitalOut blue(PK_7, 1);
36+
37+
Ticker swap_ticker;
3338
int envie_swap_index = -1;
3439

35-
DigitalOut led(PK_6);
40+
static inline void swap_feedback() {
41+
42+
static int blink_idx = 0;
43+
static int blink_state = 0;
44+
45+
if(envie_swap_index >= 0){
46+
switch(blink_state) {
47+
case 0: {
48+
if(blink_idx < envie_swap_index) {
49+
if(blue == 0){
50+
blue = 1;
51+
} else {
52+
blue = 0;
53+
blink_idx++;
54+
}
55+
} else {
56+
blink_idx = 0;
57+
blink_state = 1;
58+
}
59+
green = 1;
60+
}
61+
break;
62+
63+
case 1: {
64+
if(blink_idx < (15 - envie_swap_index)) {
65+
if(green == 0){
66+
green = 1;
67+
} else {
68+
green = 0;
69+
blink_idx++;
70+
}
71+
} else {
72+
blink_idx = 0;
73+
blink_state = 0;
74+
}
75+
blue = 1;
76+
}
77+
break;
78+
}
79+
}
80+
}
3681

3782
static inline void LED_pulse(DigitalOut* led)
3883
{
@@ -178,6 +223,7 @@ int target_init(void) {
178223
RTCSetBKPRegister(RTC_BKP_DR0, 0);
179224
HAL_FLASH_Lock();
180225
BOOT_LOG_DBG("Envie app magic 0x%x", RTCGetBKPRegister(RTC_BKP_DR0));
226+
swap_ticker.attach(&swap_feedback, 250ms);
181227
return 0;
182228

183229
} else {
@@ -242,7 +288,7 @@ void envie_loop(void) {
242288
HAL_PCD_IRQHandler(&hpcd);
243289
}
244290
#endif
245-
LED_pulse(&led);
291+
LED_pulse(&green);
246292
}
247293
}
248294

0 commit comments

Comments
 (0)