diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-04-11 08:44:42 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-04-11 08:44:42 (GMT) |
| commit | eb821c286288dfbabf9a0877814a209fb59a8ca3 (patch) | |
| tree | d101e8dfdde8950669bbf0c82fac69dc4786f2aa | |
| parent | bc01efe95ab26ba579f28d98811c46001f43c5ca (diff) | |
Flashlight starts on at full brightness; to save energy use backed-up brightness when flashlight is off
| -rw-r--r-- | src/displayapp/screens/FlashLight.cpp | 97 | ||||
| -rw-r--r-- | src/displayapp/screens/FlashLight.h | 7 |
2 files changed, 46 insertions, 58 deletions
diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp index 266e089..3493381 100644 --- a/src/displayapp/screens/FlashLight.cpp +++ b/src/displayapp/screens/FlashLight.cpp @@ -10,8 +10,9 @@ namespace { screen->OnClickEvent(obj, event); } - Pinetime::Controllers::BrightnessController::Levels brightnessLevel = Pinetime::Controllers::BrightnessController::Levels::High; + typedef Pinetime::Controllers::BrightnessController::Levels Levels; + Levels brightnessLevel = Levels::High; } FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, @@ -22,8 +23,7 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, brightnessController {brightnessController} { - brightnessController.Backup(); - + systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping); flashLight = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont2); @@ -40,10 +40,7 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, lv_obj_align(indicators[0], indicators[1], LV_ALIGN_OUT_LEFT_MID, -8, 0); lv_obj_align(indicators[2], indicators[1], LV_ALIGN_OUT_RIGHT_MID, 8, 0); - SetIndicators(); - // brightnessLevel = brightnessController.Level(); - brightnessController.Set(brightnessLevel); - SetColors(); + Update(true, brightnessLevel); backgroundAction = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(backgroundAction, LV_LABEL_LONG_CROP); @@ -53,56 +50,59 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, lv_obj_set_click(backgroundAction, true); backgroundAction->user_data = this; lv_obj_set_event_cb(backgroundAction, event_handler); - - systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping); } FlashLight::~FlashLight() { + Update(false, brightnessLevel); lv_obj_clean(lv_scr_act()); - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); - brightnessController.Restore(); systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping); } -void FlashLight::SetColors() { - if (isOn) { - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); - for (auto & i : indicators) { - lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); - lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_WHITE); - lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); - } - } else { - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - for (auto & i : indicators) { - lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_BLACK); - lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); - } - } -} - -void FlashLight::SetIndicators() { - using namespace Pinetime::Controllers; - - if (brightnessLevel == BrightnessController::Levels::High) { +void FlashLight::Update(bool on, Controllers::BrightnessController::Levels level) { + brightnessLevel = level; + + if (brightnessLevel == Controllers::BrightnessController::Levels::High) { lv_obj_set_state(indicators[1], LV_STATE_DEFAULT); lv_obj_set_state(indicators[2], LV_STATE_DEFAULT); - } else if (brightnessLevel == BrightnessController::Levels::Medium) { + } else if (brightnessLevel == Controllers::BrightnessController::Levels::Medium) { lv_obj_set_state(indicators[1], LV_STATE_DEFAULT); lv_obj_set_state(indicators[2], LV_STATE_DISABLED); } else { lv_obj_set_state(indicators[1], LV_STATE_DISABLED); lv_obj_set_state(indicators[2], LV_STATE_DISABLED); } + + if (on != isOn) { + isOn = on; + if (isOn) { + brightnessController.Backup(); + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + for (auto & i : indicators) { + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_WHITE); + lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); + } + } else { + brightnessController.Restore(); + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + for (auto & i : indicators) { + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + lv_obj_set_style_local_bg_color(i, LV_OBJ_PART_MAIN, LV_STATE_DISABLED, LV_COLOR_BLACK); + lv_obj_set_style_local_border_color(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE); + } + } + } + + if (isOn) { + brightnessController.Set(brightnessLevel); + } } void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) { if (obj == backgroundAction && event == LV_EVENT_CLICKED) { - isOn = !isOn; - SetColors(); + Update(!isOn, brightnessLevel); } } @@ -110,26 +110,15 @@ bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { using namespace Pinetime::Controllers; if (event == TouchEvents::SwipeLeft) { - if (brightnessLevel == BrightnessController::Levels::High) { - brightnessLevel = BrightnessController::Levels::Medium; - brightnessController.Set(brightnessLevel); - SetIndicators(); - } else if (brightnessLevel == BrightnessController::Levels::Medium) { - brightnessLevel = BrightnessController::Levels::Low; - brightnessController.Set(brightnessLevel); - SetIndicators(); + if (brightnessLevel >= Levels::Medium) { + Update(isOn, static_cast<Levels>( static_cast< std::underlying_type_t<Levels> >(brightnessLevel) - 1) ); } return true; } + if (event == TouchEvents::SwipeRight) { - if (brightnessLevel == BrightnessController::Levels::Low) { - brightnessLevel = BrightnessController::Levels::Medium; - brightnessController.Set(brightnessLevel); - SetIndicators(); - } else if (brightnessLevel == BrightnessController::Levels::Medium) { - brightnessLevel = BrightnessController::Levels::High; - brightnessController.Set(brightnessLevel); - SetIndicators(); + if (brightnessLevel <= Levels::Medium) { + Update(isOn, static_cast<Levels>( static_cast< std::underlying_type_t<Levels> >(brightnessLevel) + 1) ); } return true; } diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h index ebc69f7..8021197 100644 --- a/src/displayapp/screens/FlashLight.h +++ b/src/displayapp/screens/FlashLight.h @@ -13,15 +13,14 @@ namespace Pinetime { class FlashLight : public Screen { public: - FlashLight(DisplayApp* app, System::SystemTask& systemTask, Controllers::BrightnessController& brightness); + FlashLight(DisplayApp* app, System::SystemTask& systemTask, Pinetime::Controllers::BrightnessController& brightness); ~FlashLight() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; void OnClickEvent(lv_obj_t* obj, lv_event_t event); private: - void SetIndicators(); - void SetColors(); + void Update(bool on, Pinetime::Controllers::BrightnessController::Levels level); Pinetime::System::SystemTask& systemTask; Controllers::BrightnessController& brightnessController; @@ -29,7 +28,7 @@ namespace Pinetime { lv_obj_t* flashLight; lv_obj_t* backgroundAction; lv_obj_t* indicators[3]; - bool isOn = true; + bool isOn = false; }; } } |
