|
5 | 5 | #include "../Config.h" |
6 | 6 |
|
7 | 7 | OLEDDriver::OLEDDriver() : display(Config::OLED::WIDTH, Config::OLED::HEIGHT, &Wire, -1) { |
8 | | - currentType = DisplayDataType::INVALID; |
| 8 | + currentType = DisplayDataType::INVALID; |
9 | 9 | } |
10 | 10 |
|
11 | 11 | bool OLEDDriver::begin() { |
12 | | - if (!display.begin(SSD1306_SWITCHCAPVCC, Config::OLED::ADDRESS)) return false; |
| 12 | + if (!display.begin(SSD1306_SWITCHCAPVCC, Config::OLED::ADDRESS)) |
| 13 | + return false; |
13 | 14 |
|
14 | | - display.clearDisplay(); |
15 | | - display.display(); |
16 | | - display.setTextColor(SSD1306_WHITE); |
17 | | - display.setTextSize(1); |
| 15 | + display.clearDisplay(); |
| 16 | + display.display(); |
| 17 | + display.setTextColor(SSD1306_WHITE); |
| 18 | + display.setTextSize(1); |
18 | 19 |
|
19 | | - currentValue = ""; |
20 | | - return true; |
| 20 | + currentValue = ""; |
| 21 | + return true; |
21 | 22 | } |
22 | 23 |
|
23 | 24 | void OLEDDriver::clear() { |
24 | | - display.clearDisplay(); |
25 | | - display.display(); |
26 | | - currentValue = ""; |
27 | | - currentType = DisplayDataType::INVALID; |
| 25 | + display.clearDisplay(); |
| 26 | + display.display(); |
| 27 | + currentValue = ""; |
| 28 | + currentType = DisplayDataType::INVALID; |
28 | 29 | } |
29 | 30 |
|
30 | | -void OLEDDriver::drawTitle(const String& title) { |
31 | | - display.setTextSize(1); |
32 | | - display.setCursor(0, 0); |
33 | | - display.println(title); |
| 31 | +void OLEDDriver::drawTitle(const String &title) { |
| 32 | + display.setTextSize(1); |
| 33 | + display.setCursor(0, 0); |
| 34 | + display.println(title); |
34 | 35 | } |
35 | 36 |
|
36 | | -void OLEDDriver::drawUnit(const String& unit) { |
37 | | - if (unit.length() <= 0) return; |
| 37 | +void OLEDDriver::drawUnit(const String &unit) { |
| 38 | + if (unit.length() <= 0) |
| 39 | + return; |
38 | 40 |
|
39 | | - int16_t x1, y1; |
40 | | - uint16_t w, h; |
41 | | - display.setTextSize(1); |
42 | | - display.getTextBounds(unit, 0, 0, &x1, &y1, &w, &h); |
43 | | - display.setCursor(Config::OLED::WIDTH - w - 4, Config::OLED::HEIGHT - h - 2); |
44 | | - display.print(unit); |
| 41 | + int16_t x1, y1; |
| 42 | + uint16_t w, h; |
| 43 | + display.setTextSize(1); |
| 44 | + display.getTextBounds(unit, 0, 0, &x1, &y1, &w, &h); |
| 45 | + display.setCursor(Config::OLED::WIDTH - w - 4, Config::OLED::HEIGHT - h - 2); |
| 46 | + display.print(unit); |
45 | 47 | } |
46 | 48 |
|
47 | | -void OLEDDriver::drawValue(const String& value) { |
48 | | - int len = value.length(); |
49 | | - if (len < 5) |
50 | | - display.setTextSize(3); |
51 | | - else |
52 | | - display.setTextSize(2); |
| 49 | +void OLEDDriver::drawValue(const String &value) { |
| 50 | + int len = value.length(); |
| 51 | + if (len < 5) |
| 52 | + display.setTextSize(3); |
| 53 | + else |
| 54 | + display.setTextSize(2); |
53 | 55 |
|
54 | | - int16_t x1, y1; |
55 | | - uint16_t w, h; |
56 | | - display.getTextBounds(value, 0, 0, &x1, &y1, &w, &h); |
| 56 | + int16_t x1, y1; |
| 57 | + uint16_t w, h; |
| 58 | + display.getTextBounds(value, 0, 0, &x1, &y1, &w, &h); |
57 | 59 |
|
58 | | - int x = (Config::OLED::WIDTH - w) / 2; |
59 | | - int y = (Config::OLED::HEIGHT - h) / 2 + 8; // shift down a bit below title |
| 60 | + int x = (Config::OLED::WIDTH - w) / 2; |
| 61 | + int y = (Config::OLED::HEIGHT - h) / 2 + 8; // shift down a bit below title |
60 | 62 |
|
61 | | - display.setCursor(x, y); |
62 | | - display.print(value); |
| 63 | + display.setCursor(x, y); |
| 64 | + display.print(value); |
63 | 65 | } |
64 | 66 |
|
65 | | -void OLEDDriver::show(DisplayDataType type, const char* value) { |
66 | | - if (type == currentType && currentValue.equals(value)) return; |
| 67 | +void OLEDDriver::show(DisplayDataType type, const char *value) { |
| 68 | + if (type == currentType && currentValue.equals(value)) |
| 69 | + return; |
67 | 70 |
|
68 | | - currentType = type; |
69 | | - currentValue = String(value); |
| 71 | + currentType = type; |
| 72 | + currentValue = String(value); |
70 | 73 |
|
71 | | - display.clearDisplay(); |
| 74 | + display.clearDisplay(); |
72 | 75 |
|
73 | | - DisplayMetadata meta = getDisplayMetadata(type); |
74 | | - drawTitle(meta.title); |
75 | | - drawValue(currentValue); |
76 | | - drawUnit(meta.unit); |
| 76 | + DisplayMetadata meta = getDisplayMetadata(type); |
| 77 | + drawTitle(meta.title); |
| 78 | + drawValue(currentValue); |
| 79 | + drawUnit(meta.unit); |
77 | 80 |
|
78 | | - display.display(); |
| 81 | + display.display(); |
79 | 82 | } |
0 commit comments