Flashlight default to max brightness and code cleanup

This commit is contained in:
Riku Isokoski 2022-06-13 23:51:05 +03:00 committed by JF
parent 2b2aefcf6a
commit 61c2d8dbc7
2 changed files with 12 additions and 12 deletions

View File

@ -5,9 +5,11 @@
using namespace Pinetime::Applications::Screens;
namespace {
void event_handler(lv_obj_t* obj, lv_event_t event) {
auto* screen = static_cast<FlashLight*>(obj->user_data);
screen->OnClickEvent(obj, event);
void EventHandler(lv_obj_t* obj, lv_event_t event) {
if (event == LV_EVENT_CLICKED) {
auto* screen = static_cast<FlashLight*>(obj->user_data);
screen->Toggle();
}
}
}
@ -16,7 +18,7 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
Controllers::BrightnessController& brightnessController)
: Screen(app), systemTask {systemTask}, brightnessController {brightnessController} {
brightnessLevel = brightnessController.Level();
brightnessController.Set(brightnessLevel);
flashLight = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48);
@ -43,7 +45,7 @@ FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app,
lv_label_set_text_static(backgroundAction, "");
lv_obj_set_click(backgroundAction, true);
backgroundAction->user_data = this;
lv_obj_set_event_cb(backgroundAction, event_handler);
lv_obj_set_event_cb(backgroundAction, EventHandler);
systemTask.PushMessage(Pinetime::System::Messages::DisableSleeping);
}
@ -89,11 +91,9 @@ void FlashLight::SetIndicators() {
}
}
void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) {
if (obj == backgroundAction && event == LV_EVENT_CLICKED) {
isOn = !isOn;
SetColors();
}
void FlashLight::Toggle() {
isOn = !isOn;
SetColors();
}
bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {

View File

@ -17,7 +17,7 @@ namespace Pinetime {
~FlashLight() override;
bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override;
void OnClickEvent(lv_obj_t* obj, lv_event_t event);
void Toggle();
private:
void SetIndicators();
@ -26,7 +26,7 @@ namespace Pinetime {
Pinetime::System::SystemTask& systemTask;
Controllers::BrightnessController& brightnessController;
Controllers::BrightnessController::Levels brightnessLevel;
Controllers::BrightnessController::Levels brightnessLevel = Controllers::BrightnessController::Levels::High;
lv_obj_t* flashLight;
lv_obj_t* backgroundAction;