-
Notifications
You must be signed in to change notification settings - Fork 1
/
obi-status-led.cpp
75 lines (67 loc) · 1.83 KB
/
obi-status-led.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
#include "obi-config.h"
#include "obi-status-led.h"
#include "obi-common.h"
static bool wifi_led_enabled_p = false;
static unsigned long last_action = 0;
static unsigned long last_test_millis = 0;
static unsigned long test_counter = 0;
void
status_led_handle (void)
{
if (cfg.suppress_led_blinking_p) {
digitalWrite (pin_led_wifi, LOW);
return;
}
switch (state) {
case st_config:
if (last_action + 500 < millis ()) {
wifi_led_enabled_p = ! wifi_led_enabled_p;
digitalWrite (pin_led_wifi, wifi_led_enabled_p? HIGH: LOW);
last_action = millis ();
}
break;
case st_connecting:
if (last_action + 100 < millis ()) {
wifi_led_enabled_p = ! wifi_led_enabled_p;
digitalWrite (pin_led_wifi, wifi_led_enabled_p? HIGH: LOW);
last_action = millis ();
}
break;
case st_flashing:
last_action = millis ();
digitalWrite (pin_led_wifi, HIGH);
break;
case st_running:
if (relay_get_state ()) {
if (wifi_led_enabled_p) {
if (last_action + 150 < millis ()) {
wifi_led_enabled_p = ! wifi_led_enabled_p;
digitalWrite (pin_led_wifi, wifi_led_enabled_p? HIGH: LOW);
last_action = millis ();
}
} else {
if (last_action + 850 < millis ()) {
wifi_led_enabled_p = ! wifi_led_enabled_p;
digitalWrite (pin_led_wifi, wifi_led_enabled_p? HIGH: LOW);
last_action = millis ();
}
}
} else {
if (wifi_led_enabled_p) {
if (last_action + 10 < millis ()) {
wifi_led_enabled_p = ! wifi_led_enabled_p;
digitalWrite (pin_led_wifi, wifi_led_enabled_p? HIGH: LOW);
last_action = millis ();
}
} else {
if (last_action + 990 < millis ()) {
wifi_led_enabled_p = ! wifi_led_enabled_p;
digitalWrite (pin_led_wifi, wifi_led_enabled_p? HIGH: LOW);
last_action = millis ();
}
}
}
break;
}
return;
}