From a039947e136ae447c6870e90afd600fa2a259dfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Tue, 3 Jan 2023 14:47:46 +0100 Subject: [PATCH] FIX: double-buffer needs to take 'brightness' into account --- src/display/Display.h | 17 +++++++++++------ src/server.cpp | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/display/Display.h b/src/display/Display.h index 24de167..3be8c6f 100644 --- a/src/display/Display.h +++ b/src/display/Display.h @@ -35,6 +35,8 @@ private: Color *buffer = nullptr; + uint8_t brightness = 10; + public: Display(uint8_t width, uint8_t height) : @@ -60,7 +62,6 @@ public: void setup() { leds.begin(); - leds.setBrightness(8); clear(); flush(); } @@ -73,12 +74,12 @@ public: } } - void setBrightness(uint8_t brightness) { - leds.setBrightness(brightness); + void setBrightness(uint8_t value) { + brightness = value; } - uint8_t getBrightness() { - return leds.getBrightness(); + uint8_t getBrightness() const { + return brightness; } void clear() { @@ -124,7 +125,11 @@ public: if (buffer == nullptr) { return; } - buffer[index] = color; + buffer[index] = { + (uint8_t) (color.r * brightness >> 8), + (uint8_t) (color.g * brightness >> 8), + (uint8_t) (color.b * brightness >> 8) + }; } private: diff --git a/src/server.cpp b/src/server.cpp index 2fa97ba..6495611 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -86,7 +86,7 @@ void web_brighter() { } void web_darker() { - setBrightness(max(1, display.getBrightness() - 10)); + setBrightness(display.getBrightness() - 10); redirect(); }