From 0b2a4c4a9d2193b7630915d677989a80cfafdfd5 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Sun, 1 Mar 2020 09:58:50 +0100 Subject: [PATCH] Add backlight control --- src/hasp_gui.cpp | 10 +++++----- src/hasp_gui.h | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/hasp_gui.cpp b/src/hasp_gui.cpp index 8a4c6d78..82620f20 100644 --- a/src/hasp_gui.cpp +++ b/src/hasp_gui.cpp @@ -272,7 +272,7 @@ void guiSetup(TFT_eSPI & screen, JsonObject settings) tft = screen; guiSetConfig(settings); - guiBacklightIsOn = guiDimLevel > 0; + // guiBacklightIsOn = guiDimLevel > 0; tft.begin(); /* TFT init */ tft.setTouch(calData); @@ -406,7 +406,7 @@ void IRAM_ATTR guiLoop() void guiStop() {} -bool guiGetBacklight(bool lighton) +bool guiGetBacklight() { return guiBacklightIsOn; } @@ -418,9 +418,9 @@ void guiSetBacklight(bool lighton) if(guiBacklightPin >= 0) { #if defined(ARDUINO_ARCH_ESP32) - ledcWrite(99, lighton ? 1023 : 0); // ledChannel and value + ledcWrite(99, lighton ? map(guiDimLevel, 0, 100, 0, 1023) : 0); // ledChannel and value #else - analogWrite(guiBacklightPin, lighton ? 1023 : 0); + analogWrite(guiBacklightPin, lighton ? map(guiDimLevel, 0, 100, 0, 1023) : 0); #endif } else { @@ -434,7 +434,7 @@ void guiSetDim(uint8_t level) guiDimLevel = level >= 0 ? level : 0; guiDimLevel = guiDimLevel <= 100 ? guiDimLevel : 100; - if(true || guiBacklightIsOn) { // The backlight is ON + if(guiBacklightIsOn) { // The backlight is ON #if defined(ARDUINO_ARCH_ESP32) ledcWrite(99, map(guiDimLevel, 0, 100, 0, 1023)); // ledChannel and value #else diff --git a/src/hasp_gui.h b/src/hasp_gui.h index cdbe5a2b..d40bc61a 100644 --- a/src/hasp_gui.h +++ b/src/hasp_gui.h @@ -25,6 +25,8 @@ void guiTakeScreenshot(const char * pFileName); void guiSetDim(uint8_t level); int8_t guiGetDim(void); +void guiSetBacklight(bool lighton); +bool guiGetBacklight(); bool guiGetConfig(const JsonObject & settings); bool guiSetConfig(const JsonObject & settings);