Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LED bar flickers #138

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions examples/OneOpenAir/OneOpenAir.ino
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ static void ledBarEnabledUpdate(void) {
ag->ledBar.setBrighness(brightness);
ag->ledBar.setEnable(configuration.getLedBarMode() != LedBarModeOff);
}
ag->ledBar.show();
}
}

Expand Down Expand Up @@ -804,10 +805,6 @@ static void configUpdateHandle() {
return;
}

if (ag->isOne()) {
ledBarEnabledUpdate();
stateMachine.executeLedBarTest();
}
stateMachine.executeCo2Calibration();

String mqttUri = configuration.getMqttBrokerUri();
Expand Down Expand Up @@ -843,15 +840,42 @@ static void configUpdateHandle() {

if (ag->isOne()) {
if (configuration.isLedBarBrightnessChanged()) {
ag->ledBar.setBrighness(configuration.getLedBarBrightness());
Serial.println("Set 'LedBarBrightness' brightness: " +
if (configuration.getLedBarBrightness() == 0) {
ag->ledBar.setEnable(false);
} else {
if (configuration.getLedBarMode() != LedBarMode::LedBarModeOff) {
ag->ledBar.setEnable(true);
}
ag->ledBar.setBrighness(configuration.getLedBarBrightness());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setBrighness -> setBrightness

}
ag->ledBar.show();
Serial.println("Set 'ledBarBrightness' brightness: " +
String(configuration.getLedBarBrightness()));
}

if (configuration.isLedBarModeChanged()) {
Serial.println("Set 'ledBarMode' " + String(configuration.getLedBarMode()));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do not really "set" the ledBarMode then later on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll remove it. It's just for test.

Serial.println("Get 'ledBarBrightness' " + String(configuration.getLedBarBrightness()));
if (configuration.getLedBarBrightness() == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code is redundant to what we have on line 843 onwards?

Copy link
Collaborator Author

@pnt325 pnt325 May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes a bit of same.

at 843: focus to set brightness
at 849: focus to enable/disable LED bar.

ag->ledBar.setEnable(false);
} else {
if(configuration.getLedBarMode() == LedBarMode::LedBarModeOff) {
ag->ledBar.setEnable(false);
} else {
ag->ledBar.setEnable(true);
ag->ledBar.setBrighness(configuration.getLedBarBrightness());
}
}
ag->ledBar.show();
}

if (configuration.isDisplayBrightnessChanged()) {
oledDisplay.setBrightness(configuration.getDisplayBrightness());
Serial.println("Set 'DisplayBrightness' brightness: " +
String(configuration.getDisplayBrightness()));
}

stateMachine.executeLedBarTest();
}

fwNewVersion = configuration.newFirmwareVersion();
Expand Down
9 changes: 9 additions & 0 deletions src/AgConfigure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ bool Configuration::parse(String data, bool isLocal) {
}
}

_ledBarModeChanged = false;
if (JSON.typeof_(root[jprop_ledBarMode]) == "string") {
String mode = root[jprop_ledBarMode];
if (mode == getLedBarModeName(LedBarMode::LedBarModeCO2) ||
Expand All @@ -380,6 +381,7 @@ bool Configuration::parse(String data, bool isLocal) {
String oldMode = jconfig[jprop_ledBarMode];
if (mode != oldMode) {
jconfig[jprop_ledBarMode] = mode;
_ledBarModeChanged = true;
changed = true;
}
} else {
Expand Down Expand Up @@ -559,6 +561,7 @@ bool Configuration::parse(String data, bool isLocal) {
}
}

ledBarBrightnessChanged = false;
if (JSON.typeof_(root[jprop_ledBarBrightness]) == "number") {
int value = root[jprop_ledBarBrightness];
int oldValue = jconfig[jprop_ledBarBrightness];
Expand Down Expand Up @@ -1148,6 +1151,12 @@ void Configuration::setOfflineModeWithoutSave(bool offline) {
_offlineMode = offline;
}

bool Configuration::isLedBarModeChanged(void) {
bool changed = _ledBarModeChanged;
_ledBarModeChanged = false;
return changed;
}

bool Configuration::isDisplayBrightnessChanged(void) {
bool changed = displayBrightnessChanged;
displayBrightnessChanged = false;
Expand Down
2 changes: 2 additions & 0 deletions src/AgConfigure.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Configuration : public PrintLog {
bool displayBrightnessChanged = false;
String otaNewFirmwareVersion;
bool _offlineMode = false;
bool _ledBarModeChanged = false;

AirGradient* ag;

Expand Down Expand Up @@ -80,6 +81,7 @@ class Configuration : public PrintLog {
bool isOfflineMode(void);
void setOfflineMode(bool offline);
void setOfflineModeWithoutSave(bool offline);
bool isLedBarModeChanged(void);
};

#endif /** _AG_CONFIG_H_ */