mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-14 16:36:31 +02:00
Merge branch 'develop' into feature/press-button-for-offline-mode
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
#else
|
||||
#include "EEPROM.h"
|
||||
#endif
|
||||
#include <time.h>
|
||||
|
||||
#define EEPROM_CONFIG_SIZE 1024
|
||||
#define CONFIG_FILE_NAME "/cfg.json"
|
||||
@ -613,6 +614,18 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON.typeof_(root["targetFirmware"]) == "string") {
|
||||
String newVer = root["targetFirmware"];
|
||||
String curVer = String(GIT_VERSION);
|
||||
if (curVer != newVer) {
|
||||
logInfo("Detected new firwmare version: " + newVer);
|
||||
otaNewFirmwareVersion = newVer;
|
||||
udpated = true;
|
||||
} else {
|
||||
otaNewFirmwareVersion = String("");
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
udpated = true;
|
||||
saveConfig();
|
||||
@ -1166,3 +1179,52 @@ bool Configuration::isDisplayBrightnessChanged(void) {
|
||||
displayBrightnessChanged = false;
|
||||
return changed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get number of sec from last OTA
|
||||
*
|
||||
* @return int < 0 is invalid, 0 mean there is no OTA trigger.
|
||||
*/
|
||||
int Configuration::getLastOta(void) {
|
||||
struct tm timeInfo;
|
||||
if (getLocalTime(&timeInfo) == false) {
|
||||
logError("Get localtime failed");
|
||||
return -1;
|
||||
}
|
||||
int curYear = timeInfo.tm_year + 1900;
|
||||
if (curYear < 2024) {
|
||||
logError("Current year " + String(curYear) + String(" invalid"));
|
||||
return -1;
|
||||
}
|
||||
time_t curTime = mktime(&timeInfo);
|
||||
logInfo("Last ota time: " + String(config.lastOta));
|
||||
if (config.lastOta == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sec = curTime - config.lastOta;
|
||||
logInfo("Last ota secconds: " + String(sec));
|
||||
return sec;
|
||||
}
|
||||
|
||||
void Configuration::updateLastOta(void) {
|
||||
struct tm timeInfo;
|
||||
if (getLocalTime(&timeInfo) == false) {
|
||||
logError("updateLastOta: Get localtime failed");
|
||||
return;
|
||||
}
|
||||
int curYear = timeInfo.tm_year + 1900;
|
||||
if (curYear < 2024) {
|
||||
logError("updateLastOta: lolcal time invalid");
|
||||
return;
|
||||
}
|
||||
config.lastOta = mktime(&timeInfo);
|
||||
logInfo("Last OTA: " + String(config.lastOta));
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
String Configuration::newFirmwareVersion(void) {
|
||||
String newFw = otaNewFirmwareVersion;
|
||||
otaNewFirmwareVersion = String("");
|
||||
return newFw;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ private:
|
||||
bool _tvocLearningOffsetChanged;
|
||||
bool ledBarBrightnessChanged = false;
|
||||
bool displayBrightnessChanged = false;
|
||||
String otaNewFirmwareVersion;
|
||||
|
||||
AirGradient* ag;
|
||||
|
||||
@ -74,6 +75,9 @@ public:
|
||||
int getLedBarBrightness(void);
|
||||
bool isDisplayBrightnessChanged(void);
|
||||
int getDisplayBrightness(void);
|
||||
int getLastOta(void);
|
||||
void updateLastOta(void);
|
||||
String newFirmwareVersion(void);
|
||||
bool isOfflineMode(void);
|
||||
void setOfflineMode(bool offline);
|
||||
};
|
||||
|
@ -49,6 +49,16 @@ void OledDisplay::showTempHum(bool hasStatus) {
|
||||
}
|
||||
}
|
||||
|
||||
void OledDisplay::setCentralText(int y, String text) {
|
||||
setCentralText(y, text.c_str());
|
||||
}
|
||||
|
||||
void OledDisplay::setCentralText(int y, const char *text) {
|
||||
int x = (DISP()->getWidth() - DISP()->getStrWidth(text)) / 2;
|
||||
DISP()->drawStr(x, y, text);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Construct a new Ag Oled Display:: Ag Oled Display object
|
||||
*
|
||||
@ -291,3 +301,42 @@ void OledDisplay::showDashboard(const char *status) {
|
||||
void OledDisplay::setBrightness(int percent) {
|
||||
DISP()->setContrast((127 * percent) / 100);
|
||||
}
|
||||
|
||||
void OledDisplay::showNewFirmwareVersion(String version) {
|
||||
DISP()->firstPage();
|
||||
do {
|
||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||
setCentralText(20, "Firmware Update");
|
||||
setCentralText(40, "New version");
|
||||
setCentralText(60, version.c_str());
|
||||
} while (DISP()->nextPage());
|
||||
}
|
||||
|
||||
void OledDisplay::showNewFirmwareUpdating(String percent) {
|
||||
DISP()->firstPage();
|
||||
do {
|
||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||
setCentralText(20, "Firmware Update");
|
||||
setCentralText(50, String("Updating... ") + percent + String("%"));
|
||||
} while (DISP()->nextPage());
|
||||
}
|
||||
|
||||
void OledDisplay::showNewFirmwareSuccess(String count) {
|
||||
DISP()->firstPage();
|
||||
do {
|
||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||
setCentralText(20, "Firmware Update");
|
||||
setCentralText(40, "Success");
|
||||
setCentralText(60, String("Rebooting... ") + count);
|
||||
} while (DISP()->nextPage());
|
||||
}
|
||||
|
||||
void OledDisplay::showNewFirmwareFailed(void) {
|
||||
DISP()->firstPage();
|
||||
do {
|
||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||
setCentralText(20, "Firmware Update");
|
||||
setCentralText(40, "Failed");
|
||||
setCentralText(60, String("Retry after 24h"));
|
||||
} while (DISP()->nextPage());
|
||||
}
|
||||
|
@ -16,6 +16,9 @@ private:
|
||||
Measurements &value;
|
||||
|
||||
void showTempHum(bool hasStatus);
|
||||
void setCentralText(int y, String text);
|
||||
void setCentralText(int y, const char *text);
|
||||
|
||||
public:
|
||||
OledDisplay(Configuration &config, Measurements &value,
|
||||
Stream &log);
|
||||
@ -32,6 +35,10 @@ public:
|
||||
void showDashboard(void);
|
||||
void showDashboard(const char *status);
|
||||
void setBrightness(int percent);
|
||||
void showNewFirmwareVersion(String version);
|
||||
void showNewFirmwareUpdating(String percent);
|
||||
void showNewFirmwareSuccess(String count);
|
||||
void showNewFirmwareFailed(void);
|
||||
};
|
||||
|
||||
#endif /** _AG_OLED_DISPLAY_H_ */
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "AgWiFiConnector.h"
|
||||
#include "Libraries/WiFiManager/WiFiManager.h"
|
||||
#include <time.h>
|
||||
|
||||
#define WIFI_CONNECT_COUNTDOWN_MAX 180
|
||||
#define WIFI_HOTSPOT_PASSWORD_DEFAULT "cleanair"
|
||||
@ -158,6 +159,11 @@ bool WifiConnector::connect(void) {
|
||||
config.setPostToAirGradient(result != "T");
|
||||
}
|
||||
hasPortalConfig = false;
|
||||
|
||||
/** Configure internet time */
|
||||
const char *ntp_server = "pool.ntp.org";
|
||||
configTime(0, 0, ntp_server);
|
||||
logInfo("Set internet time server: " + String(ntp_server));
|
||||
}
|
||||
#else
|
||||
_wifiProcess();
|
||||
|
@ -61,6 +61,9 @@ enum AgStateMachineState {
|
||||
AgStateMachineLedBarTest,
|
||||
AgStateMachineLedBarPowerUpTest,
|
||||
|
||||
/** OTA perform, show display status */
|
||||
AgStateMachineOtaPerform,
|
||||
|
||||
/** LED: Show working state.
|
||||
* Display: Show dashboard */
|
||||
AgStateMachineNormal,
|
||||
|
Reference in New Issue
Block a user