From cc18ff0a1548c88fe28b5d40cede171d3e115ea1 Mon Sep 17 00:00:00 2001 From: fvanroie <15969459+fvanroie@users.noreply.github.com> Date: Sat, 10 Apr 2021 17:33:21 +0200 Subject: [PATCH] Add backlight_invert --- src/dev/esp32/esp32.cpp | 1 + src/dev/esp32/esp32.h | 10 ++++++---- src/dev/esp8266/esp8266.cpp | 8 +++++--- src/dev/esp8266/esp8266.h | 10 ++++++---- src/dev/posix/hasp_posix.cpp | 6 ++++-- src/dev/posix/hasp_posix.h | 1 + src/dev/stm32f4/stm32f4.h | 8 +++++--- src/dev/win32/hasp_win32.cpp | 1 + src/dev/win32/hasp_win32.h | 6 ++++-- 9 files changed, 33 insertions(+), 18 deletions(-) diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index 8835cb9f..aa715f38 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -115,6 +115,7 @@ void Esp32Device::update_backlight() { if(_backlight_pin < GPIO_NUM_MAX) { uint32_t duty = _backlight_power ? map(_backlight_level, 0, 255, 0, 4095) : 0; + if(_backlight_invert) duty = 4095 - duty; ledcWrite(BACKLIGHT_CHANNEL, duty); // ledChannel and value } } diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index 72dde072..76d61c34 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -16,12 +16,13 @@ class Esp32Device : public BaseDevice { Esp32Device() { #ifdef MQTT_NODENAME - _hostname = MQTT_NODENAME; + _hostname = MQTT_NODENAME; #else - _hostname = "plate"; + _hostname = "plate"; #endif - _backlight_power = 1; - _backlight_level = 100; + _backlight_power = 1; + _backlight_invert = 0; + _backlight_level = 255; #ifdef TFT_BCKL _backlight_pin = TFT_BCKL; #else @@ -55,6 +56,7 @@ class Esp32Device : public BaseDevice { uint8_t _backlight_pin; uint8_t _backlight_level; uint8_t _backlight_power; + uint8_t _backlight_invert; void update_backlight(); }; diff --git a/src/dev/esp8266/esp8266.cpp b/src/dev/esp8266/esp8266.cpp index b3e53837..7cda5642 100644 --- a/src/dev/esp8266/esp8266.cpp +++ b/src/dev/esp8266/esp8266.cpp @@ -82,9 +82,11 @@ bool Esp8266Device::get_backlight_power() void Esp8266Device::update_backlight() { - if(_backlight_pin == -1) return; - - analogWrite(_backlight_pin, _backlight_power ? map(_backlight_level, 0, 255, 0, 1023) : 0); + if(_backlight_pin < GPIO_NUM_MAX) { + uint32_t duty = _backlight_power ? map(_backlight_level, 0, 255, 0, 1023) : 0; + if(_backlight_invert) duty = 1023 - duty; + analogWrite(_backlight_pin, duty); + } } size_t Esp8266Device::get_free_max_block() diff --git a/src/dev/esp8266/esp8266.h b/src/dev/esp8266/esp8266.h index 4c48d1ae..bd1502ae 100644 --- a/src/dev/esp8266/esp8266.h +++ b/src/dev/esp8266/esp8266.h @@ -16,10 +16,11 @@ class Esp8266Device : public BaseDevice { public: Esp8266Device() { - _hostname = "plate"; - _backlight_power = 1; - _backlight_level = 100; - _core_version = ESP.getCoreVersion().c_str(); + _hostname = "plate"; + _backlight_power = 1; + _backlight_invert = 0; + _backlight_level = 100; + _core_version = ESP.getCoreVersion().c_str(); #ifdef TFT_BCKL _backlight_pin = TFT_BCKL; #else @@ -55,6 +56,7 @@ class Esp8266Device : public BaseDevice { uint8_t _backlight_pin; uint8_t _backlight_level; uint8_t _backlight_power; + uint8_t _backlight_invert; void update_backlight(); }; diff --git a/src/dev/posix/hasp_posix.cpp b/src/dev/posix/hasp_posix.cpp index 01c7397b..18e84404 100644 --- a/src/dev/posix/hasp_posix.cpp +++ b/src/dev/posix/hasp_posix.cpp @@ -38,8 +38,9 @@ PosixDevice::PosixDevice() _hostname = uts.nodename; } - _backlight_power = 1; - _backlight_level = 100; + _backlight_power = 1; + _backlight_invert = 0; + _backlight_level = 100; } void PosixDevice::reboot() @@ -115,6 +116,7 @@ bool PosixDevice::get_backlight_power() void PosixDevice::update_backlight() { uint8_t level = _backlight_power ? _backlight_level : 0; + if(_backlight_invert) level = 255 - level; monitor_backlight(level); // SDL_SetTextureColorMod(monitor.texture, level, level, level); // window_update(&monitor); diff --git a/src/dev/posix/hasp_posix.h b/src/dev/posix/hasp_posix.h index 962bd45d..3a47edc8 100644 --- a/src/dev/posix/hasp_posix.h +++ b/src/dev/posix/hasp_posix.h @@ -60,6 +60,7 @@ class PosixDevice : public BaseDevice { uint8_t _backlight_pin; uint8_t _backlight_level; uint8_t _backlight_power; + uint8_t _backlight_invert; void update_backlight(); }; diff --git a/src/dev/stm32f4/stm32f4.h b/src/dev/stm32f4/stm32f4.h index 30513dc0..d9903f17 100644 --- a/src/dev/stm32f4/stm32f4.h +++ b/src/dev/stm32f4/stm32f4.h @@ -16,9 +16,10 @@ class Stm32f4Device : public BaseDevice { public: Stm32f4Device() { - _hostname = "plate"; - _backlight_power = 1; - _backlight_level = 100; + _hostname = "plate"; + _backlight_power = 1; + _backlight_invert = 0; + _backlight_level = 100; #ifdef TFT_BCKL _backlight_pin = TFT_BCKL; #else @@ -53,6 +54,7 @@ class Stm32f4Device : public BaseDevice { uint8_t _backlight_pin; uint8_t _backlight_level; uint8_t _backlight_power; + uint8_t _backlight_invert; void update_backlight(); }; diff --git a/src/dev/win32/hasp_win32.cpp b/src/dev/win32/hasp_win32.cpp index 47733d63..b6389d52 100644 --- a/src/dev/win32/hasp_win32.cpp +++ b/src/dev/win32/hasp_win32.cpp @@ -95,6 +95,7 @@ bool Win32Device::get_backlight_power() void Win32Device::update_backlight() { uint8_t level = _backlight_power ? _backlight_level : 0; + if(_backlight_invert) level = 255 - level; monitor_backlight(level); } diff --git a/src/dev/win32/hasp_win32.h b/src/dev/win32/hasp_win32.h index 7aaa9ae3..67a727b1 100644 --- a/src/dev/win32/hasp_win32.h +++ b/src/dev/win32/hasp_win32.h @@ -47,8 +47,9 @@ class Win32Device : public BaseDevice { _core_version = version; // _backlight_pin = -1; - _backlight_power = 1; - _backlight_level = 100; + _backlight_power = 1; + _backlight_invert = 0; + _backlight_level = 255; } void reboot() override; @@ -79,6 +80,7 @@ class Win32Device : public BaseDevice { uint8_t _backlight_pin; uint8_t _backlight_level; uint8_t _backlight_power; + uint8_t _backlight_invert; void update_backlight(); };