forked from airgradienthq/arduino
Merge pull request #119 from airgradienthq/hotfix/fix-issue-before-release-new-version
Hotfix: Fix some issue before release new version
This commit is contained in:
@ -239,6 +239,9 @@ void setup() {
|
|||||||
if (ag->isOne()) {
|
if (ag->isOne()) {
|
||||||
oledDisplay.setText("Warming Up", "Serial Number:", ag->deviceId().c_str());
|
oledDisplay.setText("Warming Up", "Serial Number:", ag->deviceId().c_str());
|
||||||
delay(DISPLAY_DELAY_SHOW_CONTENT_MS);
|
delay(DISPLAY_DELAY_SHOW_CONTENT_MS);
|
||||||
|
|
||||||
|
Serial.println("Display brightness: " + String(configuration.getDisplayBrightness()));
|
||||||
|
oledDisplay.setBrightness(configuration.getDisplayBrightness());
|
||||||
}
|
}
|
||||||
|
|
||||||
appLedHandler();
|
appLedHandler();
|
||||||
@ -399,9 +402,8 @@ static void factoryConfigReset(void) {
|
|||||||
mqttTask = NULL;
|
mqttTask = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Disconnect WIFI */
|
/** Reset WIFI */
|
||||||
wifiConnector.disconnect();
|
WiFi.disconnect(true, true);
|
||||||
wifiConnector.reset();
|
|
||||||
|
|
||||||
/** Reset local config */
|
/** Reset local config */
|
||||||
configuration.reset();
|
configuration.reset();
|
||||||
@ -437,14 +439,20 @@ static void factoryConfigReset(void) {
|
|||||||
static void wdgFeedUpdate(void) {
|
static void wdgFeedUpdate(void) {
|
||||||
ag->watchdog.reset();
|
ag->watchdog.reset();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("External watchdog feed");
|
Serial.println("Offline mode or isPostToAirGradient = false: watchdog reset");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ledBarEnabledUpdate(void) {
|
static void ledBarEnabledUpdate(void) {
|
||||||
if (ag->isOne()) {
|
if (ag->isOne()) {
|
||||||
ag->ledBar.setBrighness(configuration.getLedBarBrightness());
|
int brightness = configuration.getLedBarBrightness();
|
||||||
ag->ledBar.setEnable(configuration.getLedBarMode() != LedBarModeOff);
|
Serial.println("LED bar brightness: " + String(brightness));
|
||||||
|
if ((brightness == 0) || (configuration.getLedBarMode() == LedBarModeOff)) {
|
||||||
|
ag->ledBar.setEnable(false);
|
||||||
|
} else {
|
||||||
|
ag->ledBar.setBrighness(brightness);
|
||||||
|
ag->ledBar.setEnable(configuration.getLedBarMode() != LedBarModeOff);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,11 +583,6 @@ static void sendDataToAg() {
|
|||||||
stateMachine.handleLeds(AgStateMachineNormal);
|
stateMachine.handleLeds(AgStateMachineNormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Must reset each 5min to avoid ESP32 reset
|
|
||||||
*/
|
|
||||||
static void resetWatchdog() { ag->watchdog.reset(); }
|
|
||||||
|
|
||||||
void dispSensorNotFound(String ss) {
|
void dispSensorNotFound(String ss) {
|
||||||
ss = ss + " not found";
|
ss = ss + " not found";
|
||||||
oledDisplay.setText("Sensor init", "Error:", ss.c_str());
|
oledDisplay.setText("Sensor init", "Error:", ss.c_str());
|
||||||
@ -871,14 +874,17 @@ static void appLedHandler(void) {
|
|||||||
static void appDispHandler(void) {
|
static void appDispHandler(void) {
|
||||||
if (ag->isOne()) {
|
if (ag->isOne()) {
|
||||||
AgStateMachineState state = AgStateMachineNormal;
|
AgStateMachineState state = AgStateMachineNormal;
|
||||||
if (wifiConnector.isConnected() == false) {
|
|
||||||
state = AgStateMachineWiFiLost;
|
|
||||||
} else if (apiClient.isFetchConfigureFailed()) {
|
|
||||||
state = AgStateMachineSensorConfigFailed;
|
|
||||||
} else if (apiClient.isPostToServerFailed()) {
|
|
||||||
state = AgStateMachineServerLost;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/** Only show display status on online mode. */
|
||||||
|
if (configuration.isOfflineMode() == false) {
|
||||||
|
if (wifiConnector.isConnected() == false) {
|
||||||
|
state = AgStateMachineWiFiLost;
|
||||||
|
} else if (apiClient.isFetchConfigureFailed()) {
|
||||||
|
state = AgStateMachineSensorConfigFailed;
|
||||||
|
} else if (apiClient.isPostToServerFailed()) {
|
||||||
|
state = AgStateMachineServerLost;
|
||||||
|
}
|
||||||
|
}
|
||||||
stateMachine.displayHandle(state);
|
stateMachine.displayHandle(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1092,10 +1098,19 @@ static void updatePm(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void sendDataToServer(void) {
|
static void sendDataToServer(void) {
|
||||||
|
/** Ignore send data to server if postToAirGradient disabled */
|
||||||
|
if (configuration.isPostDataToAirGradient() == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI(),
|
String syncData = measurements.toString(false, fwMode, wifiConnector.RSSI(),
|
||||||
ag, &configuration);
|
ag, &configuration);
|
||||||
if (apiClient.postToServer(syncData)) {
|
if (apiClient.postToServer(syncData)) {
|
||||||
resetWatchdog();
|
ag->watchdog.reset();
|
||||||
|
Serial.println();
|
||||||
|
Serial.println(
|
||||||
|
"Online mode and isPostToAirGradient = true: watchdog reset");
|
||||||
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
measurements.bootCount++;
|
measurements.bootCount++;
|
||||||
|
@ -103,7 +103,12 @@ bool OledDisplay::begin(void) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
setBrightness(config.getDisplayBrightness());
|
/** Show low brightness on startup. then it's completely turn off on main
|
||||||
|
* application */
|
||||||
|
int brightness = config.getDisplayBrightness();
|
||||||
|
if(brightness == 0) {
|
||||||
|
setBrightness(1);
|
||||||
|
}
|
||||||
|
|
||||||
isBegin = true;
|
isBegin = true;
|
||||||
logInfo("begin");
|
logInfo("begin");
|
||||||
@ -148,6 +153,10 @@ void OledDisplay::setText(String &line1, String &line2, String &line3) {
|
|||||||
*/
|
*/
|
||||||
void OledDisplay::setText(const char *line1, const char *line2,
|
void OledDisplay::setText(const char *line1, const char *line2,
|
||||||
const char *line3) {
|
const char *line3) {
|
||||||
|
if (isDisplayOff) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DISP()->firstPage();
|
DISP()->firstPage();
|
||||||
do {
|
do {
|
||||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||||
@ -180,6 +189,10 @@ void OledDisplay::setText(String &line1, String &line2, String &line3,
|
|||||||
*/
|
*/
|
||||||
void OledDisplay::setText(const char *line1, const char *line2,
|
void OledDisplay::setText(const char *line1, const char *line2,
|
||||||
const char *line3, const char *line4) {
|
const char *line3, const char *line4) {
|
||||||
|
if (isDisplayOff) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DISP()->firstPage();
|
DISP()->firstPage();
|
||||||
do {
|
do {
|
||||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||||
@ -201,6 +214,10 @@ void OledDisplay::showDashboard(void) { showDashboard(NULL); }
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void OledDisplay::showDashboard(const char *status) {
|
void OledDisplay::showDashboard(const char *status) {
|
||||||
|
if (isDisplayOff) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
char strBuf[10];
|
char strBuf[10];
|
||||||
|
|
||||||
DISP()->firstPage();
|
DISP()->firstPage();
|
||||||
@ -299,10 +316,25 @@ void OledDisplay::showDashboard(const char *status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OledDisplay::setBrightness(int percent) {
|
void OledDisplay::setBrightness(int percent) {
|
||||||
DISP()->setContrast((127 * percent) / 100);
|
if (percent == 0) {
|
||||||
|
isDisplayOff = true;
|
||||||
|
|
||||||
|
// Clear display.
|
||||||
|
DISP()->firstPage();
|
||||||
|
do {
|
||||||
|
} while (DISP()->nextPage());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
isDisplayOff = false;
|
||||||
|
DISP()->setContrast((127 * percent) / 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OledDisplay::showNewFirmwareVersion(String version) {
|
void OledDisplay::showNewFirmwareVersion(String version) {
|
||||||
|
if (isDisplayOff) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DISP()->firstPage();
|
DISP()->firstPage();
|
||||||
do {
|
do {
|
||||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||||
@ -313,6 +345,10 @@ void OledDisplay::showNewFirmwareVersion(String version) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OledDisplay::showNewFirmwareUpdating(String percent) {
|
void OledDisplay::showNewFirmwareUpdating(String percent) {
|
||||||
|
if (isDisplayOff) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DISP()->firstPage();
|
DISP()->firstPage();
|
||||||
do {
|
do {
|
||||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||||
@ -322,6 +358,10 @@ void OledDisplay::showNewFirmwareUpdating(String percent) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OledDisplay::showNewFirmwareSuccess(String count) {
|
void OledDisplay::showNewFirmwareSuccess(String count) {
|
||||||
|
if (isDisplayOff) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DISP()->firstPage();
|
DISP()->firstPage();
|
||||||
do {
|
do {
|
||||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||||
@ -332,6 +372,10 @@ void OledDisplay::showNewFirmwareSuccess(String count) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OledDisplay::showNewFirmwareFailed(void) {
|
void OledDisplay::showNewFirmwareFailed(void) {
|
||||||
|
if (isDisplayOff) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DISP()->firstPage();
|
DISP()->firstPage();
|
||||||
do {
|
do {
|
||||||
DISP()->setFont(u8g2_font_t0_16_tf);
|
DISP()->setFont(u8g2_font_t0_16_tf);
|
||||||
|
@ -14,6 +14,7 @@ private:
|
|||||||
bool isBegin = false;
|
bool isBegin = false;
|
||||||
void *u8g2 = NULL;
|
void *u8g2 = NULL;
|
||||||
Measurements &value;
|
Measurements &value;
|
||||||
|
bool isDisplayOff = false;
|
||||||
|
|
||||||
void showTempHum(bool hasStatus);
|
void showTempHum(bool hasStatus);
|
||||||
void setCentralText(int y, String text);
|
void setCentralText(int y, String text);
|
||||||
|
Reference in New Issue
Block a user