diff --git a/Platformio/HAL/Targets/ESP32/display/display.cpp b/Platformio/HAL/Targets/ESP32/display/display.cpp index d5e5d1c..854acdd 100644 --- a/Platformio/HAL/Targets/ESP32/display/display.cpp +++ b/Platformio/HAL/Targets/ESP32/display/display.cpp @@ -7,7 +7,7 @@ std::shared_ptr Display::getInstance() { if (DisplayAbstract::mInstance == nullptr) { - DisplayAbstract::mInstance = std::shared_ptr(new Display(LCD_EN, LCD_BL)); + DisplayAbstract::mInstance = std::shared_ptr(new Display(LCD_BL, LCD_EN)); } return std::static_pointer_cast(mInstance); } @@ -38,6 +38,8 @@ Display::Display(int backlight_pin, int enable_pin): DisplayAbstract(), } setupTouchScreen(); + mFadeTaskMutex = xSemaphoreCreateBinary(); + xSemaphoreGive(mFadeTaskMutex); } void Display::onTouch(Notification::HandlerTy aTouchHandler){ @@ -61,6 +63,8 @@ void Display::setupTouchScreen(){ void Display::setBrightness(uint8_t brightness) { mAwakeBrightness = brightness; + Serial.print("Set Brightness:"); + Serial.println(mAwakeBrightness); startFade(); } @@ -70,7 +74,10 @@ uint8_t Display::getBrightness(){ void Display::setCurrentBrightness(uint8_t brightness){ mBrightness = brightness; - ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, mBrightness); + auto duty = abs(255 - static_cast(mBrightness)); + ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, duty); + Serial.print("Current Brightness:"); + Serial.println(mBrightness); } void Display::turnOff() @@ -119,8 +126,12 @@ void Display::fadeImpl(void* ){ vTaskDelay(3 / portTICK_PERIOD_MS); // 3 miliseconds between steps // 0 - 255 will take about .75 seconds to fade up. } - vTaskDelete(getInstance()->mDisplayFadeTask); + + xSemaphoreTake(getInstance()->mFadeTaskMutex,portMAX_DELAY); getInstance()->mDisplayFadeTask = nullptr; + xSemaphoreGive(getInstance()->mFadeTaskMutex); + + vTaskDelete(nullptr); // Delete Fade Task } bool Display::fade(){ @@ -140,10 +151,13 @@ bool Display::fade(){ } void Display::startFade(){ - if(mDisplayFadeTask != nullptr){// Already have fade task no need to start another. + xSemaphoreTake(mFadeTaskMutex,portMAX_DELAY); + // Only Create Task if it is needed + if(mDisplayFadeTask == nullptr){ xTaskCreate(&Display::fadeImpl, "Display Fade Task", 1024, nullptr, 5, &mDisplayFadeTask); } + xSemaphoreGive(mFadeTaskMutex); } void Display::flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) { diff --git a/Platformio/HAL/Targets/ESP32/display/display.hpp b/Platformio/HAL/Targets/ESP32/display/display.hpp index e4e0bdf..51b29d7 100644 --- a/Platformio/HAL/Targets/ESP32/display/display.hpp +++ b/Platformio/HAL/Targets/ESP32/display/display.hpp @@ -63,6 +63,7 @@ class Display: public DisplayAbstract Notification mTouchEvent; TaskHandle_t mDisplayFadeTask = nullptr; + SemaphoreHandle_t mFadeTaskMutex = nullptr; static void fadeImpl(void* aBrightness); uint8_t mBrightness = 0; // Current display brightness diff --git a/Platformio/OmoteUI/displaySettings.cpp b/Platformio/OmoteUI/displaySettings.cpp index 6588334..2f9dd39 100644 --- a/Platformio/OmoteUI/displaySettings.cpp +++ b/Platformio/OmoteUI/displaySettings.cpp @@ -14,7 +14,7 @@ void OmoteUI::display_settings(lv_obj_t* parent) lv_obj_t* brightnessIcon = imgs.addLowBrightnessIcon(menuBox); lv_obj_align(brightnessIcon, LV_ALIGN_TOP_LEFT, 0, 0); lv_obj_t* slider = lv_slider_create(menuBox); - lv_slider_set_range(slider, 30, 255); + lv_slider_set_range(slider, 0, 255); lv_obj_set_style_bg_color(slider, lv_color_white(), LV_PART_KNOB); lv_obj_set_style_bg_opa(slider, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_bg_color(slider, lv_color_lighten(color_primary, 50), LV_PART_MAIN);