diff options
| author | Michele Bini <michele.bini@gmail.com> | 2022-03-27 10:44:47 (GMT) |
|---|---|---|
| committer | Michele Bini <michele.bini@gmail.com> | 2022-03-27 10:52:52 (GMT) |
| commit | fa38eb8721d159623a344abae2bb510417b2f7a6 (patch) | |
| tree | 5fedd399e4b5c4823608d316e9fce763bfdf5e6e | |
| parent | 06fc04bcb3b0993c0b1ff2a13848e62b0eaeb529 (diff) | |
Adding back chimes and torch
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/components/settings/Settings.h | 14 | ||||
| -rw-r--r-- | src/displayapp/Apps.h | 2 | ||||
| -rw-r--r-- | src/displayapp/DisplayApp.cpp | 10 | ||||
| -rw-r--r-- | src/displayapp/screens/FlashLight.cpp | 134 | ||||
| -rw-r--r-- | src/displayapp/screens/FlashLight.h | 38 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/QuickSettings.cpp | 4 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/SettingChimes.cpp | 100 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/SettingChimes.h | 27 | ||||
| -rw-r--r-- | src/displayapp/screens/settings/Settings.cpp | 2 | ||||
| -rw-r--r-- | src/systemtask/SystemTask.cpp | 16 |
11 files changed, 347 insertions, 2 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 921bcf4..c1bb32f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -396,6 +396,7 @@ list(APPEND SOURCE_FILES displayapp/screens/FirmwareValidation.cpp displayapp/screens/ApplicationList.cpp displayapp/screens/Notifications.cpp + displayapp/screens/FlashLight.cpp displayapp/screens/List.cpp displayapp/screens/Error.cpp displayapp/screens/Styles.cpp @@ -407,6 +408,7 @@ list(APPEND SOURCE_FILES displayapp/screens/settings/SettingTimeFormat.cpp displayapp/screens/settings/SettingWakeUp.cpp displayapp/screens/settings/SettingDisplay.cpp + displayapp/screens/settings/SettingChimes.cpp ## Watch faces displayapp/screens/WatchFaceDigital.cpp diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 5201b77..fb7f598 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -9,6 +9,7 @@ namespace Pinetime { public: enum class ClockType : uint8_t { H24, H12 }; enum class Notification : uint8_t { ON, OFF }; + enum class ChimesOption : uint8_t { None, Hours, HalfHours }; enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, @@ -49,6 +50,16 @@ namespace Pinetime { return settings.clockFace; }; + void SetChimeOption(ChimesOption chimeOption) { + if (chimeOption != settings.chimesOption) { + settingsChanged = true; + } + settings.chimesOption = chimeOption; + }; + ChimesOption GetChimeOption() const { + return settings.chimesOption; + }; + void SetAppMenu(uint8_t menu) { appMenu = menu; }; @@ -135,7 +146,7 @@ namespace Pinetime { }; private: - static constexpr uint32_t settingsVersion = 0x4021; // infinitime redux settings + static constexpr uint32_t settingsVersion = 0x4031; // infinitime redux settings struct SettingsData { uint32_t version = settingsVersion; uint32_t screenTimeOut = 15000; @@ -144,6 +155,7 @@ namespace Pinetime { Notification notificationStatus = Notification::ON; uint8_t clockFace = 0; + ChimesOption chimesOption = ChimesOption::None; std::bitset<4> wakeUpMode {0}; Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; diff --git a/src/displayapp/Apps.h b/src/displayapp/Apps.h index c308c75..3cbaa9e 100644 --- a/src/displayapp/Apps.h +++ b/src/displayapp/Apps.h @@ -10,11 +10,13 @@ namespace Pinetime { FirmwareValidation, NotificationsPreview, Notifications, + FlashLight, QuickSettings, Settings, SettingTimeFormat, SettingDisplay, SettingWakeUp, + SettingChimes, Error }; } diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 155d69a..9219472 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -13,6 +13,7 @@ #include "displayapp/screens/FirmwareValidation.h" #include "displayapp/screens/Notifications.h" #include "displayapp/screens/Tile.h" +#include "displayapp/screens/FlashLight.h" #include "displayapp/screens/Error.h" #include "drivers/Cst816s.h" @@ -26,6 +27,7 @@ #include "displayapp/screens/settings/SettingTimeFormat.h" #include "displayapp/screens/settings/SettingWakeUp.h" #include "displayapp/screens/settings/SettingDisplay.h" +#include "displayapp/screens/settings/SettingChimes.h" #include "libs/lv_conf.h" @@ -345,6 +347,14 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) currentScreen = std::make_unique<Screens::SettingDisplay>(this, settingsController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; + case Apps::SettingChimes: + currentScreen = std::make_unique<Screens::SettingChimes>(this, settingsController); + ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); + break; + case Apps::FlashLight: + currentScreen = std::make_unique<Screens::FlashLight>(this, *systemTask, brightnessController); + ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown); + break; } currentApp = app; } diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp new file mode 100644 index 0000000..c4d0264 --- /dev/null +++ b/src/displayapp/screens/FlashLight.cpp @@ -0,0 +1,134 @@ +#include "displayapp/screens/FlashLight.h" +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Symbols.h" + +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); + } +} + +FlashLight::FlashLight(Pinetime::Applications::DisplayApp* app, + System::SystemTask& systemTask, + Controllers::BrightnessController& brightnessController) + : Screen(app), + systemTask {systemTask}, + brightnessController {brightnessController} + +{ + brightnessController.Backup(); + + brightnessLevel = brightnessController.Level(); + + 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); + lv_label_set_text_static(flashLight, Symbols::highlight); + lv_obj_align(flashLight, nullptr, LV_ALIGN_CENTER, 0, 0); + + for (auto & i : indicators) { + i = lv_obj_create(lv_scr_act(), nullptr); + lv_obj_set_size(i, 15, 10); + lv_obj_set_style_local_border_width(i, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 2); + } + + lv_obj_align(indicators[1], flashLight, LV_ALIGN_OUT_BOTTOM_MID, 0, 5); + 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(); + SetColors(); + + 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_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) { + lv_obj_set_state(indicators[1], LV_STATE_DEFAULT); + lv_obj_set_state(indicators[2], LV_STATE_DEFAULT); + } else if (brightnessLevel == 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); + } +} + +void FlashLight::OnClickEvent(lv_obj_t* obj, lv_event_t event) { + if (obj == backgroundAction && event == LV_EVENT_CLICKED) { + isOn = !isOn; + SetColors(); + } +} + +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(); + } + 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(); + } + return true; + } + + return false; +} diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h new file mode 100644 index 0000000..e91a103 --- /dev/null +++ b/src/displayapp/screens/FlashLight.h @@ -0,0 +1,38 @@ +#pragma once + +#include "displayapp/screens/Screen.h" +#include "components/brightness/BrightnessController.h" +#include "systemtask/SystemTask.h" +#include <cstdint> +#include <lvgl/lvgl.h> + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class FlashLight : public Screen { + public: + FlashLight(DisplayApp* app, System::SystemTask& systemTask, 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(); + + Pinetime::System::SystemTask& systemTask; + Controllers::BrightnessController& brightnessController; + + Controllers::BrightnessController::Levels brightnessLevel; + + lv_obj_t* flashLight; + lv_obj_t* backgroundAction; + lv_obj_t* indicators[3]; + bool isOn = false; + }; + } + } +} diff --git a/src/displayapp/screens/settings/QuickSettings.cpp b/src/displayapp/screens/settings/QuickSettings.cpp index c00518e..cd56c14 100644 --- a/src/displayapp/screens/settings/QuickSettings.cpp +++ b/src/displayapp/screens/settings/QuickSettings.cpp @@ -129,6 +129,10 @@ void QuickSettings::UpdateScreen() { void QuickSettings::OnButtonEvent(lv_obj_t* object, lv_event_t event) { if (object == btn2 && event == LV_EVENT_CLICKED) { + + running = false; + app->StartApp(Apps::FlashLight, DisplayApp::FullRefreshDirections::Up); + } else if (object == btn1 && event == LV_EVENT_CLICKED) { brightness.Step(); diff --git a/src/displayapp/screens/settings/SettingChimes.cpp b/src/displayapp/screens/settings/SettingChimes.cpp new file mode 100644 index 0000000..543b5e0 --- /dev/null +++ b/src/displayapp/screens/settings/SettingChimes.cpp @@ -0,0 +1,100 @@ +#include "displayapp/screens/settings/SettingChimes.h" +#include <lvgl/lvgl.h> +#include "displayapp/DisplayApp.h" +#include "displayapp/screens/Styles.h" +#include "displayapp/screens/Screen.h" +#include "displayapp/screens/Symbols.h" + +using namespace Pinetime::Applications::Screens; + +namespace { + static void event_handler(lv_obj_t* obj, lv_event_t event) { + SettingChimes* screen = static_cast<SettingChimes*>(obj->user_data); + screen->UpdateSelected(obj, event); + } +} + +SettingChimes::SettingChimes(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, "Chimes"); + 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::clock); + 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], " Off"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + SetRadioButtonStyle(cbOption[optionsTotal]); + if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::None) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + + optionsTotal++; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Every hour"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + SetRadioButtonStyle(cbOption[optionsTotal]); + if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + + optionsTotal++; + cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Every 30 mins"); + cbOption[optionsTotal]->user_data = this; + lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); + SetRadioButtonStyle(cbOption[optionsTotal]); + if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours) { + lv_checkbox_set_checked(cbOption[optionsTotal], true); + } + + optionsTotal++; +} + +SettingChimes::~SettingChimes() { + lv_obj_clean(lv_scr_act()); + settingsController.SaveSettings(); +} + +void SettingChimes::UpdateSelected(lv_obj_t* object, lv_event_t event) { + if (event == LV_EVENT_VALUE_CHANGED) { + for (uint8_t i = 0; i < optionsTotal; i++) { + if (object == cbOption[i]) { + lv_checkbox_set_checked(cbOption[i], true); + if (i == 0) { + settingsController.SetChimeOption(Controllers::Settings::ChimesOption::None); + } + if (i == 1) { + settingsController.SetChimeOption(Controllers::Settings::ChimesOption::Hours); + } + if (i == 2) { + settingsController.SetChimeOption(Controllers::Settings::ChimesOption::HalfHours); + } + } else { + lv_checkbox_set_checked(cbOption[i], false); + } + } + } +} diff --git a/src/displayapp/screens/settings/SettingChimes.h b/src/displayapp/screens/settings/SettingChimes.h new file mode 100644 index 0000000..a251e95 --- /dev/null +++ b/src/displayapp/screens/settings/SettingChimes.h @@ -0,0 +1,27 @@ +#pragma once + +#include <cstdint> +#include <lvgl/lvgl.h> +#include "components/settings/Settings.h" +#include "displayapp/screens/Screen.h" + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class SettingChimes : public Screen { + public: + SettingChimes(DisplayApp* app, Pinetime::Controllers::Settings& settingsController); + ~SettingChimes() override; + + void UpdateSelected(lv_obj_t* object, lv_event_t event); + + private: + Controllers::Settings& settingsController; + uint8_t optionsTotal; + lv_obj_t* cbOption[3]; + }; + } + } +} diff --git a/src/displayapp/screens/settings/Settings.cpp b/src/displayapp/screens/settings/Settings.cpp index 3d257ae..9e19d20 100644 --- a/src/displayapp/screens/settings/Settings.cpp +++ b/src/displayapp/screens/settings/Settings.cpp @@ -37,7 +37,7 @@ std::unique_ptr<Screen> Settings::CreateScreen1() { {Symbols::sun, "Display", Apps::SettingDisplay}, {Symbols::eye, "Wake Up", Apps::SettingWakeUp}, {Symbols::clock, "Time format", Apps::SettingTimeFormat}, - {Symbols::none, "None", Apps::None} + {Symbols::clock, "Chimes", Apps::SettingChimes}, }}; return std::make_unique<Screens::List>(0, 1, app, settingsController, applications); diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 8f76d8e..855513e 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -343,8 +343,24 @@ void SystemTask::Work() { stepCounterMustBeReset = true; break; case Messages::OnNewHour: + using Pinetime::Controllers::AlarmController; + if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours) { + if (isSleeping && !isWakingUp) { + GoToRunning(); + displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); + } + motorController.RunForDuration(35); + } break; case Messages::OnNewHalfHour: + using Pinetime::Controllers::AlarmController; + if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours) { + if (isSleeping && !isWakingUp) { + GoToRunning(); + displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); + } + motorController.RunForDuration(35); + } break; case Messages::OnChargingEvent: batteryController.ReadPowerState(); |
