From 773f2857678727f416a67a3a5ae71bd5b6761078 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 29 Aug 2023 12:18:15 +1000 Subject: [PATCH] Don't fade for brightness slider changes --- src/drivers/display.cpp | 16 +++++++++++----- src/drivers/include/display.hpp | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/drivers/display.cpp b/src/drivers/display.cpp index 257327d7..2d480aa6 100644 --- a/src/drivers/display.cpp +++ b/src/drivers/display.cpp @@ -198,20 +198,26 @@ Display::~Display() { auto Display::SetDisplayOn(bool enabled) -> void { display_on_ = enabled; int new_duty = display_on_ ? brightness_ : 0; - SetDutyCycle(new_duty); + SetDutyCycle(new_duty, true); } auto Display::SetBrightness(uint_fast8_t percent) -> void { brightness_ = std::pow(static_cast(percent) / 100.0, 2.8) * 1024.0 + 0.5; if (display_on_) { - SetDutyCycle(brightness_); + SetDutyCycle(brightness_, false); } } -auto Display::SetDutyCycle(uint_fast8_t new_duty) -> void { - ledc_set_fade_with_time(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, new_duty, 100); - ledc_fade_start(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, LEDC_FADE_NO_WAIT); +auto Display::SetDutyCycle(uint_fast8_t new_duty, bool fade) -> void { + if (fade) { + ledc_set_fade_with_time(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, new_duty, 100); + ledc_fade_start(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, LEDC_FADE_NO_WAIT); + } else { + ESP_ERROR_CHECK( + ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, new_duty)); + ESP_ERROR_CHECK(ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0)); + } } void Display::SendInitialisationSequence(const uint8_t* data) { diff --git a/src/drivers/include/display.hpp b/src/drivers/include/display.hpp index 3e667be7..77165c99 100644 --- a/src/drivers/include/display.hpp +++ b/src/drivers/include/display.hpp @@ -76,7 +76,7 @@ class Display { const uint8_t* data, size_t length); - auto SetDutyCycle(uint_fast8_t) -> void; + auto SetDutyCycle(uint_fast8_t, bool) -> void; }; } // namespace drivers