mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-04 19:56:31 +02:00
[temporary commit]
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,4 @@
|
|||||||
#include "AgOledDisplay.h"
|
#include "AgOledDisplay.h"
|
||||||
// #include "Libraries/U8g2/src/U8g2lib.h"
|
|
||||||
#include <U8g2lib.h>
|
#include <U8g2lib.h>
|
||||||
|
|
||||||
#define DISP() ((U8G2_SH1106_128X64_NONAME_F_HW_I2C *)(this->u8g2))
|
#define DISP() ((U8G2_SH1106_128X64_NONAME_F_HW_I2C *)(this->u8g2))
|
||||||
@ -36,9 +35,13 @@ void AgOledDisplay::showTempHum(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AgOledDisplay::AgOledDisplay(AirGradient &ag, AgConfigure &config,
|
AgOledDisplay::AgOledDisplay(AgConfigure &config,
|
||||||
AgValue &value, Stream &log)
|
AgValue &value, Stream &log)
|
||||||
: PrintLog(log, "AgOledDisplay"), ag(ag), config(config), value(value) {}
|
: PrintLog(log, "AgOledDisplay"), config(config), value(value) {}
|
||||||
|
|
||||||
|
void AgOledDisplay::setAirGradient(AirGradient *ag) {
|
||||||
|
this->ag = ag;
|
||||||
|
}
|
||||||
|
|
||||||
AgOledDisplay::~AgOledDisplay() {}
|
AgOledDisplay::~AgOledDisplay() {}
|
||||||
|
|
||||||
@ -185,7 +188,7 @@ void AgOledDisplay::showDashboard(const char *status) {
|
|||||||
DISP()->setFont(u8g2_font_t0_22b_tf);
|
DISP()->setFont(u8g2_font_t0_22b_tf);
|
||||||
if (config.isPmStandardInUSAQI()) {
|
if (config.isPmStandardInUSAQI()) {
|
||||||
if (value.PM25 >= 0) {
|
if (value.PM25 >= 0) {
|
||||||
sprintf(strBuf, "%d", ag.pms5003.convertPm25ToUsAqi(value.PM25));
|
sprintf(strBuf, "%d", ag->pms5003.convertPm25ToUsAqi(value.PM25));
|
||||||
} else {
|
} else {
|
||||||
sprintf(strBuf, "%s", "-");
|
sprintf(strBuf, "%s", "-");
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
class AgOledDisplay : public PrintLog {
|
class AgOledDisplay : public PrintLog {
|
||||||
private:
|
private:
|
||||||
AgConfigure &config;
|
AgConfigure &config;
|
||||||
AirGradient &ag;
|
AirGradient *ag;
|
||||||
bool isBegin = false;
|
bool isBegin = false;
|
||||||
void *u8g2 = NULL;
|
void *u8g2 = NULL;
|
||||||
AgValue &value;
|
AgValue &value;
|
||||||
@ -18,11 +18,12 @@ private:
|
|||||||
void showTempHum(void);
|
void showTempHum(void);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AgOledDisplay(AirGradient &ag, AgConfigure &config, AgValue &value,
|
AgOledDisplay(AgConfigure &config, AgValue &value,
|
||||||
Stream &log);
|
Stream &log);
|
||||||
~AgOledDisplay();
|
~AgOledDisplay();
|
||||||
|
|
||||||
bool begin(void);
|
void setAirGradient(AirGradient *ag);
|
||||||
|
bool begin(void);
|
||||||
void end(void);
|
void end(void);
|
||||||
void setStatus(String &status);
|
void setStatus(String &status);
|
||||||
void setStatus(const char *status);
|
void setStatus(const char *status);
|
||||||
|
@ -8,20 +8,20 @@
|
|||||||
void AgStateMachine::ledBarSingleLedAnimation(uint8_t r, uint8_t g, uint8_t b) {
|
void AgStateMachine::ledBarSingleLedAnimation(uint8_t r, uint8_t g, uint8_t b) {
|
||||||
if (ledBarAnimationCount < 0) {
|
if (ledBarAnimationCount < 0) {
|
||||||
ledBarAnimationCount = 0;
|
ledBarAnimationCount = 0;
|
||||||
ag.ledBar.setColor(r, g, b, ledBarAnimationCount);
|
ag->ledBar.setColor(r, g, b, ledBarAnimationCount);
|
||||||
} else {
|
} else {
|
||||||
ledBarAnimationCount++;
|
ledBarAnimationCount++;
|
||||||
if (ledBarAnimationCount >= ag.ledBar.getNumberOfLeds()) {
|
if (ledBarAnimationCount >= ag->ledBar.getNumberOfLeds()) {
|
||||||
ledBarAnimationCount = 0;
|
ledBarAnimationCount = 0;
|
||||||
}
|
}
|
||||||
ag.ledBar.setColor(r, g, b, ledBarAnimationCount);
|
ag->ledBar.setColor(r, g, b, ledBarAnimationCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgStateMachine::ledStatusBlinkDelay(uint32_t ms) {
|
void AgStateMachine::ledStatusBlinkDelay(uint32_t ms) {
|
||||||
ag.statusLed.setOn();
|
ag->statusLed.setOn();
|
||||||
delay(ms);
|
delay(ms);
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
delay(ms);
|
delay(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,91 +34,87 @@ void AgStateMachine::sensorLedHandle(void) {
|
|||||||
pm25LedHandle();
|
pm25LedHandle();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ag.ledBar.clear();
|
ag->ledBar.clear();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (config.getLedBarMode() == LedBarMode::LedBarModeCO2) {
|
|
||||||
// co2LedHandle();
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgStateMachine::co2LedHandle(void) {
|
void AgStateMachine::co2LedHandle(void) {
|
||||||
int co2Value = value.CO2;
|
int co2Value = value.CO2;
|
||||||
if (co2Value <= 400) {
|
if (co2Value <= 400) {
|
||||||
/** G; 1 */
|
/** G; 1 */
|
||||||
ag.ledBar.setColor(0, 255, 0, ag.ledBar.getNumberOfLeds() - 1);
|
ag->ledBar.setColor(0, 255, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||||
} else if (co2Value <= 700) {
|
} else if (co2Value <= 700) {
|
||||||
/** GG; 2 */
|
/** GG; 2 */
|
||||||
ag.ledBar.setColor(0, 255, 0, ag.ledBar.getNumberOfLeds() - 1);
|
ag->ledBar.setColor(0, 255, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||||
ag.ledBar.setColor(0, 255, 0, ag.ledBar.getNumberOfLeds() - 2);
|
ag->ledBar.setColor(0, 255, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||||
} else if (co2Value <= 1000) {
|
} else if (co2Value <= 1000) {
|
||||||
/** YYY; 3 */
|
/** YYY; 3 */
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 3);
|
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||||
} else if (co2Value <= 1333) {
|
} else if (co2Value <= 1333) {
|
||||||
/** YYYY; 4 */
|
/** YYYY; 4 */
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
} else if (co2Value <= 1666) {
|
} else if (co2Value <= 1666) {
|
||||||
/** YYYYY; 5 */
|
/** YYYYY; 5 */
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 5);
|
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 5);
|
||||||
} else if (co2Value <= 2000) {
|
} else if (co2Value <= 2000) {
|
||||||
/** RRRRRR; 6 */
|
/** RRRRRR; 6 */
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 5);
|
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() - 6);
|
||||||
} else if (co2Value <= 2666) {
|
} else if (co2Value <= 2666) {
|
||||||
/** RRRRRRR; 7 */
|
/** RRRRRRR; 7 */
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 5);
|
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() - 6);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 7);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 7);
|
||||||
} else if (co2Value <= 3333) {
|
} else if (co2Value <= 3333) {
|
||||||
/** RRRRRRRR; 8 */
|
/** RRRRRRRR; 8 */
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 5);
|
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() - 6);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 7);
|
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() - 8);
|
||||||
} else if (co2Value <= 4000) {
|
} else if (co2Value <= 4000) {
|
||||||
/** RRRRRRRRR; 9 */
|
/** RRRRRRRRR; 9 */
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 5);
|
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() - 6);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 7);
|
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() - 8);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 9);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 9);
|
||||||
} else { /** > 4000 */
|
} else { /** > 4000 */
|
||||||
/* PRPRPRPRP; 9 */
|
/* PRPRPRPRP; 9 */
|
||||||
ag.ledBar.setColor(153, 153, 0, ag.ledBar.getNumberOfLeds() - 1);
|
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 2);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||||
ag.ledBar.setColor(153, 153, 0, ag.ledBar.getNumberOfLeds() - 3);
|
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 4);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 4);
|
||||||
ag.ledBar.setColor(153, 153, 0, ag.ledBar.getNumberOfLeds() - 5);
|
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 5);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 6);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 6);
|
||||||
ag.ledBar.setColor(153, 153, 0, ag.ledBar.getNumberOfLeds() - 7);
|
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 7);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 8);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 8);
|
||||||
ag.ledBar.setColor(153, 153, 0, ag.ledBar.getNumberOfLeds() - 9);
|
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,89 +122,94 @@ void AgStateMachine::pm25LedHandle(void) {
|
|||||||
int pm25Value = value.PM25;
|
int pm25Value = value.PM25;
|
||||||
if (pm25Value <= 5) {
|
if (pm25Value <= 5) {
|
||||||
/** G; 1 */
|
/** G; 1 */
|
||||||
ag.ledBar.setColor(0, 255, 0, ag.ledBar.getNumberOfLeds() - 1);
|
ag->ledBar.setColor(0, 255, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||||
} else if (pm25Value <= 10) {
|
} else if (pm25Value <= 10) {
|
||||||
/** GG; 2 */
|
/** GG; 2 */
|
||||||
ag.ledBar.setColor(0, 255, 0, ag.ledBar.getNumberOfLeds() - 1);
|
ag->ledBar.setColor(0, 255, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||||
ag.ledBar.setColor(0, 255, 0, ag.ledBar.getNumberOfLeds() - 2);
|
ag->ledBar.setColor(0, 255, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||||
} else if (pm25Value <= 20) {
|
} else if (pm25Value <= 20) {
|
||||||
/** YYY; 3 */
|
/** YYY; 3 */
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 3);
|
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||||
} else if (pm25Value <= 35) {
|
} else if (pm25Value <= 35) {
|
||||||
/** YYYY; 4 */
|
/** YYYY; 4 */
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
} else if (pm25Value <= 45) {
|
} else if (pm25Value <= 45) {
|
||||||
/** YYYYY; 5 */
|
/** YYYYY; 5 */
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
ag.ledBar.setColor(255, 255, 0, ag.ledBar.getNumberOfLeds() - 5);
|
ag->ledBar.setColor(255, 255, 0, ag->ledBar.getNumberOfLeds() - 5);
|
||||||
} else if (pm25Value <= 55) {
|
} else if (pm25Value <= 55) {
|
||||||
/** RRRRRR; 6 */
|
/** RRRRRR; 6 */
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 5);
|
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() - 6);
|
||||||
} else if (pm25Value <= 65) {
|
} else if (pm25Value <= 65) {
|
||||||
/** RRRRRRR; 7 */
|
/** RRRRRRR; 7 */
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 5);
|
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() - 6);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 7);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 7);
|
||||||
} else if (pm25Value <= 150) {
|
} else if (pm25Value <= 150) {
|
||||||
/** RRRRRRRR; 8 */
|
/** RRRRRRRR; 8 */
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 5);
|
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() - 6);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 7);
|
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() - 8);
|
||||||
} else if (pm25Value <= 250) {
|
} else if (pm25Value <= 250) {
|
||||||
/** RRRRRRRRR; 9 */
|
/** RRRRRRRRR; 9 */
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 1);
|
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() - 2);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 3);
|
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() - 4);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 5);
|
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() - 6);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 7);
|
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() - 8);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 9);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 9);
|
||||||
} else { /** > 250 */
|
} else { /** > 250 */
|
||||||
/* PRPRPRPRP; 9 */
|
/* PRPRPRPRP; 9 */
|
||||||
ag.ledBar.setColor(153, 153, 0, ag.ledBar.getNumberOfLeds() - 1);
|
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 1);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 2);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 2);
|
||||||
ag.ledBar.setColor(153, 153, 0, ag.ledBar.getNumberOfLeds() - 3);
|
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 3);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 4);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 4);
|
||||||
ag.ledBar.setColor(153, 153, 0, ag.ledBar.getNumberOfLeds() - 5);
|
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 5);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 6);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 6);
|
||||||
ag.ledBar.setColor(153, 153, 0, ag.ledBar.getNumberOfLeds() - 7);
|
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 7);
|
||||||
ag.ledBar.setColor(255, 0, 0, ag.ledBar.getNumberOfLeds() - 8);
|
ag->ledBar.setColor(255, 0, 0, ag->ledBar.getNumberOfLeds() - 8);
|
||||||
ag.ledBar.setColor(153, 153, 0, ag.ledBar.getNumberOfLeds() - 9);
|
ag->ledBar.setColor(153, 153, 0, ag->ledBar.getNumberOfLeds() - 9);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AgStateMachine::AgStateMachine(AirGradient &ag, AgOledDisplay &disp,
|
AgStateMachine::AgStateMachine(AgOledDisplay &disp, Stream &log, AgValue &value,
|
||||||
Stream &log, AgValue &value, AgConfigure &config)
|
AgConfigure &config)
|
||||||
: PrintLog(log, "AgStateMachine"), ag(ag), disp(disp), value(value),
|
: PrintLog(log, "AgStateMachine"), disp(disp), value(value),
|
||||||
config(config) {}
|
config(config) {}
|
||||||
|
|
||||||
AgStateMachine::~AgStateMachine() {}
|
AgStateMachine::~AgStateMachine() {}
|
||||||
|
|
||||||
void AgStateMachine::displayHandle(AgStateMachineState state) {
|
void AgStateMachine::displayHandle(AgStateMachineState state) {
|
||||||
|
// Ignore handle if not ONE_INDOOR board
|
||||||
|
if (!ag->isOneIndoor()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (state > AgStateMachineNormal) {
|
if (state > AgStateMachineNormal) {
|
||||||
logError("displayHandle: State invalid");
|
logError("displayHandle: State invalid");
|
||||||
return;
|
return;
|
||||||
@ -223,7 +224,7 @@ void AgStateMachine::displayHandle(AgStateMachineState state) {
|
|||||||
String line1 = String(wifiConnectCountDown) + "s to connect";
|
String line1 = String(wifiConnectCountDown) + "s to connect";
|
||||||
String line2 = "to WiFi hotspot:";
|
String line2 = "to WiFi hotspot:";
|
||||||
String line3 = "\"airgradient-";
|
String line3 = "\"airgradient-";
|
||||||
String line4 = ag.deviceId() + "\"";
|
String line4 = ag->deviceId() + "\"";
|
||||||
disp.setText(line1, line2, line3, line4);
|
disp.setText(line1, line2, line3, line4);
|
||||||
// displayShowWifiText(String(wifiConnectCountDown) + "s to connect",
|
// displayShowWifiText(String(wifiConnectCountDown) + "s to connect",
|
||||||
// "to WiFi hotspot:", "\"airgradient-",
|
// "to WiFi hotspot:", "\"airgradient-",
|
||||||
@ -285,7 +286,7 @@ void AgStateMachine::displayHandle(AgStateMachineState state) {
|
|||||||
disp.showDashboard("Add to Dashboard");
|
disp.showDashboard("Add to Dashboard");
|
||||||
} else {
|
} else {
|
||||||
// displayshowDashboard(getDevId());
|
// displayshowDashboard(getDevId());
|
||||||
disp.showDashboard(ag.deviceId().c_str());
|
disp.showDashboard(ag->deviceId().c_str());
|
||||||
}
|
}
|
||||||
addToDashBoard = !addToDashBoard;
|
addToDashBoard = !addToDashBoard;
|
||||||
}
|
}
|
||||||
@ -324,80 +325,80 @@ void AgStateMachine::ledHandle(AgStateMachineState state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ledState = state;
|
ledState = state;
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ag.ledBar.clear(); // Set all LED OFF
|
ag->ledBar.clear(); // Set all LED OFF
|
||||||
}
|
}
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case AgStateMachineWiFiManagerMode: {
|
case AgStateMachineWiFiManagerMode: {
|
||||||
/** In WiFi Manager Mode */
|
/** In WiFi Manager Mode */
|
||||||
/** Turn LED OFF */
|
/** Turn LED OFF */
|
||||||
/** Turn midle LED Color */
|
/** Turn midle LED Color */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ag.ledBar.setColor(0, 0, 255, ag.ledBar.getNumberOfLeds() / 2);
|
ag->ledBar.setColor(0, 0, 255, ag->ledBar.getNumberOfLeds() / 2);
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setToggle();
|
ag->statusLed.setToggle();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineWiFiManagerPortalActive: {
|
case AgStateMachineWiFiManagerPortalActive: {
|
||||||
/** WiFi Manager has connected to mobile phone */
|
/** WiFi Manager has connected to mobile phone */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ag.ledBar.setColor(0, 0, 255);
|
ag->ledBar.setColor(0, 0, 255);
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOn();
|
ag->statusLed.setOn();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineWiFiManagerStaConnecting: {
|
case AgStateMachineWiFiManagerStaConnecting: {
|
||||||
/** after SSID and PW entered and OK clicked, connection to WiFI network is
|
/** after SSID and PW entered and OK clicked, connection to WiFI network is
|
||||||
* attempted */
|
* attempted */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ledBarSingleLedAnimation(255, 255, 255);
|
ledBarSingleLedAnimation(255, 255, 255);
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineWiFiManagerStaConnected: {
|
case AgStateMachineWiFiManagerStaConnected: {
|
||||||
/** Connecting to WiFi worked */
|
/** Connecting to WiFi worked */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ag.ledBar.setColor(255, 255, 255);
|
ag->ledBar.setColor(255, 255, 255);
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineWiFiOkServerConnecting: {
|
case AgStateMachineWiFiOkServerConnecting: {
|
||||||
/** once connected to WiFi an attempt to reach the server is performed */
|
/** once connected to WiFi an attempt to reach the server is performed */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ledBarSingleLedAnimation(0, 255, 0);
|
ledBarSingleLedAnimation(0, 255, 0);
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineWiFiOkServerConnected: {
|
case AgStateMachineWiFiOkServerConnected: {
|
||||||
/** Server is reachable, all fine */
|
/** Server is reachable, all fine */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ag.ledBar.setColor(0, 255, 0);
|
ag->ledBar.setColor(0, 255, 0);
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
|
|
||||||
/** two time slow blink, then off */
|
/** two time slow blink, then off */
|
||||||
for (int i = 0; i < 2; i++) {
|
for (int i = 0; i < 2; i++) {
|
||||||
ledStatusBlinkDelay(LED_SLOW_BLINK_DELAY);
|
ledStatusBlinkDelay(LED_SLOW_BLINK_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineWiFiManagerConnectFailed: {
|
case AgStateMachineWiFiManagerConnectFailed: {
|
||||||
/** Cannot connect to WiFi (e.g. wrong password, WPA Enterprise etc.) */
|
/** Cannot connect to WiFi (e.g. wrong password, WPA Enterprise etc.) */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ag.ledBar.setColor(255, 0, 0);
|
ag->ledBar.setColor(255, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
|
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
@ -405,91 +406,89 @@ void AgStateMachine::ledHandle(AgStateMachineState state) {
|
|||||||
}
|
}
|
||||||
delay(2000);
|
delay(2000);
|
||||||
}
|
}
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineWiFiOkServerConnectFailed: {
|
case AgStateMachineWiFiOkServerConnectFailed: {
|
||||||
/** Connected to WiFi but server not reachable, e.g. firewall block/
|
/** Connected to WiFi but server not reachable, e.g. firewall block/
|
||||||
* whitelisting needed etc. */
|
* whitelisting needed etc. */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ag.ledBar.setColor(233, 183, 54); /** orange */
|
ag->ledBar.setColor(233, 183, 54); /** orange */
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
ledStatusBlinkDelay(LED_FAST_BLINK_DELAY);
|
ledStatusBlinkDelay(LED_FAST_BLINK_DELAY);
|
||||||
}
|
}
|
||||||
delay(2000);
|
delay(2000);
|
||||||
}
|
}
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineWiFiOkServerOkSensorConfigFailed: {
|
case AgStateMachineWiFiOkServerOkSensorConfigFailed: {
|
||||||
/** Server reachable but sensor not configured correctly */
|
/** Server reachable but sensor not configured correctly */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ag.ledBar.setColor(139, 24, 248); /** violet */
|
ag->ledBar.setColor(139, 24, 248); /** violet */
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
ledStatusBlinkDelay(LED_FAST_BLINK_DELAY);
|
ledStatusBlinkDelay(LED_FAST_BLINK_DELAY);
|
||||||
}
|
}
|
||||||
delay(2000);
|
delay(2000);
|
||||||
}
|
}
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineWiFiLost: {
|
case AgStateMachineWiFiLost: {
|
||||||
/** Connection to WiFi network failed credentials incorrect encryption not
|
/** Connection to WiFi network failed credentials incorrect encryption not
|
||||||
* supported etc. */
|
* supported etc. */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
/** WIFI failed status LED color */
|
/** WIFI failed status LED color */
|
||||||
ag.ledBar.setColor(255, 0, 0, 0);
|
ag->ledBar.setColor(255, 0, 0, 0);
|
||||||
/** Show CO2 or PM color status */
|
/** Show CO2 or PM color status */
|
||||||
// sensorLedColorHandler();
|
// sensorLedColorHandler();
|
||||||
sensorLedHandle();
|
sensorLedHandle();
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineServerLost: {
|
case AgStateMachineServerLost: {
|
||||||
/** Connected to WiFi network but the server cannot be reached through the
|
/** Connected to WiFi network but the server cannot be reached through the
|
||||||
* internet, e.g. blocked by firewall */
|
* internet, e.g. blocked by firewall */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ag.ledBar.setColor(233, 183, 54, 0);
|
ag->ledBar.setColor(233, 183, 54, 0);
|
||||||
|
|
||||||
/** Show CO2 or PM color status */
|
/** Show CO2 or PM color status */
|
||||||
sensorLedHandle();
|
sensorLedHandle();
|
||||||
// sensorLedColorHandler();
|
// sensorLedColorHandler();
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineSensorConfigFailed: {
|
case AgStateMachineSensorConfigFailed: {
|
||||||
/** Server is reachable but there is some configuration issue to be fixed on
|
/** Server is reachable but there is some configuration issue to be fixed on
|
||||||
* the server side */
|
* the server side */
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
ag.ledBar.setColor(139, 24, 248, 0);
|
ag->ledBar.setColor(139, 24, 248, 0);
|
||||||
|
|
||||||
/** Show CO2 or PM color status */
|
/** Show CO2 or PM color status */
|
||||||
// sensorLedColorHandler();
|
|
||||||
sensorLedHandle();
|
sensorLedHandle();
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case AgStateMachineNormal: {
|
case AgStateMachineNormal: {
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
// sensorLedColorHandler();
|
|
||||||
sensorLedHandle();
|
sensorLedHandle();
|
||||||
} else {
|
} else {
|
||||||
ag.statusLed.setOff();
|
ag->statusLed.setOff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -497,21 +496,18 @@ void AgStateMachine::ledHandle(AgStateMachineState state) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ag.isOneIndoor()) {
|
// Show LED bar color
|
||||||
ag.ledBar.show();
|
if (ag->isOneIndoor()) {
|
||||||
|
ag->ledBar.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgStateMachine::ledHandle(void) { ledHandle(ledState); }
|
void AgStateMachine::ledHandle(void) { ledHandle(ledState); }
|
||||||
|
|
||||||
// void AgStateMachine::setState(AgStateMachineState state) {
|
|
||||||
// this->state = state;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// AgStateMachineState AgStateMachine::getState(void) { return state; }
|
|
||||||
|
|
||||||
void AgStateMachine::setDisplayState(AgStateMachineState state) {
|
void AgStateMachine::setDisplayState(AgStateMachineState state) {
|
||||||
dispState = state;
|
dispState = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
AgStateMachineState AgStateMachine::getDisplayState(void) { return dispState; }
|
AgStateMachineState AgStateMachine::getDisplayState(void) { return dispState; }
|
||||||
|
|
||||||
|
void AgStateMachine::setAirGradient(AirGradient *ag) { this->ag = ag; }
|
||||||
|
@ -12,7 +12,7 @@ private:
|
|||||||
// AgStateMachineState state;
|
// AgStateMachineState state;
|
||||||
AgStateMachineState ledState;
|
AgStateMachineState ledState;
|
||||||
AgStateMachineState dispState;
|
AgStateMachineState dispState;
|
||||||
AirGradient &ag;
|
AirGradient *ag;
|
||||||
AgOledDisplay &disp;
|
AgOledDisplay &disp;
|
||||||
AgValue &value;
|
AgValue &value;
|
||||||
AgConfigure &config;
|
AgConfigure &config;
|
||||||
@ -29,9 +29,10 @@ private:
|
|||||||
void pm25LedHandle(void);
|
void pm25LedHandle(void);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AgStateMachine(AirGradient &ag, AgOledDisplay &disp, Stream &log,
|
AgStateMachine(AgOledDisplay &disp, Stream &log,
|
||||||
AgValue &value, AgConfigure& config);
|
AgValue &value, AgConfigure& config);
|
||||||
~AgStateMachine();
|
~AgStateMachine();
|
||||||
|
void setAirGradient(AirGradient* ag);
|
||||||
void displayHandle(AgStateMachineState state);
|
void displayHandle(AgStateMachineState state);
|
||||||
void displayHandle(void);
|
void displayHandle(void);
|
||||||
void displaySetAddToDashBoard(void);
|
void displaySetAddToDashBoard(void);
|
||||||
@ -41,7 +42,6 @@ public:
|
|||||||
void ledHandle(AgStateMachineState state);
|
void ledHandle(AgStateMachineState state);
|
||||||
void ledHandle(void);
|
void ledHandle(void);
|
||||||
void setDisplayState(AgStateMachineState state);
|
void setDisplayState(AgStateMachineState state);
|
||||||
// AgStateMachineState getState(void);
|
|
||||||
AgStateMachineState getDisplayState(void);
|
AgStateMachineState getDisplayState(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#include "AgWiFiConnector.h"
|
#include "AgWiFiConnector.h"
|
||||||
// #include "Libraries/WiFiManager/WiFiManager.h"
|
|
||||||
#include <WiFiManager.h>
|
#include <WiFiManager.h>
|
||||||
|
|
||||||
#define WIFI_CONNECT_COUNTDOWN_MAX 180
|
#define WIFI_CONNECT_COUNTDOWN_MAX 180
|
||||||
@ -7,16 +6,15 @@
|
|||||||
|
|
||||||
#define WIFI() ((WiFiManager *)(this->wifi))
|
#define WIFI() ((WiFiManager *)(this->wifi))
|
||||||
|
|
||||||
AgWiFiConnector::AgWiFiConnector(AirGradient &ag, AgOledDisplay &disp,
|
AgWiFiConnector::AgWiFiConnector(AgOledDisplay &disp, Stream &log,
|
||||||
String ssid, Stream &log, AgStateMachine &sm)
|
AgStateMachine &sm)
|
||||||
: PrintLog(log, "AgWiFiConnector"), ag(ag), disp(disp), ssid(ssid), sm(sm) {
|
: PrintLog(log, "AgWiFiConnector"), disp(disp), sm(sm) {}
|
||||||
}
|
|
||||||
|
|
||||||
AgWiFiConnector::~AgWiFiConnector() {}
|
AgWiFiConnector::~AgWiFiConnector() {}
|
||||||
|
|
||||||
void AgWiFiConnector::setHotspotSSID(String ssid) { this->ssid = ssid; }
|
void AgWiFiConnector::setAirGradient(AirGradient *ag) { this->ag = ag; }
|
||||||
|
|
||||||
bool AgWiFiConnector::connect(uint32_t timeout) {
|
bool AgWiFiConnector::connect(void) {
|
||||||
if (wifi == NULL) {
|
if (wifi == NULL) {
|
||||||
wifi = new WiFiManager();
|
wifi = new WiFiManager();
|
||||||
if (wifi == NULL) {
|
if (wifi == NULL) {
|
||||||
@ -26,19 +24,21 @@ bool AgWiFiConnector::connect(uint32_t timeout) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WIFI()->setConfigPortalBlocking(false);
|
WIFI()->setConfigPortalBlocking(false);
|
||||||
WIFI()->setTimeout(timeout);
|
WIFI()->setTimeout(WIFI_CONNECT_COUNTDOWN_MAX);
|
||||||
|
|
||||||
WIFI()->setAPCallback([this](WiFiManager *obj) { _wifiApCallback(); });
|
WIFI()->setAPCallback([this](WiFiManager *obj) { _wifiApCallback(); });
|
||||||
WIFI()->setSaveConfigCallback([this]() { _wifiSaveConfig(); });
|
WIFI()->setSaveConfigCallback([this]() { _wifiSaveConfig(); });
|
||||||
WIFI()->setSaveParamsCallback([this]() { _wifiSaveParamCallback(); });
|
WIFI()->setSaveParamsCallback([this]() { _wifiSaveParamCallback(); });
|
||||||
|
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
disp.setText("Connecting to", "WiFi", "...");
|
disp.setText("Connecting to", "WiFi", "...");
|
||||||
} else {
|
} else {
|
||||||
logInfo("Connecting to WiFi...");
|
logInfo("Connecting to WiFi...");
|
||||||
}
|
}
|
||||||
|
|
||||||
WIFI()->autoConnect(ssid.c_str(), WIFI_HOTSPOT_PASSWORD_DEFAULT);
|
WIFI()->autoConnect(ssid.c_str(), WIFI_HOTSPOT_PASSWORD_DEFAULT);
|
||||||
|
|
||||||
|
// Task handle WiFi connection.
|
||||||
xTaskCreate(
|
xTaskCreate(
|
||||||
[](void *obj) {
|
[](void *obj) {
|
||||||
AgWiFiConnector *connector = (AgWiFiConnector *)obj;
|
AgWiFiConnector *connector = (AgWiFiConnector *)obj;
|
||||||
@ -56,11 +56,12 @@ bool AgWiFiConnector::connect(uint32_t timeout) {
|
|||||||
|
|
||||||
AgStateMachineState stateOld = sm.getDisplayState();
|
AgStateMachineState stateOld = sm.getDisplayState();
|
||||||
while (WIFI()->getConfigPortalActive()) {
|
while (WIFI()->getConfigPortalActive()) {
|
||||||
/** LED and display animation */
|
/** LED animatoin and display update content */
|
||||||
if (WiFi.isConnected() == false) {
|
if (WiFi.isConnected() == false) {
|
||||||
/** Display countdown */
|
/** Display countdown */
|
||||||
uint32_t ms = (uint32_t)(millis() - dispPeriod);
|
uint32_t ms;
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
|
ms = (uint32_t)(millis() - dispPeriod);
|
||||||
if (ms >= 1000) {
|
if (ms >= 1000) {
|
||||||
dispPeriod = millis();
|
dispPeriod = millis();
|
||||||
sm.displayHandle();
|
sm.displayHandle();
|
||||||
@ -85,36 +86,31 @@ bool AgWiFiConnector::connect(uint32_t timeout) {
|
|||||||
clientConnectChanged = clientConnected;
|
clientConnectChanged = clientConnected;
|
||||||
if (clientConnectChanged) {
|
if (clientConnectChanged) {
|
||||||
sm.ledHandle(AgStateMachineWiFiManagerPortalActive);
|
sm.ledHandle(AgStateMachineWiFiManagerPortalActive);
|
||||||
// ledSmHandler(AgStateMachineWiFiManagerPortalActive);
|
|
||||||
} else {
|
} else {
|
||||||
// ledCount = LED_BAR_COUNT_INIT_VALUE;
|
|
||||||
sm.ledAnimationInit();
|
sm.ledAnimationInit();
|
||||||
// ledSmHandler(AgStateMachineWiFiManagerMode);
|
|
||||||
sm.ledHandle(AgStateMachineWiFiManagerMode);
|
sm.ledHandle(AgStateMachineWiFiManagerMode);
|
||||||
if (ag.isOneIndoor()) {
|
if (ag->isOneIndoor()) {
|
||||||
// dispSmHandler(AgStateMachineWiFiManagerMode);
|
|
||||||
sm.displayHandle(AgStateMachineWiFiManagerMode);
|
sm.displayHandle(AgStateMachineWiFiManagerMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delay(1); // avoid watchdog timer reset.
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Show display wifi connect result failed */
|
/** Show display wifi connect result failed */
|
||||||
if (WiFi.isConnected() == false) {
|
if (WiFi.isConnected() == false) {
|
||||||
sm.ledHandle(AgStateMachineWiFiManagerConnectFailed);
|
sm.ledHandle(AgStateMachineWiFiManagerConnectFailed);
|
||||||
// ledSmHandler(AgStateMachineWiFiManagerConnectFailed);
|
if (ag->isOneIndoor()) {
|
||||||
if (ag.isOneIndoor()) {
|
|
||||||
// dispSmHandler(AgStateMachineWiFiManagerConnectFailed);
|
|
||||||
sm.displayHandle(AgStateMachineWiFiManagerConnectFailed);
|
sm.displayHandle(AgStateMachineWiFiManagerConnectFailed);
|
||||||
}
|
}
|
||||||
delay(6000);
|
delay(6000);
|
||||||
} else {
|
} else {
|
||||||
wifiHasConfig = true;
|
hasConfig = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update LED bar color */
|
return true;
|
||||||
appLedHandler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AgWiFiConnector::wifiClientConnected(void) {
|
bool AgWiFiConnector::wifiClientConnected(void) {
|
||||||
@ -123,18 +119,19 @@ bool AgWiFiConnector::wifiClientConnected(void) {
|
|||||||
|
|
||||||
void AgWiFiConnector::_wifiApCallback(void) {
|
void AgWiFiConnector::_wifiApCallback(void) {
|
||||||
sm.displayWiFiConnectCountDown(WIFI_CONNECT_COUNTDOWN_MAX);
|
sm.displayWiFiConnectCountDown(WIFI_CONNECT_COUNTDOWN_MAX);
|
||||||
sm.ledAnimationInit();
|
|
||||||
sm.setDisplayState(AgStateMachineWiFiManagerMode);
|
sm.setDisplayState(AgStateMachineWiFiManagerMode);
|
||||||
|
sm.ledAnimationInit();
|
||||||
|
sm.ledHandle(AgStateMachineWiFiManagerMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgWiFiConnector::_wifiSaveConfig(void) {
|
void AgWiFiConnector::_wifiSaveConfig(void) {
|
||||||
sm.setDisplayState(AgStateMachineWiFiManagerStaConnected);
|
sm.setDisplayState(AgStateMachineWiFiManagerStaConnected);
|
||||||
sm.ledHandle();
|
sm.ledHandle(AgStateMachineWiFiManagerStaConnected);
|
||||||
// sm.displayHandle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AgWiFiConnector::_wifiSaveParamCallback(void) {
|
void AgWiFiConnector::_wifiSaveParamCallback(void) {
|
||||||
sm.ledAnimationInit();
|
sm.ledAnimationInit();
|
||||||
|
sm.ledHandle(AgStateMachineWiFiManagerStaConnecting);
|
||||||
sm.setDisplayState(AgStateMachineWiFiManagerStaConnecting);
|
sm.setDisplayState(AgStateMachineWiFiManagerStaConnecting);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,3 +140,27 @@ bool AgWiFiConnector::_wifiConfigPortalActive(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AgWiFiConnector::_wifiProcess() { WIFI()->process(); }
|
void AgWiFiConnector::_wifiProcess() { WIFI()->process(); }
|
||||||
|
|
||||||
|
void AgWiFiConnector::handle(void) {
|
||||||
|
// Ignore if WiFi is not configured
|
||||||
|
if (hasConfig == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (WiFi.isConnected()) {
|
||||||
|
lastRetry = millis();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Retry connect WiFi each 10sec */
|
||||||
|
uint32_t ms = (uint32_t)(millis() - lastRetry);
|
||||||
|
if (ms >= 10000) {
|
||||||
|
lastRetry = millis();
|
||||||
|
WiFi.reconnect();
|
||||||
|
|
||||||
|
// Serial.printf("Re-Connect WiFi\r\n");
|
||||||
|
logInfo("Re-Connect WiFi");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AgWiFiConnector::isConnected(void) { return WiFi.isConnected(); }
|
||||||
|
@ -2,33 +2,37 @@
|
|||||||
#define _AG_WIFI_CONNECTOR_H_
|
#define _AG_WIFI_CONNECTOR_H_
|
||||||
|
|
||||||
#include "AgOledDisplay.h"
|
#include "AgOledDisplay.h"
|
||||||
#include "AirGradient.h"
|
|
||||||
#include "AgStateMachine.h"
|
#include "AgStateMachine.h"
|
||||||
|
#include "AirGradient.h"
|
||||||
#include "Main/PrintLog.h"
|
#include "Main/PrintLog.h"
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
class AgWiFiConnector : public PrintLog {
|
class AgWiFiConnector : public PrintLog {
|
||||||
private:
|
private:
|
||||||
AirGradient &ag;
|
AirGradient *ag;
|
||||||
AgOledDisplay &disp;
|
AgOledDisplay &disp;
|
||||||
AgStateMachine &sm;
|
AgStateMachine &sm;
|
||||||
String ssid;
|
String ssid;
|
||||||
void *wifi = NULL;
|
void *wifi = NULL;
|
||||||
|
bool hasConfig;
|
||||||
|
uint32_t lastRetry;
|
||||||
|
|
||||||
bool wifiClientConnected(void);
|
bool wifiClientConnected(void);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AgWiFiConnector(AirGradient &ag, AgOledDisplay &disp, String ssid,
|
AgWiFiConnector(AgOledDisplay &disp, Stream &log, AgStateMachine &sm);
|
||||||
Stream &log, AgStateMachine &sm);
|
|
||||||
~AgWiFiConnector();
|
~AgWiFiConnector();
|
||||||
|
|
||||||
void setHotspotSSID(String ssid);
|
void setAirGradient(AirGradient *ag);
|
||||||
bool connect(uint32_t timeout);
|
bool connect(void);
|
||||||
|
void handle(void);
|
||||||
void _wifiApCallback(void);
|
void _wifiApCallback(void);
|
||||||
void _wifiSaveConfig(void);
|
void _wifiSaveConfig(void);
|
||||||
void _wifiSaveParamCallback(void);
|
void _wifiSaveParamCallback(void);
|
||||||
bool _wifiConfigPortalActive(void);
|
bool _wifiConfigPortalActive(void);
|
||||||
void _wifiProcess();
|
void _wifiProcess();
|
||||||
|
bool isConnected(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /** _AG_WIFI_CONNECTOR_H_ */
|
#endif /** _AG_WIFI_CONNECTOR_H_ */
|
||||||
|
Reference in New Issue
Block a user