small changes and many new sensors
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
|
||||
#include "../../io/SoftI2C.h"
|
||||
|
||||
// NOTE: this is almost the same as SH1106
|
||||
// https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf
|
||||
|
||||
//#define SSD1306_128_64 1
|
||||
//#define SSD1306_64_48 1 // https://github.com/mcauser/Adafruit_SSD1306/blob/esp8266-64x48/Adafruit_SSD1306.cpp
|
||||
|
||||
@@ -88,6 +91,14 @@ public:
|
||||
bool isPresent() {
|
||||
return i2c.query(ADDR7);
|
||||
}
|
||||
|
||||
/** checks if LCD is present and initializes it once / when it was gone */
|
||||
bool isPresentAndInit() {
|
||||
bool present = isPresent();
|
||||
if (!present) {inited = false;}
|
||||
if ( present && !inited) {initOnce();}
|
||||
return present;
|
||||
}
|
||||
|
||||
void initOnce() {
|
||||
if (inited) {return;}
|
||||
@@ -98,20 +109,29 @@ public:
|
||||
|
||||
void flush(const uint8_t* data) {
|
||||
|
||||
sendCommand(SSD1306_COLUMNADDR);
|
||||
|
||||
|
||||
// special handling for 64x48 oled shield
|
||||
#if SSD1306_LCDWIDTH == 64 && SSD1306_LCDHEIGHT == 48
|
||||
sendCommand(SSD1306_COLUMNADDR);
|
||||
sendCommand(32);
|
||||
sendCommand(32 + SSD1306_LCDWIDTH - 1);
|
||||
#else
|
||||
sendCommand(0); // Column start address (0 = reset)
|
||||
sendCommand(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)
|
||||
sendCommand(SSD1306_COLUMNADDR, 0, SSD1306_LCDWIDTH-1);
|
||||
//sendCommand(SSD1306_COLUMNADDR);
|
||||
//sendCommand(0); // Column start address (0 = reset)
|
||||
//sendCommand(SSD1306_LCDWIDTH-1); // Column end address (127 = reset)
|
||||
#endif
|
||||
|
||||
sendCommand(SSD1306_PAGEADDR);
|
||||
sendCommand(0); // Page start address (0 = reset)
|
||||
sendCommand( (SSD1306_LCDHEIGHT/8)-1 ); // Page end address
|
||||
|
||||
sendCommand(SSD1306_PAGEADDR, 0, (SSD1306_LCDHEIGHT/8)-1);
|
||||
//sendCommand(SSD1306_PAGEADDR);
|
||||
//sendCommand(0); // Page start address (0 = reset)
|
||||
//sendCommand( (SSD1306_LCDHEIGHT/8)-1 ); // Page end address
|
||||
|
||||
|
||||
|
||||
|
||||
// #if SSD1306_LCDHEIGHT == 64
|
||||
// sendCommand(7); // Page end address
|
||||
// #endif
|
||||
@@ -147,7 +167,8 @@ public:
|
||||
bool ok = i2c.writeByteAndCheck(0x40);
|
||||
if (!ok) {os_printf("failed write data\n");}
|
||||
|
||||
for (uint16_t i=0; i < (SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
|
||||
//for (uint16_t i=0; i < (SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
|
||||
for (uint16_t i=0; i < 16; i++) {
|
||||
i2c.writeByteAndCheck(data[i]);
|
||||
}
|
||||
|
||||
@@ -163,25 +184,32 @@ private:
|
||||
uint8_t vccstate = 0;
|
||||
|
||||
sendCommand(SSD1306_DISPLAYOFF); // 0xAE
|
||||
|
||||
sendCommand(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
|
||||
sendCommand(0x80); // the suggested ratio 0x80
|
||||
|
||||
sendCommand(SSD1306_SETMULTIPLEX); // 0xA8
|
||||
sendCommand(SSD1306_SETMULTIPLEX); // 0xA8: multiplexer (31 == 32MUX, 63 == 64MUX)
|
||||
sendCommand(SSD1306_LCDHEIGHT - 1);
|
||||
|
||||
sendCommand(SSD1306_SETDISPLAYOFFSET); // 0xD3
|
||||
sendCommand(SSD1306_SETDISPLAYOFFSET); // 0xD3: vertical shift 0-63
|
||||
sendCommand(0x0); // no offset
|
||||
|
||||
sendCommand(SSD1306_SETSTARTLINE | 0x0); // line #0
|
||||
|
||||
sendCommand(SSD1306_CHARGEPUMP); // 0x8D
|
||||
if (vccstate == SSD1306_EXTERNALVCC) {
|
||||
sendCommand(0x10);
|
||||
} else {
|
||||
sendCommand(0x14);
|
||||
}
|
||||
sendCommand(SSD1306_MEMORYMODE); // 0x20
|
||||
sendCommand(0x00); // 0x0 act like ks0108
|
||||
sendCommand(SSD1306_SEGREMAP | 0x1);
|
||||
|
||||
//sendCommand(SSD1306_MEMORYMODE); // 0x20: memory mode: hor/ver/page
|
||||
//sendCommand(0x02); // 0x0 act like ks0108
|
||||
sendCommand(SSD1306_MEMORYMODE, 0x00); // 0x20: memory mode: hor/ver/page
|
||||
|
||||
sendCommand(SSD1306_SEGREMAP | 0x0);
|
||||
|
||||
//sendCommand(SSD1306_COMSCANINC); // rotate 0
|
||||
sendCommand(SSD1306_COMSCANDEC); // rotate 180?
|
||||
|
||||
// OLD
|
||||
@@ -244,6 +272,8 @@ private:
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
void sendCommand(uint8_t cmd) {
|
||||
bool ok;
|
||||
ok = i2c.startWrite(ADDR7);
|
||||
@@ -254,6 +284,37 @@ private:
|
||||
if (!ok) {os_printf("failed command\n");}
|
||||
i2c.stop();
|
||||
}
|
||||
|
||||
void sendCommand(uint8_t cmd, uint8_t v1) {
|
||||
bool ok;
|
||||
ok = i2c.startWrite(ADDR7);
|
||||
if (!ok) {os_printf("failed start write\n");}
|
||||
ok = i2c.writeByteAndCheck(0x00); // command
|
||||
if (!ok) {os_printf("failed command mode\n");}
|
||||
ok = i2c.writeByteAndCheck(cmd);
|
||||
if (!ok) {os_printf("failed command\n");}
|
||||
ok = i2c.writeByteAndCheck(0x00); // command
|
||||
ok = i2c.writeByteAndCheck(v1);
|
||||
if (!ok) {os_printf("failed command\n");}
|
||||
i2c.stop();
|
||||
}
|
||||
|
||||
void sendCommand(uint8_t cmd, uint8_t v1, uint8_t v2) {
|
||||
bool ok;
|
||||
ok = i2c.startWrite(ADDR7);
|
||||
if (!ok) {os_printf("failed start write\n");}
|
||||
ok = i2c.writeByteAndCheck(0x00); // command
|
||||
if (!ok) {os_printf("failed command mode\n");}
|
||||
ok = i2c.writeByteAndCheck(cmd);
|
||||
if (!ok) {os_printf("failed command\n");}
|
||||
ok = i2c.writeByteAndCheck(0x00); // command
|
||||
ok = i2c.writeByteAndCheck(v1);
|
||||
if (!ok) {os_printf("failed command\n");}
|
||||
ok = i2c.writeByteAndCheck(0x00); // command
|
||||
ok = i2c.writeByteAndCheck(v2);
|
||||
if (!ok) {os_printf("failed command\n");}
|
||||
i2c.stop();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user