25
25
#define OBS_DISPLAYS_H
26
26
27
27
#include < Arduino.h>
28
- #include < SSD1306 .h>
28
+ #include < U8g2lib .h>
29
29
30
30
#include " config.h"
31
31
#include " globals.h"
32
32
#include " gps.h"
33
33
#include " logo.h"
34
+ #include " fonts/fonts.h"
34
35
#include " sensor.h"
35
36
36
37
37
- extern const uint8_t Open_Sans_Regular_Plain_8[];
38
- // // this font is part of OLEDDisplay::OLEDDisplay :/
39
- // extern const uint8_t ArialMT_Plain_10[]; // :(
40
- extern const uint8_t Open_Sans_Regular_Plain_10[];
41
- extern const uint8_t Open_Sans_Regular_Plain_20[];
42
- extern const uint8_t Open_Sans_Regular_Plain_34[];
43
- extern const uint8_t Open_Sans_Regular_Plain_50[];
38
+ #define BLACK 0
39
+ #define WHITE 1
40
+
44
41
extern const uint8_t BatterieLogo1[];
45
42
extern const uint8_t TempLogo[];
46
43
47
- #define TINY_FONT Open_Sans_Regular_Plain_8
48
- #define SMALL_FONT Open_Sans_Regular_Plain_10
49
- #define MEDIUM_FONT Open_Sans_Regular_Plain_20
50
- #define LARGE_FONT Open_Sans_Regular_Plain_34
51
- #define HUGE_FONT Open_Sans_Regular_Plain_50
44
+ #define TINY_FONT OpenSans_Regular_6
45
+ #define SMALL_FONT OpenSans_Regular_7
46
+ #define MEDIUM_FONT OpenSans_Regular_15
47
+ #define LARGE_FONT OpenSans_Regular_26
48
+ #define HUGE_FONT OpenSans_Regular_37
52
49
53
50
// Forward declare classes to build (because there is a cyclic dependency between sensor.h and displays.h)
54
51
class HCSR04SensorInfo ;
@@ -64,21 +61,24 @@ class DisplayDevice {
64
61
private:
65
62
void handleHighlight ();
66
63
void displaySimple (uint16_t value);
67
- SSD1306 * m_display;
64
+ U8G2 * m_display = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(U8G2_R0, U8X8_PIN_NONE); // original OBS display
68
65
String gridText[ 4 ][ 6 ];
69
66
uint8_t mLastProgress = 255 ;
70
67
uint8_t mCurrentLine = 0 ;
71
68
bool mInverted = false ;
69
+ bool mFlipped = true ;
72
70
uint32_t mHighlightTill = 0 ;
73
71
bool mHighlighted = false ;
74
72
75
73
public:
76
74
DisplayDevice () {
77
- m_display = new SSD1306 (0x3c , 21 , 22 ); // ADDRESS, SDA, SCL
78
- m_display->init ();
79
- m_display->setBrightness (255 );
80
- m_display->setTextAlignment (TEXT_ALIGN_LEFT);
81
- m_display->display ();
75
+ m_display->begin ();
76
+ m_display->setFlipMode (mFlipped );
77
+ m_display->setContrast (74 );
78
+ m_display->setFontPosTop ();
79
+ m_display->setFontMode (1 );
80
+ m_display->setDrawColor (WHITE);
81
+ m_display->updateDisplay ();
82
82
}
83
83
84
84
~DisplayDevice () {
@@ -96,20 +96,19 @@ class DisplayDevice {
96
96
// ##############################################################
97
97
98
98
void invert () {
99
- m_display->invertDisplay ();
100
- m_display->display ();
101
99
mInverted = true ;
100
+ setInversion (mInverted );
102
101
}
103
102
104
103
void normalDisplay () {
105
- m_display->normalDisplay ();
106
- m_display->display ();
107
104
mInverted = false ;
105
+ setInversion (mInverted );
108
106
}
109
107
110
108
void flipScreen () {
111
- m_display->flipScreenVertically ();
112
- m_display->display ();
109
+ mFlipped = !mFlipped ;
110
+ m_display->setFlipMode (mFlipped );
111
+ m_display->updateDisplay ();
113
112
}
114
113
115
114
void clear () {
@@ -122,8 +121,8 @@ class DisplayDevice {
122
121
// ##############################################################
123
122
124
123
void showLogo (bool val) {
125
- m_display->drawXbm (0 , 0 , OBSLogo_width, OBSLogo_height, OBSLogo);
126
- m_display->display ();
124
+ m_display->drawXBM (0 , 0 , OBSLogo_width, OBSLogo_height, OBSLogo);
125
+ m_display->updateDisplay ();
127
126
}
128
127
129
128
// ##############################################################
@@ -132,18 +131,18 @@ class DisplayDevice {
132
131
133
132
void showGrid (bool val) {
134
133
// Horizontal lines
135
- m_display->drawHorizontalLine (0 , 2 , 128 );
136
- m_display->drawHorizontalLine (0 , 12 , 128 );
137
- m_display->drawHorizontalLine (0 , 22 , 128 );
138
- m_display->drawHorizontalLine (0 , 32 , 128 );
139
- m_display->drawHorizontalLine (0 , 42 , 128 );
140
- m_display->drawHorizontalLine (0 , 52 , 128 );
141
- m_display->drawHorizontalLine (0 , 62 , 128 );
134
+ m_display->drawHLine (0 , 2 , 128 );
135
+ m_display->drawHLine (0 , 12 , 128 );
136
+ m_display->drawHLine (0 , 22 , 128 );
137
+ m_display->drawHLine (0 , 32 , 128 );
138
+ m_display->drawHLine (0 , 42 , 128 );
139
+ m_display->drawHLine (0 , 52 , 128 );
140
+ m_display->drawHLine (0 , 62 , 128 );
142
141
143
142
// Vertical lines
144
- m_display->drawVerticalLine (32 , 0 , 64 );
145
- m_display->drawVerticalLine (64 , 0 , 64 );
146
- m_display->drawVerticalLine (96 , 0 , 64 );
143
+ m_display->drawVLine (32 , 0 , 64 );
144
+ m_display->drawVLine (64 , 0 , 64 );
145
+ m_display->drawVLine (96 , 0 , 64 );
147
146
}
148
147
149
148
// ##############################################################
@@ -166,7 +165,7 @@ class DisplayDevice {
166
165
167
166
void showTextOnGrid (int16_t x, int16_t y, String text, const uint8_t * font = SMALL_FONT, int8_t offset_x_ = 0 , int8_t offset_y_ = 0 ) {
168
167
if (prepareTextOnGrid (x, y, text, font,offset_x_,offset_y_)) {
169
- m_display->display ();
168
+ m_display->updateDisplay ();
170
169
}
171
170
}
172
171
@@ -186,7 +185,7 @@ class DisplayDevice {
186
185
// 2 => 8 - (2*2) = 4
187
186
// 3 => 8 - (3*2) = 2
188
187
int x_offset = 8 - (x * 2 );
189
- m_display->drawString (x * 32 + x_offset + offset_x_, y * 10 + 1 + offset_y_, gridText[x][y]);
188
+ m_display->drawStr (x * 32 + x_offset + offset_x_, y * 10 + 1 + offset_y_, gridText[x][y]. c_str () );
190
189
changed = true ;
191
190
}
192
191
return changed;
@@ -199,7 +198,7 @@ class DisplayDevice {
199
198
gridText[x][y] = " " ;
200
199
}
201
200
}
202
- m_display->display ();
201
+ m_display->updateDisplay ();
203
202
}
204
203
205
204
// Override the existing WHITE text with BLACK
@@ -208,23 +207,23 @@ class DisplayDevice {
208
207
}
209
208
210
209
void cleanGridCell (int16_t x, int16_t y,int8_t offset_x_, int8_t offset_y_) {
211
- m_display->setColor (BLACK);
210
+ m_display->setDrawColor (BLACK);
212
211
int x_offset = 8 - (x * 2 );
213
- m_display->drawString (x * 32 + x_offset + offset_x_, y * 10 + 1 + offset_y_, gridText[x][y]);
212
+ m_display->drawStr (x * 32 + x_offset + offset_x_, y * 10 + 1 + offset_y_, gridText[x][y]. c_str () );
214
213
gridText[x][y] = " " ;
215
- m_display->setColor (WHITE);
214
+ m_display->setDrawColor (WHITE);
216
215
}
217
216
218
217
void cleanBattery (int16_t x, int16_t y){
219
- m_display->setColor (BLACK);
220
- m_display->drawXbm (x, y, 8 , 9 , BatterieLogo1);
221
- m_display->setColor (WHITE);
218
+ m_display->setDrawColor (BLACK);
219
+ m_display->drawXBM (x, y, 8 , 9 , BatterieLogo1);
220
+ m_display->setDrawColor (WHITE);
222
221
}
223
222
224
223
void cleanTemperatur (int16_t x, int16_t y){
225
- m_display->setColor (BLACK);
226
- m_display->drawXbm (x, y, 8 , 9 , TempLogo);
227
- m_display->setColor (WHITE);
224
+ m_display->setDrawColor (BLACK);
225
+ m_display->drawXBM (x, y, 8 , 9 , TempLogo);
226
+ m_display->setDrawColor (WHITE);
228
227
}
229
228
230
229
void drawProgressBar (uint8_t y, uint32_t current, uint32_t target) {
@@ -242,34 +241,34 @@ class DisplayDevice {
242
241
uint16_t rowOffset = y * 10 + 3 ;
243
242
244
243
if (mLastProgress != progress) {
245
- m_display->drawRect (12 , rowOffset, 104 , 8 );
244
+ m_display->drawFrame (12 , rowOffset, 104 , 8 );
246
245
if (progress != 0 ) {
247
- m_display->fillRect (14 , rowOffset + 2 , progress > 100 ? 100 : progress, 4 );
246
+ m_display->drawBox (14 , rowOffset + 2 , progress > 100 ? 100 : progress, 4 );
248
247
}
249
- m_display->display ();
248
+ m_display->updateDisplay ();
250
249
mLastProgress = progress;
251
250
}
252
251
}
253
252
254
253
void drawWaitBar (uint8_t y, uint16_t tick) {
255
254
uint16_t rowOffset = y * 10 + 3 ;
256
- m_display->drawRect (12 , rowOffset, 104 , 8 );
257
- m_display->setColor (BLACK);
258
- m_display->fillRect (14 , rowOffset + 2 , 100 , 4 );
259
- m_display->setColor (WHITE);
255
+ m_display->drawFrame (12 , rowOffset, 104 , 8 );
256
+ m_display->setDrawColor (BLACK);
257
+ m_display->drawBox (14 , rowOffset + 2 , 100 , 4 );
258
+ m_display->setDrawColor (WHITE);
260
259
261
260
int16_t pos = 45 + (45.0 * sin (tick / 10.0 ));
262
- m_display->fillRect (14 + pos, rowOffset + 2 , 10 , 4 );
263
- m_display->display ();
261
+ m_display->drawBox (14 + pos, rowOffset + 2 , 10 , 4 );
262
+ m_display->updateDisplay ();
264
263
}
265
264
266
265
void clearProgressBar (uint8_t y) {
267
266
if (UINT8_MAX != mLastProgress ) {
268
267
clearTextLine (y);
269
268
uint16_t rowOffset = y * 10 + 3 ;
270
- m_display->setColor (BLACK);
271
- m_display->fillRect (12 , rowOffset, 104 , 8 );
272
- m_display->setColor (WHITE);
269
+ m_display->setDrawColor (BLACK);
270
+ m_display->drawBox (12 , rowOffset, 104 , 8 );
271
+ m_display->setDrawColor (WHITE);
273
272
m_display->display ();
274
273
mLastProgress = UINT8_MAX;
275
274
}
@@ -310,6 +309,15 @@ class DisplayDevice {
310
309
uint16_t minDistanceToConfirm, int16_t batteryPercentage, int16_t TemperaturValue,
311
310
int lastMeasurements, boolean insidePrivacyArea, double speed, uint8_t satellites);
312
311
312
+
313
+ // ##############################################################
314
+ // Internal methods
315
+ // ##############################################################
316
+
317
+ private:
318
+ void setInversion (bool enabled) {
319
+ m_display->sendF (" c" , enabled ? 0xa7 : 0xa6 ); // set inversion of the SSD1306 OLED
320
+ }
313
321
};
314
322
315
323
#endif
0 commit comments