-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLED.cpp
More file actions
66 lines (51 loc) · 1.35 KB
/
Copy pathLED.cpp
File metadata and controls
66 lines (51 loc) · 1.35 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
/*
* Navinaut-AIS
* Code: https://github.com/andrejanowicz/Navinaut-AIS
* Shop: https://navinaut-ais.de/
*
* Author: Andre Janowicz, <aj@main-void.de>
* License: CC BY-SA Creative Commons Attribution-ShareAlike
* https://creativecommons.org/licenses/by-sa/4.0/
*
*/
#include <Arduino.h>
#include "defs.h"
#include "LED.h"
#include "BLE.h"
#include "wireless.h"
uint32_t last_tick = 0;
bool AIS_flash_pending = false;
uint32_t AIS_LED_start = 0;
uint8_t LED_pulse_length = 50;
void LED_setup(void) {
pinMode(PWR_LED, OUTPUT);
pinMode(CONNECTION_LED, OUTPUT);
digitalWrite(PWR_LED, LOW);
digitalWrite(CONNECTION_LED, LOW);
}
void LED_PWR_error_flash(void) {
digitalWrite(PWR_LED, HIGH);
delay(LED_pulse_length);
digitalWrite(PWR_LED, LOW);
delay(LED_pulse_length);
}
void LED_power_cycle(void) {
digitalWrite(PWR_LED, HIGH);
digitalWrite(CONNECTION_LED, HIGH);
delay(LED_pulse_length);
digitalWrite(PWR_LED, LOW);
digitalWrite(CONNECTION_LED, LOW);
delay(LED_pulse_length);
}
void LED_handle(void) {
uint32_t now = millis();
if (AIS_flash_pending) {
digitalWrite(PWR_LED, LOW);
AIS_flash_pending = false;
AIS_LED_start = now;
}
if (now - AIS_LED_start > LED_pulse_length) {
digitalWrite(PWR_LED, HIGH);
}
digitalWrite(CONNECTION_LED, BLE_device_connected | wireless_has_clients);
}