Skip to content

Commit

Permalink
Fix power on animation when increasing brightness
Browse files Browse the repository at this point in the history
  • Loading branch information
DrA1ex committed Oct 28, 2024
1 parent 151ec64 commit 5c590b3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@ CheckOptions:
readability-identifier-naming.PrivateMemberCase: lower_case
readability-identifier-naming.PrivateMemberPrefix: _
readability-identifier-naming.PrivateMethodPrefix: _
readability-identifier-naming.ClassMethodPrefix: _
17 changes: 10 additions & 7 deletions src/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void Application::begin() {
}
});

_btn->set_hold_call_interval(BTN_HOLD_CALL_INTERVAL);
_btn->begin();
}

Expand Down Expand Up @@ -162,25 +163,27 @@ void Application::change_state(AppState s) {
D_PRINTF("Change app state: %s\r\n", __debug_enum_str(s));
}

void Application::set_power(bool on) {
void Application::set_power(bool on, bool skip_animation) {
config().power = on;

D_PRINTF("Turning Power: %s\r\n", on ? "ON" : "OFF");
if (_state != AppState::INITIALIZATION) {
if (!skip_animation && _state != AppState::INITIALIZATION) {
change_state(on ? AppState::TURNING_ON : AppState::TURNING_OFF);
} else {
change_state(AppState::STAND_BY);
load();
}

_bootstrap->save_changes();
NotificationBus::get().notify_parameter_changed(this, _metadata->power.get_parameter());
}

void Application::brightness_increase() {
if (config().brightness == PWM_MAX_VALUE) return;
if (!config().power) set_power(true, true);

if (!config().power) set_power(true);
if (config().brightness == PWM_MAX_VALUE) return;

config().brightness = std::min<uint16_t>(PWM_MAX_VALUE,
config().brightness + max<uint16_t>(1, config().brightness / BRIGHTNESS_CHANGE_DIVIDER));
config().brightness = std::min<uint16_t>(PWM_MAX_VALUE, config().brightness + max<uint16_t>(1, PWM_MAX_VALUE / BRIGHTNESS_CHANGE_DIVIDER));

D_PRINTF("Increase brightness: %u\r\n", config().brightness);
update();
Expand All @@ -189,7 +192,7 @@ void Application::brightness_increase() {
void Application::brightness_decrease() {
if (config().brightness == 0) return;

config().brightness = std::max(0, config().brightness - std::max<uint16_t>(1, config().brightness / BRIGHTNESS_CHANGE_DIVIDER));
config().brightness = std::max(0, config().brightness - std::max<uint16_t>(1, PWM_MAX_VALUE / BRIGHTNESS_CHANGE_DIVIDER));

D_PRINTF("Decrease brightness: %u\r\n", config().brightness);
update();
Expand Down
2 changes: 1 addition & 1 deletion src/app/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Application {
void event_loop();

void change_state(AppState s);
void set_power(bool on);
void set_power(bool on, bool skip_animation = false);

void brightness_increase();
void brightness_decrease();
Expand Down
2 changes: 1 addition & 1 deletion src/lib
Submodule lib updated from 017fa5 to e97443
4 changes: 3 additions & 1 deletion src/sys_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@
#define LED_MIN_TEMPERATURE (2700u)
#define LED_MAX_TEMPERATURE (6000u)

#define BRIGHTNESS_CHANGE_DIVIDER (20u)
#define BRIGHTNESS_CHANGE_DIVIDER (50u)
#define TEMPERATURE_CHANGE_STEPS (4u)

#define BTN_HOLD_CALL_INTERVAL (20u)

0 comments on commit 5c590b3

Please sign in to comment.