-
Notifications
You must be signed in to change notification settings - Fork 0
/
statussimpleled.cpp
54 lines (49 loc) · 1.26 KB
/
statussimpleled.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
#include "statussimpleled.h"
#include <Arduino.h>
StatusSimpleLed::StatusSimpleLed(int ledPin) : _ledPin(ledPin)
{
// Configure LED output pin and set to a known state
pinMode(_ledPin, OUTPUT);
setLedOn(false);
}
void StatusSimpleLed::setBusy(bool busy)
{
if (busy) {
// Mark busyness by keeping LED on
setLedOn(true);
} else {
// Return to previous state
setState(_lastState);
}
}
void StatusSimpleLed::setState(States::State state)
{
switch (state) {
case States::State::Idle:
// Keep LED on when device first starts, to show readiness
setLedOn(true);
break;
case States::State::Linked:
case States::State::DisplayBlack:
case States::State::DisplayIdentify:
case States::State::DisplayDarkOrange:
case States::State::DisplayOrange:
case States::State::DisplayAmbient:
case States::State::DisplayWhite:
// Turn LED off in any state, to distinguish from busyness
setLedOn(false);
break;
}
// Track current state
_lastState = state;
}
void StatusSimpleLed::setLedOn(bool ledOn)
{
if (ledOn) {
// Turn LED on
digitalWrite(_ledPin, HIGH);
} else {
// Turn LED off
digitalWrite(_ledPin, LOW);
}
}