diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a7242903b8..9e05e35654 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -429,6 +429,7 @@ list(APPEND SOURCE_FILES displayapp/screens/settings/SettingDisplay.cpp displayapp/screens/settings/SettingSteps.cpp displayapp/screens/settings/SettingPineTimeStyle.cpp + displayapp/screens/settings/SettingFlashlight.cpp ## Watch faces displayapp/icons/bg_clock.c diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index a294ab7840..f941565cee 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -25,6 +25,9 @@ namespace Pinetime { Colors ColorBar = Colors::Teal; Colors ColorBG = Colors::Black; }; + struct FlashlightColor { + Colors ColorFlashlight = Colors::White; + }; Settings(Pinetime::Controllers::FS& fs); @@ -68,6 +71,15 @@ namespace Pinetime { return settings.PTS.ColorBG; }; + void SetFlashlightColor(Colors colorFlashlight) { + if (colorFlashlight != settings.Flash.ColorFlashlight) + settingsChanged = true; + settings.Flash.ColorFlashlight = colorFlashlight; + }; + Colors GetFlashlightColor() const { + return settings.Flash.ColorFlashlight; + }; + void SetAppMenu(uint8_t menu) { appMenu = menu; }; @@ -175,6 +187,7 @@ namespace Pinetime { uint8_t clockFace = 0; PineTimeStyle PTS; + FlashlightColor Flash; std::bitset<3> wakeUpMode {0}; diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index dd51fdb4a0..4026246279 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -31,7 +31,8 @@ namespace Pinetime { SettingDisplay, SettingWakeUp, SettingSteps, - SettingPineTimeStyle + SettingPineTimeStyle, + SettingFlashlight }; } } diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index d6100ececd..75e59fe265 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -43,6 +43,7 @@ #include "displayapp/screens/settings/SettingDisplay.h" #include "displayapp/screens/settings/SettingSteps.h" #include "displayapp/screens/settings/SettingPineTimeStyle.h" +#include "displayapp/screens/settings/SettingFlashlight.h" #include "libs/lv_conf.h" @@ -375,6 +376,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique(this, settingsController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; + case Apps::SettingFlashlight: + currentScreen = std::make_unique(this, settingsController); + ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); + break; case Apps::BatteryInfo: currentScreen = std::make_unique(this, batteryController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); @@ -385,7 +390,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; case Apps::FlashLight: - currentScreen = std::make_unique(this, *systemTask, brightnessController); + currentScreen = std::make_unique(this, *systemTask, brightnessController, settingsController); ReturnApp(Apps::Clock, FullRefreshDirections::Down, TouchEvents::None); break; case Apps::StopWatch: diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp index 4bc5b558c2..e44e910dfc 100644 --- a/src/displayapp/screens/FlashLight.cpp +++ b/src/displayapp/screens/FlashLight.cpp @@ -1,6 +1,8 @@ #include "FlashLight.h" #include "../DisplayApp.h" #include "Symbols.h" +#include "components/settings/Settings.h" +#include using namespace Pinetime::Applications::Screens; @@ -13,16 +15,17 @@ namespace { FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, System::SystemTask& systemTask, - Controllers::BrightnessController& brightness) + Controllers::BrightnessController& brightness, + Controllers::Settings& settingsController) : Screen(app), systemTask {systemTask}, - brightness {brightness} + brightness {brightness}, + settingsController {settingsController} { -{ brightness.Backup(); brightness.Set(Controllers::BrightnessController::Levels::High); // Set the background - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetFlashlightColor())); flashLight = lv_label_create(lv_scr_act(), NULL); lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); @@ -55,11 +58,11 @@ void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) { isOn = !isOn; if (isOn) { - lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetFlashlightColor())); lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); } else { lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); - lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); + lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Convert(settingsController.GetFlashlightColor())); } } } diff --git a/src/displayapp/screens/FlashLight.cpp~ b/src/displayapp/screens/FlashLight.cpp~ new file mode 100644 index 0000000000..63b2345e3a --- /dev/null +++ b/src/displayapp/screens/FlashLight.cpp~ @@ -0,0 +1,74 @@ +#include "FlashLight.h" +#include "../DisplayApp.h" +#include "Symbols.h" + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t* obj, lv_event_t event) { + FlashLight* screen = static_cast(obj->user_data); + screen->OnClickEvent(obj, event); + } +} + +FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, + System::SystemTask& systemTask, + Controllers::BrightnessController& brightness) + : Screen(app), + systemTask {systemTask}, + brightness {brightness} + +{ + brightness.Backup(); + brightness.Set(Controllers::BrightnessController::Levels::High); + // Set the background + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); + + flashLight = lv_label_create(lv_scr_act(), NULL); + lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); + lv_obj_set_style_local_text_font(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &lv_font_sys_48); + lv_label_set_text_static(flashLight, Symbols::highlight); + lv_obj_align(flashLight, NULL, LV_ALIGN_CENTER, 0, 0); + + backgroundAction = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_long_mode(backgroundAction, LV_LABEL_LONG_CROP); + lv_obj_set_size(backgroundAction, 240, 240); + lv_obj_set_pos(backgroundAction, 0, 0); + lv_label_set_text(backgroundAction, ""); + 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() { + 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_hex(0x000000)); + brightness.Restore(); + systemTask.PushMessage(Pinetime::System::Messages::EnableSleeping); +} + +void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) { + if (obj == backgroundAction) { + if (event == LV_EVENT_CLICKED) { + isOn = !isOn; + + if (isOn) { + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); + lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); + } else { + lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x000000)); + lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xFFFFFF)); + } + } + } +} + +bool FlashLight::Refresh() { + return running; +} + +bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + return false; +} diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h index 7f5ca6c5dc..b716e267ee 100644 --- a/src/displayapp/screens/FlashLight.h +++ b/src/displayapp/screens/FlashLight.h @@ -6,14 +6,22 @@ #include "systemtask/SystemTask.h" #include "components/brightness/BrightnessController.h" + namespace Pinetime { + namespace Controllers { + class Settings; + } + namespace Applications { namespace Screens { class FlashLight : public Screen { public: - FlashLight(DisplayApp* app, System::SystemTask& systemTask, Controllers::BrightnessController& brightness); + FlashLight(DisplayApp* app, + System::SystemTask& systemTask, + Controllers::BrightnessController& brightness, + Controllers::Settings& settingsController); ~FlashLight() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; @@ -22,6 +30,7 @@ namespace Pinetime { private: Pinetime::System::SystemTask& systemTask; Controllers::BrightnessController& brightness; + Controllers::Settings& settingsController; lv_obj_t* flashLight; lv_obj_t* backgroundAction; diff --git a/src/displayapp/screens/settings/SettingFlashlight.cpp b/src/displayapp/screens/settings/SettingFlashlight.cpp new file mode 100644 index 0000000000..80c7005d05 --- /dev/null +++ b/src/displayapp/screens/settings/SettingFlashlight.cpp @@ -0,0 +1,110 @@ +#include "SettingFlashlight.h" +#include +#include "displayapp/DisplayApp.h" +#include "displayapp/Messages.h" +#include "displayapp/screens/Screen.h" +#include "displayapp/screens/Symbols.h" +#include + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t* obj, lv_event_t event) { + SettingFlashlight* screen = static_cast(obj->user_data); + screen->UpdateSelected(obj, event); + } +} + +SettingFlashlight::SettingFlashlight(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController) + : Screen(app), settingsController {settingsController} { + + lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr); + + lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); + lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); + lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); + lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); + + lv_obj_set_pos(container1, 10, 60); + lv_obj_set_width(container1, LV_HOR_RES - 20); + lv_obj_set_height(container1, LV_VER_RES - 50); + lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); + + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); + lv_label_set_text_static(title, "Flashlight"); + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15); + + lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); + lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); + lv_label_set_text_static(icon, Symbols::highlight); + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); + + optionsTotal = 0; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " White"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + if (settingsController.GetFlashlightColor() == Pinetime::Controllers::Settings::Colors::White) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + optionsTotal++; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Red"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + if (settingsController.GetFlashlightColor() == Pinetime::Controllers::Settings::Colors::Red) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + optionsTotal++; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Green"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + if (settingsController.GetFlashlightColor() == Pinetime::Controllers::Settings::Colors::Green) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + optionsTotal++; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Blue"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + if (settingsController.GetFlashlightColor() == Pinetime::Controllers::Settings::Colors::Blue) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + optionsTotal++; +} + +SettingFlashlight::~SettingFlashlight() { + lv_obj_clean(lv_scr_act()); + settingsController.SaveSettings(); +} + +void SettingFlashlight::UpdateSelected(lv_obj_t* object, lv_event_t event) { + if (event == LV_EVENT_CLICKED) { + for (int i = 0; i < optionsTotal; i++) { + if (object == cbOption[i]) { + lv_checkbox_set_checked(cbOption[i], true); + + if (i == 0) { + settingsController.SetFlashlightColor(Pinetime::Controllers::Settings::Colors::White); + }; + if (i == 1) { + settingsController.SetFlashlightColor(Pinetime::Controllers::Settings::Colors::Red); + }; + if (i == 2) { + settingsController.SetFlashlightColor(Pinetime::Controllers::Settings::Colors::Green); + }; + if (i == 3) { + settingsController.SetFlashlightColor(Pinetime::Controllers::Settings::Colors::Blue); + }; + + app->PushMessage(Applications::Display::Messages::UpdateTimeOut); + + } else { + lv_checkbox_set_checked(cbOption[i], false); + } + } + } +} diff --git a/src/displayapp/screens/settings/SettingFlashlight.h b/src/displayapp/screens/settings/SettingFlashlight.h new file mode 100644 index 0000000000..4ea71e2049 --- /dev/null +++ b/src/displayapp/screens/settings/SettingFlashlight.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include "components/settings/Settings.h" +#include "displayapp/screens/Screen.h" +#include + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class SettingFlashlight : public Screen { + public: + SettingFlashlight(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); + ~SettingFlashlight() override; + + void UpdateSelected(lv_obj_t* object, lv_event_t event); + + private: + Controllers::Settings& settingsController; + uint8_t optionsTotal; + lv_obj_t* cbOption[4]; + }; + } + } +} diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index f82b03c1a1..b99719e78c 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -61,7 +61,7 @@ std::unique_ptr Settings::CreateScreen3() { std::array applications {{ {Symbols::paintbrush, "PTS Colors", Apps::SettingPineTimeStyle}, - {Symbols::none, "None", Apps::None}, + {Symbols::highlight, "Flashlight", Apps::SettingFlashlight}, {Symbols::none, "None", Apps::None}, {Symbols::none, "None", Apps::None}, }};