-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirmataStatusLed.h
89 lines (72 loc) · 1.59 KB
/
FirmataStatusLed.h
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// FirmataStatusLed.h
#ifndef _FirmataStatusLed_h
#define _FirmataStatusLed_h
#include <ConfigurableFirmata.h>
#include <FirmataFeature.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
#define STATUS_IDLE 0
#define STATUS_COMMANDED 1
#define STATUS_LOADING_PROGRAM 2
#define STATUS_EXECUTING_PROGRAM 3
#define STATUS_ERROR 4
#define STATUS_NUMBER_OF_STEPS 4
/// <summary>
/// Simple component that reports the CPU status by some blinking patterns.
/// By default, the VERSION_BLINK_PIN is used, but any other digital pin can be choosen.
/// </summary>
class FirmataStatusLed : public FirmataFeature
{
private:
int _pin;
int _status;
uint32_t _startClock;
uint32_t _resetAt;
bool _isOn;
public:
static FirmataStatusLed* FirmataStatusLedInstance;
FirmataStatusLed(int pinNumber)
{
FirmataStatusLedInstance = this;
_pin = pinNumber;
Init();
}
/// <summary>
/// Use the default builtin LED for the status. If not defined, uses pin 13
/// </summary>
FirmataStatusLed()
{
FirmataStatusLedInstance = this;
#ifdef VERSION_BLINK_PIN
_pin = VERSION_BLINK_PIN;
#else
_pin = 13;
#endif
Init();
}
virtual void handleCapability(byte pin)
{
}
virtual boolean handlePinMode(byte pin, int mode)
{
setStatus(STATUS_COMMANDED, 500);
return false;
}
virtual boolean handleSysex(byte command, byte argc, byte* argv) override;
virtual void reset()
{
Init();
}
void setStatus(int status, int resetAfter);
int getStatus()
{
return _status;
}
virtual void report(bool elapsed) override;
private:
void Init();
};
#endif