Merge branch 'master' into dev
This commit is contained in:
@@ -168,14 +168,12 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
// network here
|
||||
void setup() {
|
||||
if (type == NONE) return;
|
||||
bool allocated = false;
|
||||
byte i;
|
||||
if (type == SSD1306_SPI || type == SSD1306_SPI64) {
|
||||
for (i=0; i<5; i++) if (!pinManager.allocatePin(ioPin[i])) { allocated=true; break; }
|
||||
if (i<5 && allocated) { for (byte i=0; i<5; i++) pinManager.deallocatePin(ioPin[i]); type=NONE; return; }
|
||||
PinManagerPinType pins[5] = { { ioPin[0], true }, { ioPin[1], true}, { ioPin[2], true }, { ioPin[3], true}, { ioPin[4], true }};
|
||||
if (!pinManager.allocateMultiplePins(pins, 5, PinOwner::UM_FourLineDisplay)) { type=NONE; return; }
|
||||
} else {
|
||||
for (i=0; i<2; i++) if (!pinManager.allocatePin(ioPin[i])) { allocated=true; break; }
|
||||
if (i<2 && allocated) { for (byte i=0; i<5; i++) pinManager.deallocatePin(ioPin[i]); type=NONE; return; }
|
||||
PinManagerPinType pins[2] = { { ioPin[0], true }, { ioPin[1], true} };
|
||||
if (!pinManager.allocateMultiplePins(pins, 2, PinOwner::UM_FourLineDisplay)) { type=NONE; return; }
|
||||
}
|
||||
DEBUG_PRINTLN(F("Allocating display."));
|
||||
switch (type) {
|
||||
@@ -240,18 +238,17 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
break;
|
||||
default:
|
||||
u8x8 = nullptr;
|
||||
}
|
||||
if (nullptr == u8x8) {
|
||||
DEBUG_PRINTLN(F("Display init failed."));
|
||||
for (byte i=0; i<5 && ioPin[i]>=0; i++) pinManager.deallocatePin(ioPin[i], PinOwner::UM_FourLineDisplay);
|
||||
type = NONE;
|
||||
return;
|
||||
}
|
||||
|
||||
initDone = true;
|
||||
if (u8x8 != nullptr) {
|
||||
DEBUG_PRINTLN(F("Starting display."));
|
||||
(static_cast<U8X8*>(u8x8))->begin();
|
||||
} else {
|
||||
DEBUG_PRINTLN(F("Display init failed."));
|
||||
type = NONE;
|
||||
return;
|
||||
}
|
||||
DEBUG_PRINTLN(F("Starting display."));
|
||||
u8x8->begin();
|
||||
setFlipMode(flip);
|
||||
setContrast(contrast); //Contrast setup will help to preserve OLED lifetime. In case OLED need to be brighter increase number up to 255
|
||||
setPowerSave(0);
|
||||
@@ -277,40 +274,40 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
*/
|
||||
void setFlipMode(uint8_t mode) {
|
||||
if (type==NONE) return;
|
||||
(static_cast<U8X8*>(u8x8))->setFlipMode(mode);
|
||||
u8x8->setFlipMode(mode);
|
||||
}
|
||||
void setContrast(uint8_t contrast) {
|
||||
if (type==NONE) return;
|
||||
(static_cast<U8X8*>(u8x8))->setContrast(contrast);
|
||||
u8x8->setContrast(contrast);
|
||||
}
|
||||
void drawString(uint8_t col, uint8_t row, const char *string, bool ignoreLH=false) {
|
||||
if (type==NONE) return;
|
||||
(static_cast<U8X8*>(u8x8))->setFont(u8x8_font_chroma48medium8_r);
|
||||
if (!ignoreLH && lineHeight==2) (static_cast<U8X8*>(u8x8))->draw1x2String(col, row, string);
|
||||
else (static_cast<U8X8*>(u8x8))->drawString(col, row, string);
|
||||
u8x8->setFont(u8x8_font_chroma48medium8_r);
|
||||
if (!ignoreLH && lineHeight==2) u8x8->draw1x2String(col, row, string);
|
||||
else u8x8->drawString(col, row, string);
|
||||
}
|
||||
void draw2x2String(uint8_t col, uint8_t row, const char *string) {
|
||||
if (type==NONE) return;
|
||||
(static_cast<U8X8*>(u8x8))->setFont(u8x8_font_chroma48medium8_r);
|
||||
(static_cast<U8X8*>(u8x8))->draw2x2String(col, row, string);
|
||||
u8x8->setFont(u8x8_font_chroma48medium8_r);
|
||||
u8x8->draw2x2String(col, row, string);
|
||||
}
|
||||
void drawGlyph(uint8_t col, uint8_t row, char glyph, const uint8_t *font, bool ignoreLH=false) {
|
||||
if (type==NONE) return;
|
||||
(static_cast<U8X8*>(u8x8))->setFont(font);
|
||||
if (!ignoreLH && lineHeight==2) (static_cast<U8X8*>(u8x8))->draw1x2Glyph(col, row, glyph);
|
||||
else (static_cast<U8X8*>(u8x8))->drawGlyph(col, row, glyph);
|
||||
u8x8->setFont(font);
|
||||
if (!ignoreLH && lineHeight==2) u8x8->draw1x2Glyph(col, row, glyph);
|
||||
else u8x8->drawGlyph(col, row, glyph);
|
||||
}
|
||||
uint8_t getCols() {
|
||||
if (type==NONE) return 0;
|
||||
return (static_cast<U8X8*>(u8x8))->getCols();
|
||||
return u8x8->getCols();
|
||||
}
|
||||
void clear() {
|
||||
if (type==NONE) return;
|
||||
(static_cast<U8X8*>(u8x8))->clear();
|
||||
u8x8->clear();
|
||||
}
|
||||
void setPowerSave(uint8_t save) {
|
||||
if (type==NONE) return;
|
||||
(static_cast<U8X8*>(u8x8))->setPowerSave(save);
|
||||
u8x8->setPowerSave(save);
|
||||
}
|
||||
|
||||
void center(String &line, uint8_t width) {
|
||||
@@ -725,9 +722,9 @@ class FourLineDisplayUsermod : public Usermod {
|
||||
bool pinsChanged = false;
|
||||
for (byte i=0; i<5; i++) if (ioPin[i] != newPin[i]) { pinsChanged = true; break; }
|
||||
if (pinsChanged || type!=newType) {
|
||||
if (type != NONE) delete (static_cast<U8X8*>(u8x8));
|
||||
if (type != NONE) delete u8x8;
|
||||
for (byte i=0; i<5; i++) {
|
||||
if (ioPin[i]>=0) pinManager.deallocatePin(ioPin[i]);
|
||||
if (ioPin[i]>=0) pinManager.deallocatePin(ioPin[i], PinOwner::UM_FourLineDisplay);
|
||||
ioPin[i] = newPin[i];
|
||||
}
|
||||
if (ioPin[0]<0 || ioPin[1]<0) { // data & clock must be > -1
|
||||
|
||||
Reference in New Issue
Block a user