mirror of https://github.com/meshcore-dev/MeshCore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.6 KiB
104 lines
2.6 KiB
#include "SSD1306Display.h"
|
|
|
|
bool SSD1306Display::i2c_probe(TwoWire& wire, uint8_t addr) {
|
|
wire.beginTransmission(addr);
|
|
uint8_t error = wire.endTransmission();
|
|
return (error == 0);
|
|
}
|
|
|
|
// Color scheme
|
|
ColorVal UIColor::window_bkg = SSD1306_BLACK;
|
|
ColorVal UIColor::title_bkg = SSD1306_WHITE;
|
|
ColorVal UIColor::title_txt = SSD1306_BLACK;
|
|
ColorVal UIColor::primary_txt = SSD1306_WHITE;
|
|
ColorVal UIColor::secondary_txt = SSD1306_WHITE;
|
|
ColorVal UIColor::warning_txt = SSD1306_WHITE;
|
|
ColorVal UIColor::popup_bkg = SSD1306_WHITE;
|
|
ColorVal UIColor::popup_txt = SSD1306_BLACK;
|
|
ColorVal UIColor::corp_blue = SSD1306_WHITE;
|
|
|
|
bool SSD1306Display::begin() {
|
|
if (!_isOn) {
|
|
if (_peripher_power) _peripher_power->claim();
|
|
_isOn = true;
|
|
}
|
|
#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() {
|
|
if (!_isOn) {
|
|
if (_peripher_power) _peripher_power->claim();
|
|
_isOn = true; // set before begin() to prevent double claim
|
|
if (_peripher_power) begin(); // re-init display after power was cut
|
|
}
|
|
display.ssd1306_command(SSD1306_DISPLAYON);
|
|
}
|
|
|
|
void SSD1306Display::turnOff() {
|
|
display.ssd1306_command(SSD1306_DISPLAYOFF);
|
|
if (_isOn) {
|
|
if (_peripher_power) {
|
|
#if PIN_OLED_RESET >= 0
|
|
digitalWrite(PIN_OLED_RESET, LOW);
|
|
#endif
|
|
_peripher_power->release();
|
|
}
|
|
_isOn = false;
|
|
}
|
|
}
|
|
|
|
void SSD1306Display::clear() {
|
|
display.clearDisplay();
|
|
display.display();
|
|
}
|
|
|
|
void SSD1306Display::startFrame(ColorVal bkg) {
|
|
display.clearDisplay(); // TODO: apply 'bkg'
|
|
_color = SSD1306_WHITE;
|
|
display.setTextColor(_color);
|
|
display.setTextSize(1);
|
|
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
|
}
|
|
|
|
void SSD1306Display::setTextSize(int sz) {
|
|
display.setTextSize(sz);
|
|
}
|
|
|
|
void SSD1306Display::setColor(ColorVal c) {
|
|
_color = c;
|
|
display.setTextColor(_color);
|
|
}
|
|
|
|
void SSD1306Display::setCursor(int x, int y) {
|
|
display.setCursor(x, y);
|
|
}
|
|
|
|
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, _color);
|
|
}
|
|
|
|
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();
|
|
}
|
|
|