-
Notifications
You must be signed in to change notification settings - Fork 6
/
led.cpp
50 lines (41 loc) · 827 Bytes
/
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
#include <Arduino.h>
#include "hwdefs.h"
#include "led.h"
static ELedMode mode;
void LedInit(void)
{
pinMode(PIN_LED, OUTPUT);
LedSetMode(E_LEDMODE_TIME);
}
void LedSetMode(ELedMode newMode)
{
mode = newMode;
switch (mode) {
case E_LEDMODE_ON:
digitalWrite(PIN_LED, 0);
break;
case E_LEDMODE_OFF:
digitalWrite(PIN_LED, 1);
break;
default:
break;
}
}
void LedUpdate(unsigned long int time, float charge, float energy)
{
int tick;
switch (mode) {
case E_LEDMODE_TIME:
tick = time / 500000;
break;
case E_LEDMODE_CURRENT:
tick = charge / 0.1;
break;
case E_LEDMODE_OFF:
case E_LEDMODE_ON:
default:
// do nothing
return;
}
digitalWrite(PIN_LED, tick & 1);
}