2020-10-12 20:32:47 +02:00
|
|
|
/*
|
2021-02-17 00:38:33 +01:00
|
|
|
* © 2020, Chris Harlow, 2021, Neil McKechnie. All rights reserved.
|
2020-10-12 20:32:47 +02:00
|
|
|
*
|
|
|
|
* This file is part of CommandStation-EX
|
|
|
|
*
|
|
|
|
* This is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* It is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with CommandStation. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// OLED Implementation of LCDDisplay class
|
2021-02-17 00:38:33 +01:00
|
|
|
// Note: this file is optionally included by LCD_Implementation.h
|
|
|
|
// It is NOT a .cpp file to prevent it being compiled and demanding libraries even when not needed.
|
2020-10-12 20:32:47 +02:00
|
|
|
|
2021-02-17 12:06:26 +01:00
|
|
|
#include "Wire.h"
|
2021-02-17 00:38:33 +01:00
|
|
|
#include "SSD1306/SSD1306AsciiWire.h"
|
|
|
|
SSD1306AsciiWire LCDDriver;
|
2020-10-12 20:32:47 +02:00
|
|
|
|
|
|
|
// DEVICE SPECIFIC LCDDisplay Implementation for OLED
|
|
|
|
|
2021-02-17 00:38:33 +01:00
|
|
|
LCDDisplay::LCDDisplay() {
|
|
|
|
// Scan for device on 0x3c and 0x3d.
|
2021-02-17 12:06:26 +01:00
|
|
|
Wire.begin();
|
2021-02-17 00:38:33 +01:00
|
|
|
for (byte address=0x3c; address<=0x3d; address++) {
|
|
|
|
Wire.beginTransmission(address);
|
2021-02-18 17:00:00 +01:00
|
|
|
byte error = Wire.endTransmission(true);
|
2021-02-17 00:38:33 +01:00
|
|
|
if (!error) {
|
|
|
|
// Device found
|
|
|
|
DIAG(F("\nOLED display found at 0x%x"), address);
|
|
|
|
interfake(OLED_DRIVER,0);
|
2021-02-18 17:00:00 +01:00
|
|
|
const DevType *devType;
|
|
|
|
if (lcdCols == 132)
|
|
|
|
devType = &SH1106_128x64; // Actually 132x64 but treated as 128x64
|
|
|
|
else if (lcdCols == 128 && lcdRows == 8)
|
|
|
|
devType = &Adafruit128x64;
|
|
|
|
else
|
|
|
|
devType = &Adafruit128x32;
|
|
|
|
LCDDriver.begin(devType, address);
|
2021-02-17 00:38:33 +01:00
|
|
|
lcdDisplay=this;
|
2021-02-18 17:00:00 +01:00
|
|
|
LCDDriver.setFont(System5x7); // Normal 1:1 pixel scale, 8 bits high
|
2021-02-17 00:38:33 +01:00
|
|
|
clear();
|
|
|
|
return;
|
2020-10-12 20:32:47 +02:00
|
|
|
}
|
|
|
|
}
|
2021-02-17 00:38:33 +01:00
|
|
|
DIAG(F("\nOLED display not found\n"));
|
|
|
|
}
|
2020-10-12 20:32:47 +02:00
|
|
|
|
2021-02-18 17:00:00 +01:00
|
|
|
void LCDDisplay::interfake(int p1, int p2, int p3) {lcdCols=p1; lcdRows=p2/8; (void)p3;}
|
2020-10-12 20:32:47 +02:00
|
|
|
|
2021-02-17 00:38:33 +01:00
|
|
|
void LCDDisplay::clearNative() {LCDDriver.clear();}
|
2020-10-12 20:32:47 +02:00
|
|
|
|
|
|
|
void LCDDisplay::setRowNative(byte row) {
|
|
|
|
// Positions text write to start of row 1..n and clears previous text
|
2021-02-17 00:38:33 +01:00
|
|
|
int y=row;
|
2020-10-12 20:32:47 +02:00
|
|
|
LCDDriver.setCursor(0, y);
|
2021-02-18 17:00:00 +01:00
|
|
|
//LCDDriver.clearToEOL();
|
2021-02-17 00:38:33 +01:00
|
|
|
}
|
2020-10-12 20:32:47 +02:00
|
|
|
|
2021-02-18 17:00:00 +01:00
|
|
|
void LCDDisplay::writeNative(char b) {
|
|
|
|
LCDDriver.write(b);
|
|
|
|
}
|
2020-10-12 20:32:47 +02:00
|
|
|
|
2021-02-17 00:38:33 +01:00
|
|
|
void LCDDisplay::displayNative() { }
|
2020-10-12 20:32:47 +02:00
|
|
|
|