Skip to content

Commit

Permalink
[temporary commit]
Browse files Browse the repository at this point in the history
  • Loading branch information
pnt325 committed Apr 4, 2024
1 parent f681d4b commit dfba4fa
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/AgApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ bool AgApiClient::fetchServerConfiguration(void) {
HTTPClient client;
WiFiClient wifiClient;
if (client.begin(wifiClient, uri) == false) {
getConfigFailed = true;
return false;
}
#else
HTTPClient client;
if (client.begin(uri) == false) {
#endif
getConfigFailed = true;
return false;
}
#endif

/** Get data */
int retCode = client.GET();
Expand Down
94 changes: 94 additions & 0 deletions src/AgConfigure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand All @@ -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();
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
64 changes: 56 additions & 8 deletions src/AgOledDisplay.cpp
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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() {}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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];

Expand Down
4 changes: 0 additions & 4 deletions src/AgOledDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ class AgOledDisplay : public PrintLog {
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);
Expand Down
Loading

0 comments on commit dfba4fa

Please sign in to comment.