Author: Jean-François Milants <jf@codingfield.com>
Brightness management in DisplayApp : do not allow the brightness level OFF when loading app and going to running mode. Such issue could occur in case of inconsistent or corrupted settings.
src/displayapp/DisplayApp.cpp | 17 +++++++++++++---- src/displayapp/DisplayApp.h | 1 +
diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index aa2c037e3fc33da4b27c9656494f7a28f3ab3a05..85c6da3e541ca1d874d1c370b840efe9cc9e804a 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -127,7 +127,7 @@ } void DisplayApp::InitHw() { brightnessController.Init(); - brightnessController.Set(settingsController.GetBrightness()); + ApplyBrightness(); } void DisplayApp::Refresh() { @@ -158,7 +158,7 @@ case Messages::DimScreen: brightnessController.Set(Controllers::BrightnessController::Levels::Low); break; case Messages::RestoreBrightness: - brightnessController.Set(settingsController.GetBrightness()); + ApplyBrightness(); break; case Messages::GoToSleep: while (brightnessController.Level() != Controllers::BrightnessController::Levels::Off) { @@ -169,7 +169,7 @@ PushMessageToSystemTask(Pinetime::System::Messages::OnDisplayTaskSleeping); state = States::Idle; break; case Messages::GoToRunning: - brightnessController.Set(settingsController.GetBrightness()); + ApplyBrightness(); state = States::Running; break; case Messages::UpdateTimeOut: @@ -303,7 +303,7 @@ } void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) { touchHandler.CancelTap(); - brightnessController.Set(settingsController.GetBrightness()); + ApplyBrightness(); currentScreen.reset(nullptr); SetFullRefresh(direction); @@ -530,3 +530,12 @@ void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) { this->systemTask = systemTask; } +void DisplayApp::ApplyBrightness() { + auto brightness = settingsController.GetBrightness(); + if(brightness != Controllers::BrightnessController::Levels::Low && + brightness != Controllers::BrightnessController::Levels::Medium && + brightness != Controllers::BrightnessController::Levels::High) { + brightness = Controllers::BrightnessController::Levels::High; + } + brightnessController.Set(brightness); +} diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index ae605114ec377047acbb3670a61d5fb814621e15..4c54e2273966042d31c2cc4ffd2c51d4169e48e9 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -121,6 +121,7 @@ Apps nextApp = Apps::None; DisplayApp::FullRefreshDirections nextDirection; System::BootErrors bootError; + void ApplyBrightness(); }; } }