|
4 | 4 |
|
5 | 5 | #include "../Config.h" |
6 | 6 |
|
7 | | -OLEDDriver::OLEDDriver() : display(Config::OLED::WIDTH, Config::OLED::HEIGHT, &Wire, -1) { |
8 | | - currentType = DisplayDataType::INVALID; |
9 | | -} |
| 7 | +namespace drivers { |
10 | 8 |
|
11 | | -bool OLEDDriver::begin() { |
12 | | - if (!display.begin(SSD1306_SWITCHCAPVCC, Config::OLED::ADDRESS)) |
13 | | - return false; |
| 9 | +OLEDDriver::OLEDDriver(TwoWire &i2c) : display(Config::OLED::WIDTH, Config::OLED::HEIGHT, &i2c, -1), wire(i2c) {} |
14 | 10 |
|
| 11 | +void OLEDDriver::begin() { |
| 12 | + if (!display.begin(SSD1306_SWITCHCAPVCC, Config::OLED::ADDRESS)) { |
| 13 | + // Initialization failed |
| 14 | + for (;;) |
| 15 | + ; |
| 16 | + } |
15 | 17 | display.clearDisplay(); |
16 | 18 | display.display(); |
17 | | - display.setTextColor(SSD1306_WHITE); |
18 | | - display.setTextSize(1); |
19 | | - |
20 | | - currentValue = ""; |
21 | | - return true; |
22 | 19 | } |
23 | 20 |
|
24 | | -void OLEDDriver::clear() { |
| 21 | +void OLEDDriver::show(application::DisplayDataType type, const char *value) { |
25 | 22 | display.clearDisplay(); |
| 23 | + |
| 24 | + drawHeader(); |
| 25 | + |
| 26 | + application::DisplayMetadata meta = application::getDisplayMetadata(type); |
| 27 | + drawMainArea(meta.title.c_str(), value, meta.unit.c_str()); |
| 28 | + |
| 29 | + drawFooter(); |
| 30 | + |
26 | 31 | display.display(); |
27 | | - currentValue = ""; |
28 | | - currentType = DisplayDataType::INVALID; |
29 | 32 | } |
30 | 33 |
|
31 | | -void OLEDDriver::drawTitle(const String &title) { |
| 34 | +void OLEDDriver::drawHeader() { |
32 | 35 | display.setTextSize(1); |
| 36 | + display.setTextColor(SSD1306_WHITE); |
33 | 37 | display.setCursor(0, 0); |
34 | | - display.println(title); |
| 38 | + display.print("GNSS ON"); |
| 39 | + |
| 40 | + drawSatelliteIcon(100, 0, satelliteCount); |
| 41 | + drawBatteryIcon(115, 0, batteryLevel); |
| 42 | + |
| 43 | + display.drawLine(0, 10, Config::OLED::WIDTH, 10, SSD1306_WHITE); |
35 | 44 | } |
36 | 45 |
|
37 | | -void OLEDDriver::drawUnit(const String &unit) { |
38 | | - if (unit.length() <= 0) |
39 | | - return; |
| 46 | +void OLEDDriver::drawFooter() { |
| 47 | + display.drawLine(0, Config::OLED::HEIGHT - 10, Config::OLED::WIDTH, Config::OLED::HEIGHT - 10, SSD1306_WHITE); |
40 | 48 |
|
41 | | - int16_t x1, y1; |
42 | | - uint16_t w, h; |
43 | 49 | 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); |
| 50 | + display.setCursor(0, Config::OLED::HEIGHT - 8); |
| 51 | + display.print("Ready"); // Placeholder for status |
47 | 52 | } |
48 | 53 |
|
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); |
| 54 | +void OLEDDriver::drawMainArea(const char *title, const char *value, const char *unit) { |
| 55 | + // Title |
| 56 | + display.setTextSize(1); |
| 57 | + display.setCursor(0, 14); |
| 58 | + display.print(title); |
55 | 59 |
|
| 60 | + // Value (Large) |
| 61 | + display.setTextSize(2); // Make value bigger |
56 | 62 | int16_t x1, y1; |
57 | 63 | uint16_t w, h; |
58 | 64 | display.getTextBounds(value, 0, 0, &x1, &y1, &w, &h); |
59 | | - |
60 | | - int x = (Config::OLED::WIDTH - w) / 2; |
61 | | - int y = (Config::OLED::HEIGHT - h) / 2 + 8; // shift down a bit below title |
62 | | - |
63 | | - display.setCursor(x, y); |
| 65 | + display.setCursor((Config::OLED::WIDTH - w) / 2, 28); |
64 | 66 | display.print(value); |
65 | | -} |
66 | | - |
67 | | -void OLEDDriver::show(DisplayDataType type, const char *value) { |
68 | | - if (type == currentType && currentValue.equals(value)) |
69 | | - return; |
70 | 67 |
|
71 | | - currentType = type; |
72 | | - currentValue = String(value); |
| 68 | + // Unit |
| 69 | + if (strlen(unit) > 0) { |
| 70 | + display.setTextSize(1); |
| 71 | + display.setCursor(Config::OLED::WIDTH - 24, 45); // Bottom right of main area |
| 72 | + display.print(unit); |
| 73 | + } |
| 74 | +} |
73 | 75 |
|
74 | | - display.clearDisplay(); |
| 76 | +void OLEDDriver::drawBatteryIcon(int x, int y, int percentage) { |
| 77 | + display.drawRect(x, y, 12, 6, SSD1306_WHITE); |
| 78 | + display.fillRect(x + 12, y + 2, 2, 2, SSD1306_WHITE); // Battery positive terminal |
75 | 79 |
|
76 | | - DisplayMetadata meta = getDisplayMetadata(type); |
77 | | - drawTitle(meta.title); |
78 | | - drawValue(currentValue); |
79 | | - drawUnit(meta.unit); |
| 80 | + int width = map(percentage, 0, 100, 0, 10); |
| 81 | + display.fillRect(x + 1, y + 1, width, 4, SSD1306_WHITE); |
| 82 | +} |
80 | 83 |
|
81 | | - display.display(); |
| 84 | +void OLEDDriver::drawSatelliteIcon(int x, int y, int count) { |
| 85 | + // Placeholder for satellite icon |
| 86 | + display.drawCircle(x + 3, y + 3, 2, SSD1306_WHITE); // Simple circle for now |
| 87 | + // Could display count next to it if needed |
82 | 88 | } |
| 89 | + |
| 90 | +} // namespace drivers |
0 commit comments