-
Notifications
You must be signed in to change notification settings - Fork 0
/
DisplaySSD1306.h
62 lines (53 loc) · 1.67 KB
/
DisplaySSD1306.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
#include <ArduinoWorkflow.h>
#include <SSD1306Ascii.h>
#include <SSD1306AsciiWire.h>
namespace AW {
class DisplaySSD1306 : public TActor {
public:
void SetContrast(uint8_t contrast) {
if (DisplayFound) {
Display.setContrast(contrast);
}
}
void DisplayOff() {
if (DisplayFound) {
Display.ssd1306WriteCmd(SSD1306_DISPLAYOFF);
}
}
void DisplayOn() {
if (DisplayFound) {
Display.ssd1306WriteCmd(SSD1306_DISPLAYON);
}
}
protected:
SSD1306AsciiWire Display;
bool DisplayFound = false;
void OnEvent(TEventPtr event, const TActorContext& context) override {
switch (event->EventID) {
case TEventBootstrap::EventID:
return OnBootstrap(static_cast<TEventBootstrap*>(event.Release()), context);
case TEventSerialData::EventID:
return OnSerialData(static_cast<TEventSerialData*>(event.Release()), context);
}
}
void OnBootstrap(TUniquePtr<TEventBootstrap>, const TActorContext&/* context*/) {
static const uint8_t address = 0x3c;
TWire::BeginTransmission(address);
if (TWire::EndTransmission()) {
DisplayFound = true;
Display.begin(&Adafruit128x64, address);
Display.setFont(Adafruit5x7);
Display.setScroll(true);
Display.clear();
}
}
void OnSerialData(TUniquePtr<TEventSerialData> event, const TActorContext&/* context*/) {
if (DisplayFound) {
for (unsigned int i = 0; i < event->Data.size(); ++i) {
Display.write(event->Data[i]);
}
Display.println();
}
}
};
}