Fix bug in Display fade code with mutexes
This commit is contained in:
parent
4a1eb8abfa
commit
6747c40df3
3 changed files with 20 additions and 5 deletions
|
@ -7,7 +7,7 @@ std::shared_ptr<Display> Display::getInstance()
|
||||||
{
|
{
|
||||||
if (DisplayAbstract::mInstance == nullptr)
|
if (DisplayAbstract::mInstance == nullptr)
|
||||||
{
|
{
|
||||||
DisplayAbstract::mInstance = std::shared_ptr<Display>(new Display(LCD_EN, LCD_BL));
|
DisplayAbstract::mInstance = std::shared_ptr<Display>(new Display(LCD_BL, LCD_EN));
|
||||||
}
|
}
|
||||||
return std::static_pointer_cast<Display>(mInstance);
|
return std::static_pointer_cast<Display>(mInstance);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ Display::Display(int backlight_pin, int enable_pin): DisplayAbstract(),
|
||||||
}
|
}
|
||||||
|
|
||||||
setupTouchScreen();
|
setupTouchScreen();
|
||||||
|
mFadeTaskMutex = xSemaphoreCreateBinary();
|
||||||
|
xSemaphoreGive(mFadeTaskMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::onTouch(Notification<TS_Point>::HandlerTy aTouchHandler){
|
void Display::onTouch(Notification<TS_Point>::HandlerTy aTouchHandler){
|
||||||
|
@ -61,6 +63,8 @@ void Display::setupTouchScreen(){
|
||||||
void Display::setBrightness(uint8_t brightness)
|
void Display::setBrightness(uint8_t brightness)
|
||||||
{
|
{
|
||||||
mAwakeBrightness = brightness;
|
mAwakeBrightness = brightness;
|
||||||
|
Serial.print("Set Brightness:");
|
||||||
|
Serial.println(mAwakeBrightness);
|
||||||
startFade();
|
startFade();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +74,10 @@ uint8_t Display::getBrightness(){
|
||||||
|
|
||||||
void Display::setCurrentBrightness(uint8_t brightness){
|
void Display::setCurrentBrightness(uint8_t brightness){
|
||||||
mBrightness = brightness;
|
mBrightness = brightness;
|
||||||
ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, mBrightness);
|
auto duty = abs(255 - static_cast<int>(mBrightness));
|
||||||
|
ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, duty);
|
||||||
|
Serial.print("Current Brightness:");
|
||||||
|
Serial.println(mBrightness);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::turnOff()
|
void Display::turnOff()
|
||||||
|
@ -119,8 +126,12 @@ void Display::fadeImpl(void* ){
|
||||||
vTaskDelay(3 / portTICK_PERIOD_MS); // 3 miliseconds between steps
|
vTaskDelay(3 / portTICK_PERIOD_MS); // 3 miliseconds between steps
|
||||||
// 0 - 255 will take about .75 seconds to fade up.
|
// 0 - 255 will take about .75 seconds to fade up.
|
||||||
}
|
}
|
||||||
vTaskDelete(getInstance()->mDisplayFadeTask);
|
|
||||||
|
xSemaphoreTake(getInstance()->mFadeTaskMutex,portMAX_DELAY);
|
||||||
getInstance()->mDisplayFadeTask = nullptr;
|
getInstance()->mDisplayFadeTask = nullptr;
|
||||||
|
xSemaphoreGive(getInstance()->mFadeTaskMutex);
|
||||||
|
|
||||||
|
vTaskDelete(nullptr); // Delete Fade Task
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Display::fade(){
|
bool Display::fade(){
|
||||||
|
@ -140,10 +151,13 @@ bool Display::fade(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::startFade(){
|
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",
|
xTaskCreate(&Display::fadeImpl, "Display Fade Task",
|
||||||
1024, nullptr, 5, &mDisplayFadeTask);
|
1024, nullptr, 5, &mDisplayFadeTask);
|
||||||
}
|
}
|
||||||
|
xSemaphoreGive(mFadeTaskMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Display::flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
|
void Display::flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) {
|
||||||
|
|
|
@ -63,6 +63,7 @@ class Display: public DisplayAbstract
|
||||||
Notification<TS_Point> mTouchEvent;
|
Notification<TS_Point> mTouchEvent;
|
||||||
|
|
||||||
TaskHandle_t mDisplayFadeTask = nullptr;
|
TaskHandle_t mDisplayFadeTask = nullptr;
|
||||||
|
SemaphoreHandle_t mFadeTaskMutex = nullptr;
|
||||||
static void fadeImpl(void* aBrightness);
|
static void fadeImpl(void* aBrightness);
|
||||||
|
|
||||||
uint8_t mBrightness = 0; // Current display brightness
|
uint8_t mBrightness = 0; // Current display brightness
|
||||||
|
|
|
@ -14,7 +14,7 @@ void OmoteUI::display_settings(lv_obj_t* parent)
|
||||||
lv_obj_t* brightnessIcon = imgs.addLowBrightnessIcon(menuBox);
|
lv_obj_t* brightnessIcon = imgs.addLowBrightnessIcon(menuBox);
|
||||||
lv_obj_align(brightnessIcon, LV_ALIGN_TOP_LEFT, 0, 0);
|
lv_obj_align(brightnessIcon, LV_ALIGN_TOP_LEFT, 0, 0);
|
||||||
lv_obj_t* slider = lv_slider_create(menuBox);
|
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_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_opa(slider, LV_OPA_COVER, LV_PART_MAIN);
|
||||||
lv_obj_set_style_bg_color(slider, lv_color_lighten(color_primary, 50), LV_PART_MAIN);
|
lv_obj_set_style_bg_color(slider, lv_color_lighten(color_primary, 50), LV_PART_MAIN);
|
||||||
|
|
Loading…
Add table
Reference in a new issue