Merge pull request #52 from airgradienthq/feature/led-test-with-button-on-power-up

Feature/led test with button on power up
This commit is contained in:
Phat Nguyen
2024-02-15 19:58:40 +07:00
committed by GitHub
6 changed files with 71 additions and 23 deletions

View File

@ -51,7 +51,7 @@ CC BY-SA 4.0 Attribution-ShareAlike 4.0 International License
#define SENSOR_CO2_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_PM_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_TEMP_HUM_UPDATE_INTERVAL 5000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 3000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 6000 /** ms */
#define WIFI_HOTSPOT_PASSWORD_DEFAULT \
"cleanair" /** default WiFi AP password \
*/
@ -160,9 +160,9 @@ public:
}
}
/** Get "pmsStandard" */
if (JSON.typeof_(root["pmsStandard"]) == "string") {
String standard = root["pmsStandard"];
/** Get "pmStandard" */
if (JSON.typeof_(root["pmStandard"]) == "string") {
String standard = root["pmStandard"];
if (standard == "ugm3") {
inUSAQI = false;
} else {

View File

@ -94,7 +94,7 @@ enum {
#define SENSOR_CO2_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_PM_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_TEMP_HUM_UPDATE_INTERVAL 5000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 3000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 6000 /** ms */
#define WIFI_HOTSPOT_PASSWORD_DEFAULT \
"cleanair" /** default WiFi AP password \
*/
@ -194,7 +194,9 @@ public:
/** Get "country" */
if (JSON.typeof_(root["country"]) == "string") {
String country = root["country"];
String _country = root["country"];
country = _country;
if (country == "US") {
inF = true;
} else {
@ -202,9 +204,9 @@ public:
}
}
/** Get "pmsStandard" */
if (JSON.typeof_(root["pmsStandard"]) == "string") {
String standard = root["pmsStandard"];
/** Get "pmStandard" */
if (JSON.typeof_(root["pmStandard"]) == "string") {
String standard = root["pmStandard"];
if (standard == "ugm3") {
inUSAQI = false;
} else {
@ -406,6 +408,13 @@ public:
*/
UseLedBar getLedBarMode(void) { return ledBarMode; }
/**
* @brief Get the Country
*
* @return String
*/
String getCountry(void) { return country; }
private:
bool inF; /** Temperature unit, true: F, false: C */
bool inUSAQI; /** PMS unit, true: USAQI, false: ugm3 */
@ -417,6 +426,7 @@ private:
UseLedBar ledBarMode = UseLedBarCO2; /** */
char models[20]; /** */
char mqttBroker[256]; /** */
String country; /***/
};
AgServer agServer;
@ -597,6 +607,19 @@ static void ledTest() {
ag.ledBar.show();
delay(1000);
}
static void ledTest2Min(void) {
uint32_t tstart = millis();
Serial.println("Start run LED test for 2 min");
while (1) {
ledTest();
uint32_t ms = (uint32_t)(millis() - tstart);
if (ms >= (60 * 1000 * 2)) {
Serial.println("LED test after 2 min finish");
break;
}
}
}
static void co2Poll(void) {
co2Ppm = ag.s8.getCo2();
@ -814,6 +837,8 @@ static void connectToWifi() {
dispSmState = APP_SM_WIFI_MANAGER_STA_CONNECTING;
ledSmState = APP_SM_WIFI_MANAGER_STA_CONNECTING;
});
displayShowText("Connecting to", "config WiFi", "...");
wifiManager.autoConnect(wifiSSID.c_str(), WIFI_HOTSPOT_PASSWORD_DEFAULT);
xTaskCreate(
[](void *obj) {
@ -986,6 +1011,25 @@ static void boardInit(void) {
if (ag.pms5003.begin(Serial0) == false) {
failedHandler("Init PMS5003 failed");
}
/** Run LED test on start up */
displayShowText("Press now for", "LED test", "");
bool test = false;
uint32_t stime = millis();
while (1) {
if (ag.button.getState() == ag.button.BUTTON_PRESSED) {
test = true;
break;
}
delay(1);
uint32_t ms = (uint32_t)(millis() - stime);
if (ms >= 3000) {
break;
}
}
if (test) {
ledTest();
}
}
/**
@ -1014,10 +1058,14 @@ static void serverConfigPoll(void) {
}
}
if (agServer.isLedBarTestRequested()) {
if (agServer.getCountry() == "TH") {
ledTest2Min();
} else {
ledTest();
}
}
}
}
/**
* @brief Calibration CO2 sensor, it's base calibration, after calib complete

View File

@ -89,7 +89,7 @@ enum {
#define SENSOR_CO2_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_PM_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_TEMP_HUM_UPDATE_INTERVAL 5000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 3000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 6000 /** ms */
#define WIFI_HOTSPOT_PASSWORD_DEFAULT \
"cleanair" /** default WiFi AP password \
*/
@ -197,9 +197,9 @@ public:
}
}
/** Get "pmsStandard" */
if (JSON.typeof_(root["pmsStandard"]) == "string") {
String standard = root["pmsStandard"];
/** Get "pmStandard" */
if (JSON.typeof_(root["pmStandard"]) == "string") {
String standard = root["pmStandard"];
if (standard == "ugm3") {
inUSAQI = false;
} else {

View File

@ -89,7 +89,7 @@ enum {
#define SENSOR_CO2_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_PM_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_TEMP_HUM_UPDATE_INTERVAL 5000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 3000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 6000 /** ms */
#define WIFI_HOTSPOT_PASSWORD_DEFAULT \
"cleanair" /** default WiFi AP password \
*/
@ -197,9 +197,9 @@ public:
}
}
/** Get "pmsStandard" */
if (JSON.typeof_(root["pmsStandard"]) == "string") {
String standard = root["pmsStandard"];
/** Get "pmStandard" */
if (JSON.typeof_(root["pmStandard"]) == "string") {
String standard = root["pmStandard"];
if (standard == "ugm3") {
inUSAQI = false;
} else {

View File

@ -93,7 +93,7 @@ enum {
#define SENSOR_CO2_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_PM_UPDATE_INTERVAL 5000 /** ms */
#define SENSOR_TEMP_HUM_UPDATE_INTERVAL 5000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 3000 /** ms */
#define DISPLAY_DELAY_SHOW_CONTENT_MS 6000 /** ms */
#define WIFI_HOTSPOT_PASSWORD_DEFAULT \
"cleanair" /** default WiFi AP password \
*/
@ -201,9 +201,9 @@ public:
}
}
/** Get "pmsStandard" */
if (JSON.typeof_(root["pmsStandard"]) == "string") {
String standard = root["pmsStandard"];
/** Get "pmStandard" */
if (JSON.typeof_(root["pmStandard"]) == "string") {
String standard = root["pmStandard"];
if (standard == "ugm3") {
inUSAQI = false;
} else {

View File

@ -1,6 +1,6 @@
#include "AirGradient.h"
#define AG_LIB_VER "3.0.0"
#define AG_LIB_VER "3.0.1"
AirGradient::AirGradient(BoardType type)
: pms5003(type), pms5003t_1(type), pms5003t_2(type), s8(type), sht4x(type),