implement new auto detect display for sh1106 and ssd1306
This commit is contained in:
1 parent
2e6c8824eb
commit
75ea17ea46
5 files changed
+100
-20
No files matched your search
@@ -0,0 +1,45 @@
|
||||
#include "AutoDetectDisplay.h"
|
||||
#include <MeshCore.h>
|
||||
|
||||
int AutoDetectDisplay::getDisplayStatus(TwoWire& wire, uint8_t addr) {
|
||||
int status = -1;
|
||||
for(int i = 0; i < 4; i++){
|
||||
|
||||
// request display status
|
||||
wire.beginTransmission(addr);
|
||||
wire.write((uint8_t)0x00);
|
||||
|
||||
// ensure response received
|
||||
if (wire.endTransmission() != 0) return -1; // expect success
|
||||
if (wire.requestFrom((int)addr, 1) == 0) return -1; // expect at least 1 byte
|
||||
|
||||
// ensure two consecutive reads are the same
|
||||
int previous = status;
|
||||
status = wire.read() & 0x0F;
|
||||
if(status == previous){
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
bool AutoDetectDisplay::begin() {
|
||||
|
||||
// request status from display address
|
||||
int status = getDisplayStatus(Wire, DISPLAY_ADDRESS);
|
||||
MESH_DEBUG_PRINTLN("AutoDetectDisplay: status=0x%02X", status);
|
||||
|
||||
// detect SH1106
|
||||
if(status == 0x00 || status == 0x08){
|
||||
MESH_DEBUG_PRINTLN("AutoDetectDisplay: SH1106 detected");
|
||||
_impl = &_sh1106;
|
||||
return _sh1106.begin();
|
||||
}
|
||||
|
||||
// fallback to SSD1306
|
||||
MESH_DEBUG_PRINTLN("AutoDetectDisplay: falling back to SSD1306");
|
||||
_impl = &_ssd1306;
|
||||
return _ssd1306.begin();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "DisplayDriver.h"
|
||||
#include "SSD1306Display.h"
|
||||
#include "SH1106Display.h"
|
||||
|
||||
// Auto detects SH1106 display at runtime, otherwise falls back to using SSD1306
|
||||
class AutoDetectDisplay : public DisplayDriver {
|
||||
DisplayDriver* _impl;
|
||||
SSD1306Display _ssd1306;
|
||||
SH1106Display _sh1106;
|
||||
|
||||
int getDisplayStatus(TwoWire& wire, uint8_t addr);
|
||||
public:
|
||||
AutoDetectDisplay() : DisplayDriver(128, 64), _impl(&_ssd1306) { }
|
||||
bool begin();
|
||||
|
||||
bool isOn() override { return _impl->isOn(); }
|
||||
void turnOn() override { _impl->turnOn(); }
|
||||
void turnOff() override { _impl->turnOff(); }
|
||||
void clear() override { _impl->clear(); }
|
||||
void startFrame(ColorVal bkg = UIColor::window_bkg) override { _impl->startFrame(bkg); }
|
||||
void setTextSize(int sz) override { _impl->setTextSize(sz); }
|
||||
void setColor(ColorVal c) override { _impl->setColor(c); }
|
||||
void setCursor(int x, int y) override { _impl->setCursor(x, y); }
|
||||
void print(const char* str) override { _impl->print(str); }
|
||||
void fillRect(int x, int y, int w, int h) override { _impl->fillRect(x, y, w, h); }
|
||||
void drawRect(int x, int y, int w, int h) override { _impl->drawRect(x, y, w, h); }
|
||||
void drawXbm(int x, int y, const uint8_t* bits, int w, int h) override { _impl->drawXbm(x, y, bits, w, h); }
|
||||
uint16_t getTextWidth(const char* str) override { return _impl->getTextWidth(str); }
|
||||
void endFrame() override { _impl->endFrame(); }
|
||||
};
|
||||
@@ -10,15 +10,15 @@ bool SH1106Display::i2c_probe(TwoWire &wire, uint8_t addr)
|
||||
}
|
||||
|
||||
// Color scheme
|
||||
ColorVal UIColor::window_bkg = SH110X_BLACK;
|
||||
ColorVal UIColor::title_bkg = SH110X_BLACK;
|
||||
ColorVal UIColor::title_txt = SH110X_WHITE;
|
||||
ColorVal UIColor::primary_txt = SH110X_WHITE;
|
||||
ColorVal UIColor::secondary_txt = SH110X_WHITE;
|
||||
ColorVal UIColor::warning_txt = SH110X_WHITE;
|
||||
ColorVal UIColor::popup_bkg = SH110X_BLACK;
|
||||
ColorVal UIColor::popup_txt = SH110X_WHITE;
|
||||
ColorVal UIColor::corp_blue = SH110X_WHITE;
|
||||
__attribute__((weak)) ColorVal UIColor::window_bkg = SH110X_BLACK;
|
||||
__attribute__((weak)) ColorVal UIColor::title_bkg = SH110X_BLACK;
|
||||
__attribute__((weak)) ColorVal UIColor::title_txt = SH110X_WHITE;
|
||||
__attribute__((weak)) ColorVal UIColor::primary_txt = SH110X_WHITE;
|
||||
__attribute__((weak)) ColorVal UIColor::secondary_txt = SH110X_WHITE;
|
||||
__attribute__((weak)) ColorVal UIColor::warning_txt = SH110X_WHITE;
|
||||
__attribute__((weak)) ColorVal UIColor::popup_bkg = SH110X_BLACK;
|
||||
__attribute__((weak)) ColorVal UIColor::popup_txt = SH110X_WHITE;
|
||||
__attribute__((weak)) ColorVal UIColor::corp_blue = SH110X_WHITE;
|
||||
|
||||
bool SH1106Display::begin()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user