diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-08-29 12:18:15 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-08-29 12:18:15 +1000 |
| commit | 773f2857678727f416a67a3a5ae71bd5b6761078 (patch) | |
| tree | 5cd8a17aa50f7a3b218bcf92cf645e895b3b0a4c /src/drivers | |
| parent | f2bb2e25281a14adf9c6b2e7e91bfe14460f2ae4 (diff) | |
| download | tangara-fw-773f2857678727f416a67a3a5ae71bd5b6761078.tar.gz | |
Don't fade for brightness slider changes
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/display.cpp | 16 | ||||
| -rw-r--r-- | 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<double>(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 |
