Skip to content

Commit

Permalink
New interface to display - LCD and OLED. Simpler code in sensors sect…
Browse files Browse the repository at this point in the history
…ion and

supports both LCD and OLED
  • Loading branch information
netmaniac committed May 20, 2021
2 parents b21d26f + 17fb76e commit 02c261c
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 155 deletions.
38 changes: 33 additions & 5 deletions src/display/commons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,31 @@ void display_values() {
if (sensor == SimpleScheduler::EMPTY) {
next_display_count = 0;
} else {
SimpleScheduler::displaySensor(sensor, char_lcd, minor);
String lines[] = {"","","",""};
SimpleScheduler::displaySensor(sensor, lines, 20, 4, minor);
if (display) {
display->clear();
display->displayOn();
// display->setTextAlignment(TEXT_ALIGN_CENTER);
// display->drawString(64, 1, display_header);
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->drawString(0, 1, lines[0]);
display->drawString(0, 16, lines[1]);
display->drawString(0, 28, lines[2]);
display->drawString(0, 40, lines[3]);
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->drawString(64, 52, displayGenerateFooter(static_screen_count + scheduler.countScreens()));
display->display();
}
if (char_lcd) {
char_lcd->clear();
for (byte i = 0; i < 4; i++) {
char_lcd->setCursor(0,i);
if (i==0) char_lcd->print(getLCDHeader(getLCDRows()==4));
char_lcd->print(lines[i]);
}

}
next_display_count++;
skipOldDisplay = true;
}
Expand Down Expand Up @@ -200,7 +224,7 @@ void display_values() {
display->drawString(0, 28, display_lines[1]);
display->drawString(0, 40, display_lines[2]);
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->drawString(64, 52, displayGenerateFooter(static_screen_count));
display->drawString(64, 52, displayGenerateFooter(static_screen_count + scheduler.countScreens()));
display->display();
}
if (cfg::has_lcd2004_27 || cfg::has_lcd2004_3f) {
Expand Down Expand Up @@ -270,13 +294,17 @@ byte getLCDCols(){

byte getLCDRows(){
if (cfg::has_lcd1602 || cfg::has_lcd1602_27) return 2;
if (cfg::has_lcd2004_27 || cfg::has_lcd2004_3f) return 4;
if (cfg::has_lcd2004_27 || cfg::has_lcd2004_3f || display) return 4;
return 0;

};

String getLCDHeader(){
String ret = String(next_display_count+1)+F("/")+String(static_screen_count+scheduler.countScreens());
String getLCDHeader(bool longDisp) {
String ret = String(next_display_count + 1);
if (longDisp)
ret += F("/");
ret += String(static_screen_count + scheduler.countScreens());
ret += F(" ");
return ret;
};

Expand Down
2 changes: 1 addition & 1 deletion src/display/commons.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ String check_display_value(double value, double undef, uint8_t len, uint8_t str_
byte getLCDCols();
byte getLCDRows();
//returns "x/y" where x is current screen being displayed and y total count
String getLCDHeader();
String getLCDHeader(bool longDisp = true);
//should we display? Should we draw new screen?
void cycleDisplay();
#endif //NAMF_DISPLAY_COMMONS_H
47 changes: 19 additions & 28 deletions src/sensors/heca/heca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,31 @@ namespace HECA {
if (enabled && printOnLCD) scheduler.registerDisplay(SimpleScheduler::HECA, 1);
};

bool display(LiquidCrystal_I2C *lcd, byte minor) {
if (lcd == NULL) return true; //we are able to do display
bool display(byte rows, byte minor, String lines[]) {
byte row = 0;
lcd->clear();
if (getLCDRows() == 4) {
lcd->setCursor(0,row++);
lcd->print(getLCDHeader());
lcd->print(F(" "));
lcd->print(FPSTR(SENSORS_HECA));
lines[row] += (FPSTR(SENSORS_HECA));
}
lcd->setCursor(0,row++);
lcd->print(F("RH: "));
lcd->print(check_display_value(last_value_HECA_H, -1, 1, 0));
lcd->print(F(" "));
lcd->print(FPSTR(UNIT_PERCENT));
lcd->setCursor(0,row++);
lcd->print(F("T: "));
lcd->print(check_display_value(last_value_HECA_T, -128, 1, 0));
lcd->print(F(" "));
lcd->print(FPSTR(UNIT_CELCIUS_LCD));
// lcd->print(F(" µg/m³"));
row++;
lines[row] += (F("RH: "));
lines[row] += (check_display_value(last_value_HECA_H, -1, 1, 0));
lines[row] += (F(" "));
lines[row] += (FPSTR(UNIT_PERCENT));
row++;
lines[row] += (F("T: "));
lines[row] += (check_display_value(last_value_HECA_T, -128, 1, 0));
lines[row] += (F(" "));
lines[row] += (FPSTR(UNIT_CELCIUS_LCD));
// lines[row] += (F(" µg/m³"));
if (getLCDRows() == 4) {
lcd->setCursor(0,row);
lcd->print(FPSTR(INTL_HECA_DC));
lcd->print(F(" "));
lcd->print(String(getDutyCycle(),1));
lcd->print(F(" "));
lcd->print(FPSTR(UNIT_PERCENT));
row++;
lines[row] += (FPSTR(INTL_HECA_DC));
lines[row] += (F(" "));
lines[row] += (String(getDutyCycle(),1));
lines[row] += (F(" "));
lines[row] += (FPSTR(UNIT_PERCENT));

}


return false;

}

void initCycle() {
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/heca/heca.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace HECA {
void resultsAsHTML(String &);
void getStatusReport(String &);
bool getDisplaySetting();
bool display(LiquidCrystal_I2C *lcd, byte minor);
bool display(byte rows, byte minor, String lines[]);
float getDutyCycle();
}

Expand Down
21 changes: 7 additions & 14 deletions src/sensors/mhz14a/winsen-mhz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,13 @@ namespace MHZ14A {
return ret;
}

bool display(LiquidCrystal_I2C *lcd, byte minor) {
if (lcd == NULL) return true;
if (getLCDRows() == 2 || getLCDRows() == 4) { // any LCD
lcd->clear();
if (getLCDRows() == 4) {
lcd->print(getLCDHeader());
lcd->print(F(" "));
}
lcd->print(F("CO2 (MHZ14A)"));
lcd->setCursor(0, 1);
lcd->print(last_value_WINSEN_CO2);
lcd->print(F(" ppm"));
}
return false;
void display(byte cols, byte minor, String lines[]) {

lines[0] = (F("CO2 (MHZ14A)"));
lines[1] = String(last_value_WINSEN_CO2);
lines[1] += (F(" ppm"));

return;
};

bool getDisplaySetting() {
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/mhz14a/winsen-mhz.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace MHZ14A {

String getConfigJSON(void);

bool display(LiquidCrystal_I2C *lcd, byte minor);
void display(byte cols, byte minor, String lines[]);

bool getDisplaySetting();

Expand Down
27 changes: 11 additions & 16 deletions src/sensors/sds011/sds011.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,24 +147,19 @@ namespace SDS011 {
return printOnLCD;
};

bool display(LiquidCrystal_I2C *lcd, byte minor) {
if (lcd == NULL) return true; //we are able to do display
bool display(byte rows, byte minor, String lines[]) {
byte row = 0;
lcd->clear();
if (getLCDRows() == 4) {
lcd->setCursor(0,row++);
lcd->print(getLCDHeader());
lcd->print(F(" "));
lcd->print(FPSTR(INTL_SDS011_LCD_HDR));
if (rows == 4) {
lines[row] += FPSTR(INTL_SDS011_LCD_HDR);
}
lcd->setCursor(0,row++);
lcd->print(F("PM2.5:"));
lcd->print(check_display_value(last_value_SDS_P2, -1, 1, 6));
// lcd->print(F(" µg/m³"));
lcd->setCursor(0,row++);
lcd->print(F("PM10: "));
lcd->print(check_display_value(last_value_SDS_P1, -1, 1, 6));
// lcd->print(F(" µg/m³"));
row++;;
lines[row] += F("PM2.5:");
lines[row] += (check_display_value(last_value_SDS_P2, -1, 1, 6));
// lines[row] += (F(" µg/m³"));
row++;;
lines[row] += F("PM10: ");
lines[row] += check_display_value(last_value_SDS_P1, -1, 1, 6);
// lines[row] += (F(" µg/m³"));

return false;
};
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/sds011/sds011.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace SDS011 {

bool getDisplaySetting();

bool display(LiquidCrystal_I2C *lcd, byte minor);
bool display(byte rows, byte minor, String lines[]);

String getConfigJSON();

Expand Down
33 changes: 14 additions & 19 deletions src/sensors/sht3x/sht3x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,22 @@ namespace SHT3x {

}

bool display(LiquidCrystal_I2C *lcd, byte minor) {
if (lcd == NULL) return true; //we are able to do display
void display(byte rows, byte minor, String lines[]) {
byte row = 0;
lcd->clear();
if (getLCDRows() == 4) {
lcd->setCursor(0, row++);
lcd->print(getLCDHeader());
lcd->print(F(" "));
lcd->print(FPSTR(SENSOR_SHT3));
if (rows == 4) {
lines[row++] = FPSTR(SENSOR_SHT3);
}
lcd->setCursor(0, row++);
lcd->print(F("T: "));
lcd->print(check_display_value(currentTemp(), -128, 1, 0));
lcd->print(F(" "));
lcd->print(FPSTR(UNIT_CELCIUS_LCD));
lcd->setCursor(0, row++);
lcd->print(F("RH: "));
lcd->print(check_display_value(currentRH(), -1, 1, 0));
lcd->print(F(" "));
lcd->print(FPSTR(UNIT_PERCENT));
return false;

lines[row] += F("T: ");
lines[row] += check_display_value(currentTemp(), -128, 1, 0);
lines[row] += F(" ");
lines[row] += FPSTR(UNIT_CELCIUS_LCD);

row++;
lines[row] += F("RH: ");
lines[row] += check_display_value(currentRH(), -1, 1, 0);
lines[row] += F(" ");
lines[row] += FPSTR(UNIT_PERCENT);
}

JsonObject &parseHTTPRequest(void) {
Expand Down
2 changes: 1 addition & 1 deletion src/sensors/sht3x/sht3x.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace SHT3x {
extern void results (String &s);
extern void resultsAsHTML(String &page_content);
extern void afterSend(bool success);
extern bool display(LiquidCrystal_I2C *lcd, byte minor);
extern void display(byte, byte, String[]);
bool getDisplaySetting();

}
Expand Down
Loading

0 comments on commit 02c261c

Please sign in to comment.