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.

This commit is contained in:
Jean-François Milants 2022-10-02 18:04:09 +02:00
parent 60abbf0639
commit c9b1fb8244
2 changed files with 14 additions and 4 deletions

View File

@ -127,7 +127,7 @@ void DisplayApp::Process(void* instance) {
void DisplayApp::InitHw() { void DisplayApp::InitHw() {
brightnessController.Init(); brightnessController.Init();
brightnessController.Set(settingsController.GetBrightness()); ApplyBrightness();
} }
void DisplayApp::Refresh() { void DisplayApp::Refresh() {
@ -158,7 +158,7 @@ void DisplayApp::Refresh() {
brightnessController.Set(Controllers::BrightnessController::Levels::Low); brightnessController.Set(Controllers::BrightnessController::Levels::Low);
break; break;
case Messages::RestoreBrightness: case Messages::RestoreBrightness:
brightnessController.Set(settingsController.GetBrightness()); ApplyBrightness();
break; break;
case Messages::GoToSleep: case Messages::GoToSleep:
while (brightnessController.Level() != Controllers::BrightnessController::Levels::Off) { while (brightnessController.Level() != Controllers::BrightnessController::Levels::Off) {
@ -169,7 +169,7 @@ void DisplayApp::Refresh() {
state = States::Idle; state = States::Idle;
break; break;
case Messages::GoToRunning: case Messages::GoToRunning:
brightnessController.Set(settingsController.GetBrightness()); ApplyBrightness();
state = States::Running; state = States::Running;
break; break;
case Messages::UpdateTimeOut: case Messages::UpdateTimeOut:
@ -303,7 +303,7 @@ void DisplayApp::ReturnApp(Apps app, DisplayApp::FullRefreshDirections direction
void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) { void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) {
touchHandler.CancelTap(); touchHandler.CancelTap();
brightnessController.Set(settingsController.GetBrightness()); ApplyBrightness();
currentScreen.reset(nullptr); currentScreen.reset(nullptr);
SetFullRefresh(direction); SetFullRefresh(direction);
@ -530,3 +530,12 @@ void DisplayApp::PushMessageToSystemTask(Pinetime::System::Messages message) {
void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) { void DisplayApp::Register(Pinetime::System::SystemTask* systemTask) {
this->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);
}

View File

@ -121,6 +121,7 @@ namespace Pinetime {
Apps nextApp = Apps::None; Apps nextApp = Apps::None;
DisplayApp::FullRefreshDirections nextDirection; DisplayApp::FullRefreshDirections nextDirection;
System::BootErrors bootError; System::BootErrors bootError;
void ApplyBrightness();
}; };
} }
} }