mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-04 11:46:32 +02:00
Implement display / ledBar brightness
This commit is contained in:
@ -414,6 +414,7 @@ static void wdgFeedUpdate(void) {
|
||||
|
||||
static void ledBarEnabledUpdate(void) {
|
||||
if (ag->isOne()) {
|
||||
ag->ledBar.setBrighness(configuration.getLedBarBrightness());
|
||||
ag->ledBar.setEnable(configuration.getLedBarMode() != LedBarModeOff);
|
||||
}
|
||||
}
|
||||
@ -721,6 +722,17 @@ static void configUpdateHandle() {
|
||||
}
|
||||
}
|
||||
|
||||
if (configuration.isLedBarBrightnessChanged()) {
|
||||
ag->ledBar.setBrighness(configuration.getLedBarBrightness());
|
||||
Serial.println("Set 'LedBarBrightness' brightness: " +
|
||||
String(configuration.getLedBarBrightness()));
|
||||
}
|
||||
if (configuration.isDisplayBrightnessChanged()) {
|
||||
oledDisplay.setBrightness(configuration.getDisplayBrightness());
|
||||
Serial.println("Set 'DisplayBrightness' brightness: " +
|
||||
String(configuration.getDisplayBrightness()));
|
||||
}
|
||||
|
||||
appDispHandler();
|
||||
appLedHandler();
|
||||
}
|
||||
|
@ -125,6 +125,15 @@ void Configuration::loadConfig(void) {
|
||||
changed = true;
|
||||
logError("LedBarMode invalid, set default: co2");
|
||||
}
|
||||
if (config.ledBarBrightness > 100) {
|
||||
config.ledBarBrightness = 100;
|
||||
changed = true;
|
||||
}
|
||||
if (config.displayBrightness > 100) {
|
||||
config.displayBrightness = 100;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
saveConfig();
|
||||
}
|
||||
@ -152,6 +161,8 @@ void Configuration::defaultConfig(void) {
|
||||
config.tvocLearningOffset = 12;
|
||||
config.noxLearningOffset = 12;
|
||||
config.temperatureUnit = 'c';
|
||||
config.ledBarBrightness = 100;
|
||||
config.displayBrightness = 100;
|
||||
|
||||
saveConfig();
|
||||
}
|
||||
@ -581,6 +592,52 @@ bool Configuration::parse(String data, bool isLocal) {
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON.typeof_(root["ledbarBrightness"]) == "number") {
|
||||
int brightnress = root["ledbarBrightness"];
|
||||
if (brightnress != config.ledBarBrightness) {
|
||||
if (brightnress <= 100) {
|
||||
changed = true;
|
||||
configLogInfo("ledbarBrightness", String(config.ledBarBrightness),
|
||||
String(brightnress));
|
||||
ledBarBrightnessChanged = true;
|
||||
config.ledBarBrightness = (uint8_t)brightnress;
|
||||
} else {
|
||||
failedMessage =
|
||||
"\"ledbarBrightness\" value invalid: " + String(brightnress);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["ledbarBrightness"], "number")) {
|
||||
failedMessage = jsonTypeInvalidMessage("ledbarBrightness", "number");
|
||||
jsonInvalid();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON.typeof_(root["displayBrightness"]) == "number") {
|
||||
int brightness = root["displayBrightness"];
|
||||
if (brightness != config.displayBrightness) {
|
||||
if (brightness <= 100) {
|
||||
changed = true;
|
||||
displayBrightnessChanged = true;
|
||||
configLogInfo("displayBrightness", String(config.displayBrightness),
|
||||
String(brightness));
|
||||
config.displayBrightness = (uint8_t)brightness;
|
||||
} else {
|
||||
failedMessage =
|
||||
"\"displayBrightness\" value invalid: " + String(brightness);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (jsonTypeInvalid(root["displayBrightness"], "number")) {
|
||||
failedMessage = jsonTypeInvalidMessage("displayBrightness", "number");
|
||||
jsonInvalid();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
udpated = true;
|
||||
saveConfig();
|
||||
@ -643,6 +700,12 @@ String Configuration::toString(void) {
|
||||
/** "postDataToAirGradient" */
|
||||
root["postDataToAirGradient"] = config.postDataToAirGradient;
|
||||
|
||||
/** Led bar brighness */
|
||||
root["ledbarBrightness"] = config.ledBarBrightness;
|
||||
|
||||
/** Display brighness */
|
||||
root["displayBrightness"] = config.displayBrightness;
|
||||
|
||||
return JSON.stringify(root);
|
||||
}
|
||||
|
||||
@ -857,3 +920,21 @@ String Configuration::wifiSSID(void) { return "airgradient-" + ag->deviceId(); }
|
||||
String Configuration::wifiPass(void) { return String("cleanair"); }
|
||||
|
||||
void Configuration::setAirGradient(AirGradient *ag) { this->ag = ag; }
|
||||
|
||||
int Configuration::getLedBarBrightness(void) { return config.ledBarBrightness; }
|
||||
|
||||
bool Configuration::isLedBarBrightnessChanged(void) {
|
||||
bool changed = ledBarBrightnessChanged;
|
||||
ledBarBrightnessChanged = false;
|
||||
return changed;
|
||||
}
|
||||
|
||||
int Configuration::getDisplayBrightness(void) {
|
||||
return config.displayBrightness;
|
||||
}
|
||||
|
||||
bool Configuration::isDisplayBrightnessChanged(void) {
|
||||
bool changed = displayBrightnessChanged;
|
||||
displayBrightnessChanged = false;
|
||||
return changed;
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ private:
|
||||
bool displayMode; /** true if enable display */
|
||||
uint8_t useRGBLedBar;
|
||||
uint8_t abcDays;
|
||||
uint8_t ledBarBrightness;
|
||||
uint8_t displayBrightness;
|
||||
int tvocLearningOffset;
|
||||
int noxLearningOffset;
|
||||
char temperatureUnit; // 'f' or 'c'
|
||||
@ -36,6 +38,8 @@ private:
|
||||
String failedMessage;
|
||||
bool _noxLearnOffsetChanged;
|
||||
bool _tvocLearningOffsetChanged;
|
||||
bool ledBarBrightnessChanged = false;
|
||||
bool displayBrightnessChanged = false;
|
||||
|
||||
AirGradient* ag;
|
||||
|
||||
@ -89,6 +93,10 @@ public:
|
||||
String wifiSSID(void);
|
||||
String wifiPass(void);
|
||||
void setAirGradient(AirGradient *ag);
|
||||
bool isLedBarBrightnessChanged(void);
|
||||
int getLedBarBrightness(void);
|
||||
bool isDisplayBrightnessChanged(void);
|
||||
int getDisplayBrightness(void);
|
||||
};
|
||||
|
||||
#endif /** _AG_CONFIG_H_ */
|
||||
|
@ -94,6 +94,8 @@ bool OledDisplay::begin(void) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setBrightness(config.getDisplayBrightness());
|
||||
|
||||
isBegin = true;
|
||||
logInfo("begin");
|
||||
return true;
|
||||
@ -308,3 +310,7 @@ void OledDisplay::showWiFiQrCode(String content, String label) {
|
||||
DISP()->drawStr(x_start, 60, label.c_str());
|
||||
} while (DISP()->nextPage());
|
||||
}
|
||||
|
||||
void OledDisplay::setBrightness(int percent) {
|
||||
DISP()->setContrast((127 * percent) / 100);
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
void showDashboard(void);
|
||||
void showDashboard(const char *status);
|
||||
void showWiFiQrCode(String content, String label);
|
||||
void setBrightness(int percent);
|
||||
};
|
||||
|
||||
#endif /** _AG_OLED_DISPLAY_H_ */
|
||||
|
@ -62,13 +62,13 @@ void LedBar::setColor(uint8_t red, uint8_t green, uint8_t blue, int ledNum) {
|
||||
/**
|
||||
* @brief Set LED brightness apply for all LED bar
|
||||
*
|
||||
* @param brightness Brightness (0 - 255)
|
||||
* @param brightness Brightness (0 - 100)%
|
||||
*/
|
||||
void LedBar::setBrighness(uint8_t brightness) {
|
||||
if (this->isBegin() == false) {
|
||||
return;
|
||||
}
|
||||
pixel()->setBrightness(brightness);
|
||||
pixel()->setBrightness((brightness * 0xff) / 100);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user