code is now compatible with standard OLED displays and original code base (default pw length = 32)

This commit is contained in:
Rainer Stransky 2020-08-19 12:35:14 +02:00
parent 3cf22bb65a
commit f7293003fb
2 changed files with 131 additions and 129 deletions

View File

@ -4,17 +4,19 @@
(c) 2019 by M. Lehmann (c) 2019 by M. Lehmann
------------------------------------------------------------------ ------------------------------------------------------------------
*/ */
#define CGSCALE_VERSION "2.1" #define CGSCALE_VERSION "2.2"
/* /*
****************************************************************** ******************************************************************
history: history:
V2.2 18.08.20 code is now compatible with standard OLED displays
and original code base (default pw length = 32)
V2.1 18.07.20 added support for ESP8266 based Wifi Kit 8 V2.1 18.07.20 added support for ESP8266 based Wifi Kit 8
(by Pulsar07/ (https://heltec.org/project/wifi-kit-8/) (by Pulsar07/ (https://heltec.org/project/wifi-kit-8/)
R.Stransky is a ESP8266 with R.Stransky is a ESP8266 with
* a build in OLED 128x32 a build in OLED 128x32
* battery connector with charging management battery connector with charging management
* reset and GPIO0 button reset and GPIO0 button
support for a tare button (PIN_TARE_BUTTON) support for a tare button (PIN_TARE_BUTTON)
bug fixed: wifi password now with up to 64 chars bug fixed: wifi password now with up to 64 chars
bug fixed: wifi data (ssid/passwd) with special bug fixed: wifi data (ssid/passwd) with special
@ -98,7 +100,7 @@
#endif #endif
// HX711 constructor array (dout pin, sck pint): // HX711 constructor array (dout pin, sck pint):
HX711_ADC LoadCell[]{HX711_ADC(PIN_LOADCELL1_DOUT, PIN_LOADCELL1_PD_SCK),HX711_ADC(PIN_LOADCELL2_DOUT, PIN_LOADCELL2_PD_SCK),HX711_ADC(PIN_LOADCELL3_DOUT, PIN_LOADCELL3_PD_SCK)}; HX711_ADC LoadCell[] {HX711_ADC(PIN_LOADCELL1_DOUT, PIN_LOADCELL1_PD_SCK), HX711_ADC(PIN_LOADCELL2_DOUT, PIN_LOADCELL2_PD_SCK), HX711_ADC(PIN_LOADCELL3_DOUT, PIN_LOADCELL3_PD_SCK)};
// webserver constructor // webserver constructor
#if defined(ESP8266) #if defined(ESP8266)
@ -153,6 +155,12 @@ bool updateMenu = true;
int menuPage = 0; int menuPage = 0;
String errMsg[5]; String errMsg[5];
int errMsgCnt = 0; int errMsgCnt = 0;
int oledDisplayHeight;
int oledDisplayWidth;
const uint8_t *oledFontLarge;
const uint8_t *oledFontNormal;
const uint8_t *oledFontSmall;
const uint8_t *oledFontTiny;
#if defined(ESP8266) #if defined(ESP8266)
String updateMsg = ""; String updateMsg = "";
bool wifiSTAmode = true; bool wifiSTAmode = true;
@ -169,40 +177,50 @@ void resetCPU() {}
void initOLED() { void initOLED() {
oledDisplay.begin(); oledDisplay.begin();
oledDisplayHeight = oledDisplay.getDisplayHeight();
oledDisplayWidth = oledDisplay.getDisplayWidth();
printConsole(T_BOOT, "init OLED display: " + String(oledDisplayWidth) + String("x") + String(oledDisplayHeight));
const uint8_t *font;
font = u8g2_font_6x12_tr; oledFontLarge = u8g2_font_helvR12_tr;
int displayHeight = oledDisplay.getDisplayHeight(); oledFontNormal = u8g2_font_helvR10_tr;
int displayWidth = oledDisplay.getDisplayWidth(); oledFontSmall = u8g2_font_5x7_tr;
if (displayHeight <= 32) { oledFontTiny = u8g2_font_4x6_tr;
font = u8g2_font_6x12_tr;
if (oledDisplayHeight <= 32) {
oledFontLarge = u8g2_font_helvR10_tr;
oledFontNormal = u8g2_font_6x12_tr;
} }
int ylineHeight = displayHeight/3; int ylineHeight = oledDisplayHeight / 3;
oledDisplay.setFont(oledFontNormal);
oledDisplay.firstPage(); oledDisplay.firstPage();
do { do {
if (displayHeight <= 32) { oledDisplay.setFont(oledFontLarge);
if (oledDisplayHeight <= 32) {
oledDisplay.drawXBMP(5, 0, 18, 18, CGImage); oledDisplay.drawXBMP(5, 0, 18, 18, CGImage);
} else { } else {
oledDisplay.drawXBMP(20, 12, 18, 18, CGImage); oledDisplay.drawXBMP(20, 12, 18, 18, CGImage);
} }
oledDisplay.setFont(u8g2_font_helvR12_tr); oledDisplay.setFont(oledFontLarge);
if (displayHeight <= 32) {
if (oledDisplayHeight <= 32) {
oledDisplay.setCursor(30, 12); oledDisplay.setCursor(30, 12);
} else { } else {
oledDisplay.setCursor(45, 28); oledDisplay.setCursor(45, 28);
} }
oledDisplay.print(F("CG scale")); oledDisplay.print(F("CG scale"));
oledDisplay.setFont(u8g2_font_5x7_tr); oledDisplay.setFont(oledFontSmall);
if (displayHeight <= 32) { if (oledDisplayHeight <= 32) {
oledDisplay.setCursor(30, 22); oledDisplay.setCursor(30, 22);
} else { } else {
oledDisplay.setCursor(35, 55); oledDisplay.setCursor(35, 55);
} }
oledDisplay.print(F("Version: ")); oledDisplay.print(F("Version: "));
oledDisplay.print(CGSCALE_VERSION); oledDisplay.print(CGSCALE_VERSION);
if (displayHeight <= 32) { if (oledDisplayHeight <= 32) {
oledDisplay.setCursor(5, 31); oledDisplay.setCursor(5, 31);
} else { } else {
oledDisplay.setCursor(20, 64); oledDisplay.setCursor(20, 64);
@ -212,35 +230,28 @@ void initOLED() {
} while ( oledDisplay.nextPage() ); } while ( oledDisplay.nextPage() );
} }
void printOLED(String aLine1, String aLine2, String aLine3=String("")); void printOLED(String aLine1, String aLine2, String aLine3 = String(""));
void printOLED(String aLine1, String aLine2, String aLine3) { void printOLED(String aLine1, String aLine2, String aLine3) {
const uint8_t *font; int ylineHeight = oledDisplayHeight / 3;
font = u8g2_font_6x12_tr;
int displayHeight = oledDisplay.getDisplayHeight();
int displayWidth = oledDisplay.getDisplayWidth();
font = u8g2_font_helvR10_tr;
if (displayHeight <= 32) {
font = u8g2_font_6x12_tr;
}
int ylineHeight = displayHeight/3;
oledDisplay.firstPage(); oledDisplay.firstPage();
do { do {
oledDisplay.setFont(u8g2_font_6x12_tr); oledDisplay.setFont(oledFontNormal);
oledDisplay.setCursor(0, ylineHeight*1); oledDisplay.setCursor(0, ylineHeight * 1);
oledDisplay.print(aLine1); oledDisplay.print(aLine1);
oledDisplay.setCursor(0, ylineHeight*2); oledDisplay.setCursor(0, ylineHeight * 2);
oledDisplay.print(aLine2); oledDisplay.print(aLine2);
if (aLine3 == "") { if (aLine3 == "") {
oledDisplay.drawLine(0, ylineHeight*2 + 2, displayWidth, ylineHeight*2+2); oledDisplay.drawLine(0, ylineHeight * 2 + 2, oledDisplayWidth, ylineHeight * 2 + 2);
oledDisplay.setFont(u8g2_font_4x6_tr); oledDisplay.setFont(oledFontTiny);
oledDisplay.setCursor(0, displayHeight); oledDisplay.setCursor(0, oledDisplayHeight);
oledDisplay.print("IP:" + WiFi.localIP().toString());
String signature = "CG scale: V" + String(CGSCALE_VERSION); String signature = "CG scale: V" + String(CGSCALE_VERSION);
oledDisplay.setCursor(displayWidth - oledDisplay.getStrWidth(signature.c_str()), displayHeight); oledDisplay.setCursor(oledDisplayWidth - oledDisplay.getStrWidth(signature.c_str()), oledDisplayHeight);
oledDisplay.print(signature); oledDisplay.print(signature);
} else { } else {
oledDisplay.setCursor(0, displayHeight); oledDisplay.setCursor(0, oledDisplayHeight);
oledDisplay.print(aLine3); oledDisplay.print(aLine3);
} }
} while ( oledDisplay.nextPage() ); } while ( oledDisplay.nextPage() );
@ -248,7 +259,9 @@ void printOLED(String aLine1, String aLine2, String aLine3) {
void printScaleOLED() { void printScaleOLED() {
// print to display // print to display
char buff[8]; char buff1[8];
char buff[12];
char buff2[8];
int pos_weightTotal = 7; int pos_weightTotal = 7;
int pos_CG_length = 28; int pos_CG_length = 28;
if (nLoadcells == 2) { if (nLoadcells == 2) {
@ -260,19 +273,6 @@ void printScaleOLED() {
} }
} }
const uint8_t *font;
int linestart = 14;
int linedist = 25;
int col0=0;
int col1=28;
font = u8g2_font_helvR12_tr;
if (oledDisplay.getDisplayHeight() <=32) {
font = u8g2_font_6x12_tr;
linestart = 8;
linedist = 12;
col0=0;
col1=28;
}
oledDisplay.firstPage(); oledDisplay.firstPage();
do { do {
if (errMsgCnt == 0) { if (errMsgCnt == 0) {
@ -283,7 +283,7 @@ void printScaleOLED() {
dtostrf(percentVolt, 3, 0, buff); dtostrf(percentVolt, 3, 0, buff);
oledDisplay.drawBox(49, 2, (percentVolt / (100 / 8)), 4); oledDisplay.drawBox(49, 2, (percentVolt / (100 / 8)), 4);
oledDisplay.setFont(u8g2_font_5x7_tr); oledDisplay.setFont(oledFontSmall);
oledDisplay.setCursor(78 - oledDisplay.getStrWidth(buff), 7); oledDisplay.setCursor(78 - oledDisplay.getStrWidth(buff), 7);
if (batType > B_VOLT) { if (batType > B_VOLT) {
dtostrf(percentVolt, 3, 0, buff); dtostrf(percentVolt, 3, 0, buff);
@ -296,46 +296,46 @@ void printScaleOLED() {
} }
// print total weight // print total weight
oledDisplay.setFont(font); oledDisplay.setFont(oledFontNormal);
if (oledDisplay.getDisplayHeight() <= 32) { dtostrf(weightTotal, 7, 1, buff);
if (oledDisplayHeight <= 32) {
oledDisplay.setCursor(1, 18); oledDisplay.setCursor(1, 18);
oledDisplay.print(F("M = ")); oledDisplay.print(F("M = "));
} else { } else {
oledDisplay.drawXBMP(2, pos_weightTotal, 18, 18, weightImage); oledDisplay.drawXBMP(2, pos_weightTotal, 18, 18, weightImage);
oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_weightTotal + 17); oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_weightTotal + 17);
} }
dtostrf(weightTotal, 5, 1, buff);
oledDisplay.print(buff); oledDisplay.print(buff);
oledDisplay.print(F("g")); oledDisplay.print(F(" g"));
// print CG longitudinal axis // print CG longitudinal axis
if (oledDisplay.getDisplayHeight() <=32) { dtostrf(CG_length, 7, 1, buff);
if (oledDisplayHeight <= 32) {
oledDisplay.setCursor(1, 32); oledDisplay.setCursor(1, 32);
oledDisplay.print(F("CG = ")); oledDisplay.print(F("CG = "));
} else { } else {
oledDisplay.drawXBMP(2, pos_CG_length, 18, 18, CGImage); oledDisplay.drawXBMP(2, pos_CG_length, 18, 18, CGImage);
oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_CG_length + 16); oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), pos_CG_length + 16);
} }
dtostrf(CG_length, 5, 1, buff);
oledDisplay.print(buff); oledDisplay.print(buff);
oledDisplay.print(F("mm")); oledDisplay.print(F(" mm"));
// print CG transverse axis // print CG transverse axis
if (nLoadcells == 3) { if (nLoadcells == 3) {
if (oledDisplay.getDisplayHeight() <=32) { if (oledDisplayHeight <= 32) {
oledDisplay.setCursor(78, 32); oledDisplay.setCursor(78, 32);
oledDisplay.print(F("LR=")); oledDisplay.print(F("LR="));
dtostrf(CG_trans, 3, 0, buff); dtostrf(CG_trans, 3, 0, buff);
} else { } else {
oledDisplay.drawXBMP(2, 47, 18, 18, CGtransImage); oledDisplay.drawXBMP(2, 47, 18, 18, CGtransImage);
oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), 64); oledDisplay.setCursor(93 - oledDisplay.getStrWidth(buff), 64);
dtostrf(CG_trans, 5, 1, buff); dtostrf(CG_trans, 7, 1, buff);
} }
oledDisplay.print(buff); oledDisplay.print(buff);
oledDisplay.print(F("mm")); oledDisplay.print(F(" mm"));
} }
} else { } else {
oledDisplay.setFont(u8g2_font_5x7_tr); oledDisplay.setFont(oledFontSmall);
for (int i = 1; i <= errMsgCnt; i++) { for (int i = 1; i <= errMsgCnt; i++) {
oledDisplay.setCursor(0, 7 * i); oledDisplay.setCursor(0, 7 * i);
oledDisplay.print(errMsg[i]); oledDisplay.print(errMsg[i]);
@ -345,19 +345,21 @@ void printScaleOLED() {
} while ( oledDisplay.nextPage() ); } while ( oledDisplay.nextPage() );
} }
#ifdef PIN_TARE_BUTTON #ifdef PIN_TARE_BUTTON
void handleTareBtn() { void handleTareBtn() {
static unsigned long lastTaraBtn = 0; static unsigned long lastTaraBtn = 0;
if ((millis() - lastTaraBtn) > 20) { if ((millis() - lastTaraBtn) > 20) {
lastTaraBtn = millis(); lastTaraBtn = millis();
static int tareBtnCnt = 0; static int tareBtnCnt = 0;
if(digitalRead(PIN_TARE_BUTTON)) { if (digitalRead(PIN_TARE_BUTTON)) {
tareBtnCnt = 0; tareBtnCnt = 0;
} else { } else {
tareBtnCnt++; tareBtnCnt++;
if (tareBtnCnt > 10) { if (tareBtnCnt > 10) {
Serial.println("tare button pressed"); Serial.println("tare button pressed");
printOLED("TARE ==>"," tare load cells ..."); printOLED("TARE ==>", " tare load cells ...");
// avoid keybounce // avoid keybounce
tareBtnCnt = -1000; tareBtnCnt = -1000;
tareLoadcells(); tareLoadcells();
@ -378,7 +380,7 @@ void saveCalFactor(int nLC) {
} }
void updateLoadcells(){ void updateLoadcells() {
for (int i = LC1; i <= LC3; i++) { for (int i = LC1; i <= LC3; i++) {
if (i < nLoadcells) { if (i < nLoadcells) {
LoadCell[i].update(); LoadCell[i].update();
@ -387,7 +389,7 @@ void updateLoadcells(){
} }
void tareLoadcells(){ void tareLoadcells() {
for (int i = LC1; i <= LC3; i++) { for (int i = LC1; i <= LC3; i++) {
if (i < nLoadcells) { if (i < nLoadcells) {
LoadCell[i].tare(); LoadCell[i].tare();
@ -396,7 +398,7 @@ void tareLoadcells(){
} }
void printNewValueText(){ void printNewValueText() {
Serial.print(F("Set new value:")); Serial.print(F("Set new value:"));
} }
@ -473,9 +475,9 @@ int percentBat(float cellVoltage) {
for (int i = 0; i <= elementCount; i++) { for (int i = 0; i <= elementCount; i++) {
float curVolt = pgm_read_float(&percentList[batTypeArray][i][0]); float curVolt = pgm_read_float(&percentList[batTypeArray][i][0]);
if (curVolt >= cellVoltage && i > 0) { if (curVolt >= cellVoltage && i > 0) {
float lastVolt = pgm_read_float(&percentList[batTypeArray][i-1][0]); float lastVolt = pgm_read_float(&percentList[batTypeArray][i - 1][0]);
float curPercent = pgm_read_float(&percentList[batTypeArray][i][1]); float curPercent = pgm_read_float(&percentList[batTypeArray][i][1]);
float lastPercent = pgm_read_float(&percentList[batTypeArray][i-1][1]); float lastPercent = pgm_read_float(&percentList[batTypeArray][i - 1][1]);
result = float((cellVoltage - lastVolt) / (curVolt - lastVolt)) * (curPercent - lastPercent) + lastPercent; result = float((cellVoltage - lastVolt) / (curVolt - lastVolt)) * (curPercent - lastPercent) + lastPercent;
break; break;
} }
@ -579,9 +581,6 @@ void setup() {
#endif #endif
// init OLED display // init OLED display
#if defined(ESP8266)
printConsole(T_BOOT, "init OLED display: " + String(oledDisplay.getDisplayWidth())+ String("x") + String(oledDisplay.getDisplayHeight()));
#endif
initOLED(); initOLED();
// init & tare Loadcells // init & tare Loadcells
@ -590,7 +589,7 @@ void setup() {
LoadCell[i].begin(); LoadCell[i].begin();
LoadCell[i].setCalFactor(calFactorLoadcell[i]); LoadCell[i].setCalFactor(calFactorLoadcell[i]);
#if defined(ESP8266) #if defined(ESP8266)
printConsole(T_BOOT, "init Loadcell " + String(i+1)); printConsole(T_BOOT, "init Loadcell " + String(i + 1));
#endif #endif
} }
} }
@ -606,12 +605,13 @@ void setup() {
#if defined(ESP8266) #if defined(ESP8266)
printConsole(T_BOOT, "Wifi: STA mode - connecing with: " + String(ssid_STA));
// Start by connecting to a WiFi network // Start by connecting to a WiFi network
WiFi.persistent(false); WiFi.persistent(false);
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
WiFi.begin(ssid_STA, password_STA); WiFi.begin(ssid_STA, password_STA);
printConsole(T_BOOT, "Wifi: STA mode - connect with: " + String(ssid_STA));
long timeoutWiFi = millis(); long timeoutWiFi = millis();
@ -653,7 +653,7 @@ void setup() {
if (!MDNS.begin(hostname, WiFi.localIP())) { if (!MDNS.begin(hostname, WiFi.localIP())) {
hostname = "mDNS failed"; hostname = "mDNS failed";
printConsole(T_ERROR, "Wifi: " + hostname); printConsole(T_ERROR, "Wifi: " + hostname);
}else{ } else {
hostname += ".local"; hostname += ".local";
printConsole(T_RUN, "Wifi: " + hostname); printConsole(T_RUN, "Wifi: " + hostname);
} }
@ -703,7 +703,7 @@ void setup() {
printConsole(T_RUN, "Webserver is up and running"); printConsole(T_RUN, "Webserver is up and running");
// init OTA (over the air update) // init OTA (over the air update)
if(enableOTA){ if (enableOTA) {
ArduinoOTA.setHostname(ssid_AP); ArduinoOTA.setHostname(ssid_AP);
ArduinoOTA.setPassword(password_AP); ArduinoOTA.setPassword(password_AP);
@ -749,7 +749,7 @@ void setup() {
// https update // https update
httpsClient.setInsecure(); httpsClient.setInsecure();
if(enableUpdate){ if (enableUpdate) {
// check for update // check for update
httpsUpdate(PROBE_UPDATE); httpsUpdate(PROBE_UPDATE);
} }
@ -767,15 +767,15 @@ void loop() {
MDNS.update(); MDNS.update();
#endif #endif
if(enableOTA){ if (enableOTA) {
ArduinoOTA.handle(); ArduinoOTA.handle();
} }
server.handleClient(); server.handleClient();
#endif #endif
#ifdef PIN_TARE_BUTTON #ifdef PIN_TARE_BUTTON
handleTareBtn(); handleTareBtn();
#endif #endif
updateLoadcells(); updateLoadcells();
@ -811,9 +811,9 @@ void loop() {
CG_length = ((weightLoadCell[LC2] * model.distance[X2]) / weightTotal) + model.distance[X1]; CG_length = ((weightLoadCell[LC2] * model.distance[X2]) / weightTotal) + model.distance[X1];
#if defined(ESP8266) #if defined(ESP8266)
if(model.mechanicsType == 2){ if (model.mechanicsType == 2) {
CG_length = ((weightLoadCell[LC2] * model.distance[X2]) / weightTotal) - model.distance[X1]; CG_length = ((weightLoadCell[LC2] * model.distance[X2]) / weightTotal) - model.distance[X1];
}else if(model.mechanicsType == 3){ } else if (model.mechanicsType == 3) {
CG_length = ((weightLoadCell[LC2] * model.distance[X2]) / weightTotal) * -1 + model.distance[X1]; CG_length = ((weightLoadCell[LC2] * model.distance[X2]) / weightTotal) * -1 + model.distance[X1];
} }
#endif #endif
@ -835,7 +835,6 @@ void loop() {
printScaleOLED(); printScaleOLED();
// serial connection // serial connection
if (Serial) { if (Serial) {
if (Serial.available() > 0) { if (Serial.available() > 0) {
@ -969,7 +968,7 @@ void loop() {
for (int i = X1; i <= X3; i++) { for (int i = X1; i <= X3; i++) {
Serial.print(MENU_DISTANCE_X1 + i); Serial.print(MENU_DISTANCE_X1 + i);
Serial.print(F(" - Set distance X")); Serial.print(F(" - Set distance X"));
Serial.print(i+1); Serial.print(i + 1);
Serial.print(F(" (")); Serial.print(F(" ("));
Serial.print(model.distance[i]); Serial.print(model.distance[i]);
Serial.print(F("mm)\n")); Serial.print(F("mm)\n"));
@ -990,9 +989,9 @@ void loop() {
for (int i = LC1; i <= LC3; i++) { for (int i = LC1; i <= LC3; i++) {
Serial.print(MENU_LOADCELL1_CALIBRATION_FACTOR + i); Serial.print(MENU_LOADCELL1_CALIBRATION_FACTOR + i);
if((MENU_LOADCELL1_CALIBRATION_FACTOR + i) < 10) Serial.print(F(" ")); if ((MENU_LOADCELL1_CALIBRATION_FACTOR + i) < 10) Serial.print(F(" "));
Serial.print(F(" - Set calibration factor of load cell ")); Serial.print(F(" - Set calibration factor of load cell "));
Serial.print(i+1); Serial.print(i + 1);
Serial.print(F(" (")); Serial.print(F(" ("));
Serial.print(calFactorLoadcell[i]); Serial.print(calFactorLoadcell[i]);
Serial.print(F(")\n")); Serial.print(F(")\n"));
@ -1001,7 +1000,7 @@ void loop() {
for (int i = R1; i <= R2; i++) { for (int i = R1; i <= R2; i++) {
Serial.print(MENU_RESISTOR_R1 + i); Serial.print(MENU_RESISTOR_R1 + i);
Serial.print(F(" - Set value of resistor R")); Serial.print(F(" - Set value of resistor R"));
Serial.print(i+1); Serial.print(i + 1);
Serial.print(F(" (")); Serial.print(F(" ("));
Serial.print(resistor[i]); Serial.print(resistor[i]);
Serial.print(F("ohm)\n")); Serial.print(F("ohm)\n"));
@ -1366,10 +1365,10 @@ void getWiFiNetworks() {
if (n > 0) { if (n > 0) {
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
response += WiFi.SSID(i); response += WiFi.SSID(i);
if(WiFi.SSID(i) == ssid_STA) ssidSTAavailable = true; if (WiFi.SSID(i) == ssid_STA) ssidSTAavailable = true;
if (i < n - 1) response += "&"; if (i < n - 1) response += "&";
} }
if(!ssidSTAavailable){ if (!ssidSTAavailable) {
response += "&"; response += "&";
response += ssid_STA; response += ssid_STA;
} }
@ -1421,7 +1420,7 @@ void saveParameter() {
EEPROM.put(P_ENABLE_OTA, enableOTA); EEPROM.put(P_ENABLE_OTA, enableOTA);
EEPROM.commit(); EEPROM.commit();
if(model.name != ""){ if (model.name != "") {
saveModelJson(model.name); saveModelJson(model.name);
} }
@ -1710,11 +1709,10 @@ void printUpdateProgress(unsigned int progress, unsigned int total) {
oledDisplay.firstPage(); oledDisplay.firstPage();
do { do {
oledDisplay.setFont(u8g2_font_helvR08_tr); oledDisplay.setFont(oledFontSmall);
oledDisplay.setCursor(0, 12); oledDisplay.setCursor(0, 12);
oledDisplay.print(updateMsg); oledDisplay.print(updateMsg);
oledDisplay.setFont(u8g2_font_5x7_tr);
oledDisplay.setCursor(107, 35); oledDisplay.setCursor(107, 35);
oledDisplay.printf("%u%%\r", (progress / (total / 100))); oledDisplay.printf("%u%%\r", (progress / (total / 100)));
@ -1739,10 +1737,10 @@ char * TimeToString(unsigned long t)
return str; return str;
} }
void printConsole(int t, String msg){ void printConsole(int t, String msg) {
Serial.print(TimeToString(millis())); Serial.print(TimeToString(millis()));
Serial.print(" ["); Serial.print(" [");
switch(t) { switch (t) {
case T_BOOT: case T_BOOT:
Serial.print("BOOT"); Serial.print("BOOT");
break; break;
@ -1768,7 +1766,7 @@ void printConsole(int t, String msg){
// https update // https update
bool httpsUpdate(uint8_t command){ bool httpsUpdate(uint8_t command) {
if (!httpsClient.connect(HOST, HTTPS_PORT)) { if (!httpsClient.connect(HOST, HTTPS_PORT)) {
printConsole(T_ERROR, "Wifi: connection to GIT failed"); printConsole(T_ERROR, "Wifi: connection to GIT failed");
return false; return false;
@ -1792,24 +1790,24 @@ bool httpsUpdate(uint8_t command){
// response // response
if (httpCode == HTTP_CODE_FOUND) { if (httpCode == HTTP_CODE_FOUND) {
String newUrl = https.header("Location"); String newUrl = https.header("Location");
gitVersion = newUrl.substring(newUrl.lastIndexOf('/')+2).toFloat(); gitVersion = newUrl.substring(newUrl.lastIndexOf('/') + 2).toFloat();
if(gitVersion > String(CGSCALE_VERSION).toFloat()){ if (gitVersion > String(CGSCALE_VERSION).toFloat()) {
printConsole(T_UPDATE, "Firmware update available: V" + String(gitVersion)); printConsole(T_UPDATE, "Firmware update available: V" + String(gitVersion));
}else{ } else {
printConsole(T_UPDATE, "Firmware version found on GitHub: V" + String(gitVersion) + " - current firmware is up to date"); printConsole(T_UPDATE, "Firmware version found on GitHub: V" + String(gitVersion) + " - current firmware is up to date");
} }
}else if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) { } else if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
Serial.println(https.getString()); Serial.println(https.getString());
}else{ } else {
printConsole(T_ERROR, "HTTPS: GET... failed, " + https.errorToString(httpCode)); printConsole(T_ERROR, "HTTPS: GET... failed, " + https.errorToString(httpCode));
https.end(); https.end();
return false; return false;
} }
}else { } else {
return false; return false;
} }
https.end(); https.end();
}else { } else {
printConsole(T_ERROR, "Wifi: Unable to connect"); printConsole(T_ERROR, "Wifi: Unable to connect");
return false; return false;
} }

View File

@ -48,7 +48,7 @@ CG scale with 3 Loadcells:
// Wifi Kit 8 (https://heltec.org/project/wifi-kit-8/) // Wifi Kit 8 (https://heltec.org/project/wifi-kit-8/)
// is a ESP8266 based board, with integrated OLED and battery management // is a ESP8266 based board, with integrated OLED and battery management
// #define WIFI_KIT_8 1 #define WIFI_KIT_8 1
#ifdef WIFI_KIT_8 #ifdef WIFI_KIT_8
#define PIN_LOADCELL1_DOUT D6 #define PIN_LOADCELL1_DOUT D6
#define PIN_LOADCELL1_PD_SCK D7 #define PIN_LOADCELL1_PD_SCK D7
@ -62,6 +62,8 @@ CG scale with 3 Loadcells:
// D3 can be used in parallel to the load cell with Wifi Kit 8 // D3 can be used in parallel to the load cell with Wifi Kit 8
#define PIN_TARE_BUTTON D3 #define PIN_TARE_BUTTON D3
#define MAX_SSID_PW_LENGHT 64
#else #else
#define PIN_LOADCELL1_DOUT D6 #define PIN_LOADCELL1_DOUT D6
#define PIN_LOADCELL1_PD_SCK D5 #define PIN_LOADCELL1_PD_SCK D5
@ -151,7 +153,9 @@ CG scale with 3 Loadcells:
// **** Wifi settings **** // **** Wifi settings ****
#define MAX_SSID_PW_LENGHT 64 #ifndef MAX_SSID_PW_LENGHT
#define MAX_SSID_PW_LENGHT 32
#endif
// Station mode: connect to available network // Station mode: connect to available network
#define SSID_STA "myWiFi" #define SSID_STA "myWiFi"