mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-15 00:46:31 +02:00
Merge branch 'develop' into hotfix/configuration-default-after-ota-success-and-new-firmware-has-change-configuration-param
This commit is contained in:
@ -90,7 +90,6 @@ static LocalServer localServer(Serial, openMetrics, measurements, configuration,
|
||||
static int pmFailCount = 0;
|
||||
static uint32_t factoryBtnPressTime = 0;
|
||||
static int getCO2FailCount = 0;
|
||||
static bool offlineMode = false;
|
||||
static AgFirmwareMode fwMode = FW_MODE_I_9PSL;
|
||||
|
||||
static bool ledBarButtonTest = false;
|
||||
@ -175,8 +174,30 @@ void setup() {
|
||||
}
|
||||
} else {
|
||||
ledBarEnabledUpdate();
|
||||
connectToWifi = true;
|
||||
}
|
||||
|
||||
/** Show message confirm offline mode. */
|
||||
oledDisplay.setText(
|
||||
"Press now for",
|
||||
configuration.isOfflineMode() ? "online mode" : "offline mode", "");
|
||||
uint32_t startTime = millis();
|
||||
while (true) {
|
||||
if (ag->button.getState() == ag->button.BUTTON_PRESSED) {
|
||||
configuration.setOfflineMode(!configuration.isOfflineMode());
|
||||
|
||||
oledDisplay.setText(
|
||||
"Offline Mode",
|
||||
configuration.isOfflineMode() ? " = True" : " = False", "");
|
||||
delay(1000);
|
||||
break;
|
||||
}
|
||||
uint32_t periodMs = (uint32_t)(millis() - startTime);
|
||||
if (periodMs >= 3000) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
connectToWifi = !configuration.isOfflineMode();
|
||||
|
||||
} else {
|
||||
connectToWifi = true;
|
||||
}
|
||||
@ -210,8 +231,6 @@ void setup() {
|
||||
} else {
|
||||
ledBarEnabledUpdate();
|
||||
}
|
||||
} else {
|
||||
offlineMode = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -259,9 +278,9 @@ void loop() {
|
||||
}
|
||||
}
|
||||
|
||||
/** Auto reset external watchdog timer on offline mode and
|
||||
* postDataToAirGradient disabled. */
|
||||
if (offlineMode || (configuration.isPostDataToAirGradient() == false)) {
|
||||
/** Auto reset watchdog timer if offline mode or postDataToAirGradient */
|
||||
if (configuration.isOfflineMode() ||
|
||||
(configuration.isPostDataToAirGradient() == false)) {
|
||||
watchdogFeedSchedule.run();
|
||||
}
|
||||
|
||||
@ -612,7 +631,7 @@ static void oneIndoorInit(void) {
|
||||
}
|
||||
|
||||
/** Run LED test on start up */
|
||||
oledDisplay.setText("Press now for", "LED test &", "offline mode");
|
||||
oledDisplay.setText("Press now for", "LED test", "");
|
||||
ledBarButtonTest = false;
|
||||
uint32_t stime = millis();
|
||||
while (true) {
|
||||
|
@ -42,6 +42,7 @@ JSON_PROP_DEF(displayBrightness);
|
||||
JSON_PROP_DEF(co2CalibrationRequested);
|
||||
JSON_PROP_DEF(ledBarTestRequested);
|
||||
JSON_PROP_DEF(lastOta);
|
||||
JSON_PROP_DEF(offlineMode);
|
||||
|
||||
#define jprop_model_default ""
|
||||
#define jprop_country_default ""
|
||||
@ -58,6 +59,7 @@ JSON_PROP_DEF(lastOta);
|
||||
#define jprop_ledbarBrightness_default 100
|
||||
#define jprop_displayBrightness_default 100
|
||||
#define jprop_lastOta_default 0
|
||||
#define jprop_offlineMode_default false
|
||||
|
||||
JSONVar jconfig;
|
||||
|
||||
@ -163,6 +165,8 @@ void Configuration::defaultConfig(void) {
|
||||
jconfig[jprop_noxLearningOffset] = jprop_noxLearningOffset_default;
|
||||
jconfig[jprop_abcDays] = jprop_abcDays_default;
|
||||
jconfig[jprop_model] = jprop_model_default;
|
||||
jconfig[lastOta] = jprop_lastOta_default;
|
||||
jconfig[jprop_offlineMode] = jprop_offlineMode_default;
|
||||
|
||||
saveConfig();
|
||||
}
|
||||
@ -1105,6 +1109,15 @@ void Configuration::toConfig(const char *buf) {
|
||||
logInfo("toConfig: displayBrightness changed");
|
||||
}
|
||||
|
||||
if (JSON.typeof_(jconfig[jprop_offlineMode]) != "boolean") {
|
||||
isInvalid = true;
|
||||
} else {
|
||||
isInvalid = false;
|
||||
}
|
||||
if (isInvalid) {
|
||||
jconfig[jprop_offlineMode] = false;
|
||||
}
|
||||
|
||||
/** Last OTA */
|
||||
if(JSON.typeof_(jconfig[jprop_lastOta]) != "number") {
|
||||
isInvalid = true;
|
||||
@ -1178,6 +1191,17 @@ int Configuration::getDisplayBrightness(void) {
|
||||
return value;
|
||||
}
|
||||
|
||||
bool Configuration::isOfflineMode(void) {
|
||||
bool offline = jconfig[jprop_offlineMode];
|
||||
return offline;
|
||||
}
|
||||
|
||||
void Configuration::setOfflineMode(bool offline) {
|
||||
logInfo("Set offline mode: " + String(offline ? "True" : "False"));
|
||||
jconfig[jprop_offlineMode] = offline;
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
bool Configuration::isDisplayBrightnessChanged(void) {
|
||||
bool changed = displayBrightnessChanged;
|
||||
displayBrightnessChanged = false;
|
||||
|
@ -78,6 +78,8 @@ public:
|
||||
int getLastOta(void);
|
||||
void updateLastOta(void);
|
||||
String newFirmwareVersion(void);
|
||||
bool isOfflineMode(void);
|
||||
void setOfflineMode(bool offline);
|
||||
};
|
||||
|
||||
#endif /** _AG_CONFIG_H_ */
|
||||
|
@ -63,10 +63,10 @@ void StateMachine::sensorhandleLeds(void) {
|
||||
*/
|
||||
void StateMachine::co2handleLeds(void) {
|
||||
int co2Value = value.CO2;
|
||||
if (co2Value <= 400) {
|
||||
if (co2Value <= 600) {
|
||||
/** G; 1 */
|
||||
ag->ledBar.setColor(0, 255, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
} else if (co2Value <= 700) {
|
||||
} else if (co2Value <= 800) {
|
||||
/** GG; 2 */
|
||||
ag->ledBar.setColor(0, 255, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(0, 255, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
@ -75,20 +75,20 @@ void StateMachine::co2handleLeds(void) {
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||
} else if (co2Value <= 1333) {
|
||||
/** YYYY; 4 */
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 4);
|
||||
} else if (co2Value <= 1666) {
|
||||
/** YYYYY; 5 */
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 4);
|
||||
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 5);
|
||||
} else if (co2Value <= 2000) {
|
||||
} else if (co2Value <= 1250) {
|
||||
/** OOOO; 4 */
|
||||
ag->ledBar.setColor(255, 165, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(255, 165, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
ag->ledBar.setColor(255, 165, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||
ag->ledBar.setColor(255, 165, 0, ag->ledBar.getNumberOfLeds() - 4);
|
||||
} else if (co2Value <= 1500) {
|
||||
/** OOOOO; 5 */
|
||||
ag->ledBar.setColor(255, 165, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(255, 165, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
ag->ledBar.setColor(255, 165, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||
ag->ledBar.setColor(255, 165, 0, ag->ledBar.getNumberOfLeds() - 4);
|
||||
ag->ledBar.setColor(255, 165, 0, ag->ledBar.getNumberOfLeds() - 5);
|
||||
} else if (co2Value <= 1750) {
|
||||
/** RRRRRR; 6 */
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
@ -96,7 +96,7 @@ void StateMachine::co2handleLeds(void) {
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 4);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 5);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 6);
|
||||
} else if (co2Value <= 2666) {
|
||||
} else if (co2Value <= 2000) {
|
||||
/** RRRRRRR; 7 */
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
@ -105,28 +105,17 @@ void StateMachine::co2handleLeds(void) {
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 5);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 6);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 7);
|
||||
} else if (co2Value <= 3333) {
|
||||
/** RRRRRRRR; 8 */
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 4);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 5);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 6);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 7);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 8);
|
||||
} else if (co2Value <= 4000) {
|
||||
/** RRRRRRRRR; 9 */
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 4);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 5);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 6);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 7);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 8);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 9);
|
||||
} else { /** > 4000 */
|
||||
} else if (co2Value <= 3000) {
|
||||
/** PPPPPPPP; 8 */
|
||||
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 4);
|
||||
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 5);
|
||||
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 6);
|
||||
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 7);
|
||||
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 8);
|
||||
} else { /** > 3000 */
|
||||
/* PRPRPRPRP; 9 */
|
||||
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||
|
Reference in New Issue
Block a user