-
-
Notifications
You must be signed in to change notification settings - Fork 837
Expand file tree
/
Copy pathSSD1306Display.cpp
More file actions
93 lines (78 loc) · 2.06 KB
/
SSD1306Display.cpp
File metadata and controls
93 lines (78 loc) · 2.06 KB
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
90
91
92
93
#include "SSD1306Display.h"
#ifdef OLED_RU
#include "glcdfont6x8.h"
#endif
bool SSD1306Display::i2c_probe(TwoWire& wire, uint8_t addr) {
wire.beginTransmission(addr);
uint8_t error = wire.endTransmission();
return (error == 0);
}
bool SSD1306Display::begin() {
#ifdef DISPLAY_ROTATION
display.setRotation(DISPLAY_ROTATION);
#endif
return display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_ADDRESS, true, false) && i2c_probe(Wire, DISPLAY_ADDRESS);
}
void SSD1306Display::turnOn() {
display.ssd1306_command(SSD1306_DISPLAYON);
_isOn = true;
}
void SSD1306Display::turnOff() {
display.ssd1306_command(SSD1306_DISPLAYOFF);
_isOn = false;
}
void SSD1306Display::clear() {
display.clearDisplay();
display.display();
}
void SSD1306Display::startFrame(Color bkg) {
display.clearDisplay(); // TODO: apply 'bkg'
_color = SSD1306_WHITE;
#ifdef OLED_RU
display.setFont(&glcdfont6x8);
#endif
display.setTextColor(_color);
display.setTextSize(1);
display.cp437(true); // Use full 256 char 'Code Page 437' font
#ifdef OLED_RU
display.setCursor(0, 7);
#endif
}
void SSD1306Display::setTextSize(int sz) {
display.setTextSize(sz);
#ifdef OLED_RU
_size = sz;
#endif
}
void SSD1306Display::setColor(Color c) {
_color = (c != 0) ? SSD1306_WHITE : SSD1306_BLACK;
display.setTextColor(_color);
}
void SSD1306Display::setCursor(int x, int y) {
#ifdef OLED_RU
display.setCursor(x, y + (_size * 7));
#else
display.setCursor(x, y);
#endif
}
void SSD1306Display::print(const char* str) {
display.print(str);
}
void SSD1306Display::fillRect(int x, int y, int w, int h) {
display.fillRect(x, y, w, h, _color);
}
void SSD1306Display::drawRect(int x, int y, int w, int h) {
display.drawRect(x, y, w, h, _color);
}
void SSD1306Display::drawXbm(int x, int y, const uint8_t* bits, int w, int h) {
display.drawBitmap(x, y, bits, w, h, SSD1306_WHITE);
}
uint16_t SSD1306Display::getTextWidth(const char* str) {
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(str, 0, 0, &x1, &y1, &w, &h);
return w;
}
void SSD1306Display::endFrame() {
display.display();
}