* companion: SSD1306 display now dynamically detected at runtime.

This commit is contained in:
Scott Powell 2025-03-16 13:42:36 +11:00
parent 4113b20b4c
commit 81bf4f0a08
5 changed files with 50 additions and 16 deletions

View file

@ -1,7 +1,13 @@
#include "SSD1306Display.h"
bool SSD1306Display::i2c_probe(TwoWire& wire, uint8_t addr) {
wire.beginTransmission(addr);
uint8_t error = wire.endTransmission();
return (error == 0);
}
bool SSD1306Display::begin() {
return display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_ADDRESS, true, false);
return display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_ADDRESS, true, false) && i2c_probe(Wire, DISPLAY_ADDRESS);
}
void SSD1306Display::turnOn() {

View file

@ -3,6 +3,7 @@
#include "DisplayDriver.h"
#include <Wire.h>
#include <Adafruit_GFX.h>
#define SSD1306_NO_SPLASH
#include <Adafruit_SSD1306.h>
#ifndef PIN_OLED_RESET
@ -18,6 +19,7 @@ class SSD1306Display : public DisplayDriver {
bool _isOn;
uint8_t _color;
bool i2c_probe(TwoWire& wire, uint8_t addr);
public:
SSD1306Display() : DisplayDriver(128, 64), display(128, 64, &Wire, PIN_OLED_RESET) { _isOn = false; }
bool begin();