diff --git a/src/AgApiClient.cpp b/src/AgApiClient.cpp index a713fe7..6ba54cc 100644 --- a/src/AgApiClient.cpp +++ b/src/AgApiClient.cpp @@ -51,13 +51,16 @@ bool AgApiClient::fetchServerConfiguration(void) { HTTPClient client; WiFiClient wifiClient; if (client.begin(wifiClient, uri) == false) { -#else - HTTPClient client; - if (client.begin(uri) == false) { -#endif getConfigFailed = true; return false; } +#else + HTTPClient client; + if (client.begin(uri) == false) { + getConfigFailed = true; + return false; + } +#endif /** Get data */ int retCode = client.GET(); diff --git a/src/AgConfigure.cpp b/src/AgConfigure.cpp index e6230a5..5b0c762 100644 --- a/src/AgConfigure.cpp +++ b/src/AgConfigure.cpp @@ -5,12 +5,19 @@ const char *CONFIGURATION_CONTROL_NAME[] = { [ConfigurationControlLocal] = "local", [ConfigurationControlCloud] = "cloud", [ConfigurationControlBoth] = "both"}; + const char *LED_BAR_MODE_NAMES[] = { [LedBarModeOff] = "off", [LedBarModePm] = "pm", [LedBarModeCO2] = "co2", }; +/** + * @brief Get LedBarMode Name + * + * @param mode LedBarMode value + * @return String + */ String AgConfigure::getLedBarModeName(LedBarMode mode) { if (mode == LedBarModeOff) { return String(LED_BAR_MODE_NAMES[LedBarModeOff]); @@ -22,6 +29,10 @@ String AgConfigure::getLedBarModeName(LedBarMode mode) { return String("unknown"); } +/** + * @brief Save configure to device storage (EEPROM) + * + */ void AgConfigure::saveConfig(void) { config._check = 0; int len = sizeof(config) - sizeof(config._check); @@ -71,6 +82,11 @@ void AgConfigure::loadConfig(void) { } } } + +/** + * @brief Set configuration default + * + */ void AgConfigure::defaultConfig(void) { // Default country is null memset(config.country, 0, sizeof(config.country)); @@ -91,12 +107,31 @@ void AgConfigure::defaultConfig(void) { saveConfig(); } +/** + * @brief Show configuration as JSON string message over log + * + */ void AgConfigure::printConfig(void) { logInfo(toString().c_str()); } +/** + * @brief Construct a new Ag Configure:: Ag Configure object + * + * @param debugLog Serial Stream + */ AgConfigure::AgConfigure(Stream &debugLog) : PrintLog(debugLog, "Configure") {} +/** + * @brief Destroy the Ag Configure:: Ag Configure object + * + */ AgConfigure::~AgConfigure() {} +/** + * @brief Initialize configuration + * + * @return true Success + * @return false Failure + */ bool AgConfigure::begin(void) { EEPROM.begin(512); loadConfig(); @@ -360,6 +395,11 @@ bool AgConfigure::parse(String data, bool isLocal) { return true; } +/** + * @brief Get current configuration value as JSON string + * + * @return String + */ String AgConfigure::toString(void) { JSONVar root; @@ -407,32 +447,86 @@ String AgConfigure::toString(void) { return JSON.stringify(root); } +/** + * @brief Temperature unit (F or C) + * + * @return true F + * @return false C + */ bool AgConfigure::isTemperatureUnitInF(void) { return (config.temperatureUnit == 'f'); } +/** + * @brief Country name, it's short name ex: TH = Thailand + * + * @return String + */ String AgConfigure::getCountry(void) { return String(config.country); } +/** + * @brief PM unit standard (USAQI, ugm3) + * + * @return true USAQI + * @return false ugm3 + */ bool AgConfigure::isPmStandardInUSAQI(void) { return config.inUSAQI; } +/** + * @brief Get CO2 calibration ABC time + * + * @return int Number of day + */ int AgConfigure::getCO2CalirationAbcDays(void) { return config.abcDays; } +/** + * @brief Get Led Bar Mode + * + * @return LedBarMode + */ LedBarMode AgConfigure::getLedBarMode(void) { return (LedBarMode)config.useRGBLedBar; } +/** + * @brief Get LED bar mode name + * + * @return String + */ String AgConfigure::getLedBarModeName(void) { return getLedBarModeName((LedBarMode)config.useRGBLedBar); } +/** + * @brief Get display mode + * + * @return true On + * @return false Off + */ bool AgConfigure::getDisplayMode(void) { return config.displayMode; } +/** + * @brief Get MQTT uri + * + * @return String + */ String AgConfigure::getMqttBrokerUri(void) { return String(config.mqttBroker); } +/** + * @brief Get configuratoin post data to AirGradient cloud + * + * @return true Post + * @return false No-Post + */ bool AgConfigure::isPostDataToAirGradient(void) { return config.postDataToAirGradient; } +/** + * @brief Get current configuration control + * + * @return ConfigurationControl + */ ConfigurationControl AgConfigure::getConfigurationControl(void) { return (ConfigurationControl)config.configurationControl; } diff --git a/src/AgOledDisplay.cpp b/src/AgOledDisplay.cpp index b73d69b..a123f13 100644 --- a/src/AgOledDisplay.cpp +++ b/src/AgOledDisplay.cpp @@ -1,8 +1,14 @@ #include "AgOledDisplay.h" #include "Libraries/U8g2/src/U8g2lib.h" +/** Cast U8G2 */ #define DISP() ((U8G2_SH1106_128X64_NONAME_F_HW_I2C *)(this->u8g2)) +/** + * @brief Show dashboard temperature and humdity + * + * @param hasStatus + */ void AgOledDisplay::showTempHum(bool hasStatus) { char buf[10]; if (value.Temperature > -1001) { @@ -43,9 +49,21 @@ void AgOledDisplay::showTempHum(bool hasStatus) { } } +/** + * @brief Construct a new Ag Oled Display:: Ag Oled Display object + * + * @param config AgConfiguration + * @param value AgValue + * @param log Serial Stream + */ AgOledDisplay::AgOledDisplay(AgConfigure &config, AgValue &value, Stream &log) : PrintLog(log, "AgOledDisplay"), config(config), value(value) {} +/** + * @brief Set AirGradient instance + * + * @param ag Point to AirGradient instance + */ void AgOledDisplay::setAirGradient(AirGradient *ag) { this->ag = ag; } AgOledDisplay::~AgOledDisplay() {} @@ -98,14 +116,24 @@ void AgOledDisplay::end(void) { logInfo("end"); } -void AgOledDisplay::setStatus(String &status) { setStatus(status.c_str()); } - -void AgOledDisplay::setStatus(const char *status) {} - +/** + * @brief Show text on 3 line of display + * + * @param line1 + * @param line2 + * @param line3 + */ void AgOledDisplay::setText(String &line1, String &line2, String &line3) { setText(line1.c_str(), line2.c_str(), line3.c_str()); } +/** + * @brief Show text on 3 line of display + * + * @param line1 + * @param line2 + * @param line3 + */ void AgOledDisplay::setText(const char *line1, const char *line2, const char *line3) { DISP()->firstPage(); @@ -117,15 +145,27 @@ void AgOledDisplay::setText(const char *line1, const char *line2, } while (DISP()->nextPage()); } -void AgOledDisplay::setText(const char *text) {} - -void AgOledDisplay::setText(String &text) {} - +/** + * @brief Set Text on 4 line + * + * @param line1 + * @param line2 + * @param line3 + * @param line4 + */ void AgOledDisplay::setText(String &line1, String &line2, String &line3, String &line4) { setText(line1.c_str(), line2.c_str(), line3.c_str(), line4.c_str()); } +/** + * @brief Set Text on 4 line + * + * @param line1 + * @param line2 + * @param line3 + * @param line4 + */ void AgOledDisplay::setText(const char *line1, const char *line2, const char *line3, const char *line4) { DISP()->firstPage(); @@ -138,8 +178,16 @@ void AgOledDisplay::setText(const char *line1, const char *line2, } while (DISP()->nextPage()); } +/** + * @brief Update dashboard content + * + */ void AgOledDisplay::showDashboard(void) { showDashboard(NULL); } +/** + * @brief Update dashboard content and error status + * + */ void AgOledDisplay::showDashboard(const char *status) { char strBuf[10]; diff --git a/src/AgOledDisplay.h b/src/AgOledDisplay.h index eb79721..a5bf54a 100644 --- a/src/AgOledDisplay.h +++ b/src/AgOledDisplay.h @@ -24,12 +24,8 @@ public: void setAirGradient(AirGradient *ag); bool begin(void); void end(void); - void setStatus(String &status); - void setStatus(const char *status); void setText(String &line1, String &line2, String &line3); void setText(const char *line1, const char *line2, const char *line3); - void setText(const char *text); - void setText(String &text); void setText(String &line1, String &line2, String &line3, String &line4); void setText(const char *line1, const char *line2, const char *line3, const char *line4); diff --git a/src/AgStateMachine.cpp b/src/AgStateMachine.cpp index 464e324..65b3e48 100644 --- a/src/AgStateMachine.cpp +++ b/src/AgStateMachine.cpp @@ -5,6 +5,13 @@ #define LED_SHORT_BLINK_DELAY 500 /** ms */ #define LED_LONG_BLINK_DELAY 2000 /** ms */ +/** + * @brief Animation LED bar with color + * + * @param r + * @param g + * @param b + */ void AgStateMachine::ledBarSingleLedAnimation(uint8_t r, uint8_t g, uint8_t b) { if (ledBarAnimationCount < 0) { ledBarAnimationCount = 0; @@ -18,6 +25,11 @@ void AgStateMachine::ledBarSingleLedAnimation(uint8_t r, uint8_t g, uint8_t b) { } } +/** + * @brief LED status blink with delay + * + * @param ms Miliseconds + */ void AgStateMachine::ledStatusBlinkDelay(uint32_t ms) { ag->statusLed.setOn(); delay(ms); @@ -25,6 +37,10 @@ void AgStateMachine::ledStatusBlinkDelay(uint32_t ms) { delay(ms); } +/** + * @brief Led bar show led color status + * + */ void AgStateMachine::sensorLedHandle(void) { switch (config.getLedBarMode()) { case LedBarMode::LedBarModeCO2: @@ -39,6 +55,10 @@ void AgStateMachine::sensorLedHandle(void) { } } +/** + * @brief Show CO2 LED status + * + */ void AgStateMachine::co2LedHandle(void) { int co2Value = value.CO2; if (co2Value <= 400) { @@ -118,6 +138,10 @@ void AgStateMachine::co2LedHandle(void) { } } +/** + * @brief Show PM2.5 LED status + * + */ void AgStateMachine::pm25LedHandle(void) { int pm25Value = value.PM25; if (pm25Value <= 5) { @@ -197,6 +221,14 @@ void AgStateMachine::pm25LedHandle(void) { } } +/** + * @brief Construct a new Ag State Machine:: Ag State Machine object + * + * @param disp AgOledDisplay + * @param log Serial Stream + * @param value AgValue + * @param config AgConfigure + */ AgStateMachine::AgStateMachine(AgOledDisplay &disp, Stream &log, AgValue &value, AgConfigure &config) : PrintLog(log, "AgStateMachine"), disp(disp), value(value), @@ -204,6 +236,11 @@ AgStateMachine::AgStateMachine(AgOledDisplay &disp, Stream &log, AgValue &value, AgStateMachine::~AgStateMachine() {} +/** + * @brief OLED display show content from state value + * + * @param state + */ void AgStateMachine::displayHandle(AgStateMachineState state) { // Ignore handle if not ONE_INDOOR board if (!ag->isOneIndoor()) { @@ -281,14 +318,23 @@ void AgStateMachine::displayHandle(AgStateMachineState state) { } case AgStateMachineNormal: { disp.showDashboard(); + break; } default: break; } } +/** + * @brief OLED display show content as previous state updated + * + */ void AgStateMachine::displayHandle(void) { displayHandle(dispState); } +/** + * @brief Update status add to dashboard + * + */ void AgStateMachine::displaySetAddToDashBoard(void) { addToDashBoard = true; addToDashboardTime = millis(); @@ -298,12 +344,26 @@ void AgStateMachine::displayClearAddToDashBoard(void) { addToDashBoard = false; } +/** + * @brief Set WiFi connection coundown on dashboard + * + * @param count Seconds + */ void AgStateMachine::displayWiFiConnectCountDown(int count) { wifiConnectCountDown = count; } +/** + * @brief Init before start LED bar animation + * + */ void AgStateMachine::ledAnimationInit(void) { ledBarAnimationCount = -1; } +/** + * @brief Handle LED from state + * + * @param state + */ void AgStateMachine::ledHandle(AgStateMachineState state) { if (state > AgStateMachineNormal) { logError("ledHandle: state invalid"); @@ -488,14 +548,38 @@ void AgStateMachine::ledHandle(AgStateMachineState state) { } } +/** + * @brief Handle LED as previous state updated + * + */ void AgStateMachine::ledHandle(void) { ledHandle(ledState); } +/** + * @brief Set display state + * + * @param state + */ void AgStateMachine::setDisplayState(AgStateMachineState state) { dispState = state; } +/** + * @brief Get current display state + * + * @return AgStateMachineState + */ AgStateMachineState AgStateMachine::getDisplayState(void) { return dispState; } +/** + * @brief Set AirGradient instance + * + * @param ag Point to AirGradient instance + */ void AgStateMachine::setAirGradient(AirGradient *ag) { this->ag = ag; } +/** + * @brief Get current LED state + * + * @return AgStateMachineState + */ AgStateMachineState AgStateMachine::getLedState(void) { return ledState; }