From 06fc04bcb3b0993c0b1ff2a13848e62b0eaeb529 Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Sun, 27 Mar 2022 12:11:34 +0200 Subject: Show temperature reading diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 574f964..155d69a 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -296,7 +296,8 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) bleController, notificationManager, settingsController, - motionController); + motionController, + *systemTask); break; case Apps::Error: diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index f390eed..ab4cafd 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -9,6 +9,7 @@ #include "components/settings/Settings.h" #include "displayapp/DisplayApp.h" #include "displayapp/screens/WatchFaceDigital.h" +#include "systemtask/SystemTask.h" using namespace Pinetime::Applications::Screens; @@ -18,8 +19,10 @@ Clock::Clock(DisplayApp* app, Controllers::Ble& bleController, Controllers::NotificationManager& notificatioManager, Controllers::Settings& settingsController, - Controllers::MotionController& motionController) + Controllers::MotionController& motionController, + System::SystemTask& systemTask) : Screen(app), + systemTask {systemTask}, dateTimeController {dateTimeController}, batteryController {batteryController}, bleController {bleController}, @@ -56,6 +59,7 @@ std::unique_ptr Clock::WatchFaceDigitalScreen() { bleController, notificatioManager, settingsController, - motionController); + motionController, + systemTask); } diff --git a/src/displayapp/screens/Clock.h b/src/displayapp/screens/Clock.h index 8d1a5b2..5001dce 100644 --- a/src/displayapp/screens/Clock.h +++ b/src/displayapp/screens/Clock.h @@ -6,6 +6,7 @@ #include #include "displayapp/screens/Screen.h" #include "components/datetime/DateTimeController.h" +#include "systemtask/SystemTask.h" namespace Pinetime { namespace Controllers { @@ -26,12 +27,14 @@ namespace Pinetime { Controllers::Ble& bleController, Controllers::NotificationManager& notificatioManager, Controllers::Settings& settingsController, - Controllers::MotionController& motionController); + Controllers::MotionController& motionController, + System::SystemTask& systemTask); ~Clock() override; bool OnTouchEvent(TouchEvents event) override; bool OnButtonPushed() override; + System::SystemTask& systemTask; private: Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; diff --git a/src/displayapp/screens/WatchFaceDigital.cpp b/src/displayapp/screens/WatchFaceDigital.cpp index e33a403..0bb2bf6 100644 --- a/src/displayapp/screens/WatchFaceDigital.cpp +++ b/src/displayapp/screens/WatchFaceDigital.cpp @@ -21,8 +21,10 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, Controllers::Ble& bleController, Controllers::NotificationManager& notificatioManager, Controllers::Settings& settingsController, - Controllers::MotionController& motionController) + Controllers::MotionController& motionController, + System::SystemTask& systemTask) : Screen(app), + systemTask {systemTask}, currentDateTime {{}}, dateTimeController {dateTimeController}, batteryController {batteryController}, @@ -56,6 +58,12 @@ WatchFaceDigital::WatchFaceDigital(DisplayApp* app, lv_obj_set_style_local_text_color(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); lv_obj_set_style_local_text_font(label_date, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont2); + label_temp = lv_label_create(lv_scr_act(), nullptr); + lv_obj_align(label_temp, lv_scr_act(), LV_ALIGN_CENTER, 0, -60); + lv_obj_set_style_local_text_color( label_temp, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x999999)); + lv_obj_set_style_local_text_font( label_temp, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont1); + lv_label_set_text_fmt(label_temp, "T? [?,?]"); + label_time = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(label_time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &neofont3); @@ -111,6 +119,13 @@ void WatchFaceDigital::Refresh() { lv_label_set_text_static(notificationIcon, NotificationIcon::GetIcon(notificationState.Get())); } + // systemTask.motionSensor.RefreshTemperature(); + lv_label_set_text_fmt(label_temp, "T%d [%d,%d]", + ((int)(systemTask.motionSensor.temperature_last_read_value+23)), + ((int)(systemTask.motionSensor.temperature_last_result)), + ((int)(systemTask.motionSensor.temperature_read_counter)) + ); + currentDateTime = dateTimeController.CurrentDateTime(); if (currentDateTime.IsUpdated()) { diff --git a/src/displayapp/screens/WatchFaceDigital.h b/src/displayapp/screens/WatchFaceDigital.h index 572a783..770645d 100644 --- a/src/displayapp/screens/WatchFaceDigital.h +++ b/src/displayapp/screens/WatchFaceDigital.h @@ -7,6 +7,7 @@ #include "displayapp/screens/Screen.h" #include "components/datetime/DateTimeController.h" #include "components/ble/BleController.h" +#include "systemtask/SystemTask.h" namespace Pinetime { namespace Controllers { @@ -28,12 +29,14 @@ namespace Pinetime { Controllers::Ble& bleController, Controllers::NotificationManager& notificatioManager, Controllers::Settings& settingsController, - Controllers::MotionController& motionController); + Controllers::MotionController& motionController, + System::SystemTask& systemTask); ~WatchFaceDigital() override; void Refresh() override; private: + System::SystemTask& systemTask; uint8_t displayedHour = -1; uint8_t displayedMinute = -1; @@ -50,6 +53,7 @@ namespace Pinetime { DirtyValue stepCount {}; DirtyValue notificationState {}; + lv_obj_t* label_temp; lv_obj_t* label_time; lv_obj_t* label_time_ampm; lv_obj_t* label_date; diff --git a/src/drivers/Bma421.cpp b/src/drivers/Bma421.cpp index 2f60f42..c5d55cc 100644 --- a/src/drivers/Bma421.cpp +++ b/src/drivers/Bma421.cpp @@ -102,9 +102,7 @@ Bma421::Values Bma421::Process() { uint32_t steps = 0; bma423_step_counter_output(&steps, &bma); - int32_t temperature; - bma4_get_temperature(&temperature, BMA4_DEG, &bma); - temperature = temperature / 1000; + RefreshTemperature(); uint8_t activity = 0; bma423_activity_output(&activity, &bma); @@ -112,6 +110,19 @@ Bma421::Values Bma421::Process() { // X and Y axis are swapped because of the way the sensor is mounted in the PineTime return {steps, data.y, data.x, data.z}; } + +void Bma421::RefreshTemperature() { + // uint8_t temperature_last_read_value; + // uint8_t temperature_last_result; + // uint8_t temperature_read_counter; + uint8_t data[BMA4_TEMP_DATA_SIZE] = { 0 }; + temperature_last_result = bma4_read_regs(BMA4_TEMPERATURE_ADDR, data, BMA4_TEMP_DATA_SIZE, &bma); + if (temperature_last_result == BMA4_OK) { + temperature_last_read_value = data[BMA4_TEMP_BYTE]; + temperature_read_counter++; + } +} + bool Bma421::IsOk() const { return isOk; } diff --git a/src/drivers/Bma421.h b/src/drivers/Bma421.h index ace644b..1503acd 100644 --- a/src/drivers/Bma421.h +++ b/src/drivers/Bma421.h @@ -30,6 +30,11 @@ namespace Pinetime { Values Process(); void ResetStepCounter(); + void RefreshTemperature(); + uint8_t temperature_last_read_value; + uint8_t temperature_last_result; + uint8_t temperature_read_counter; + void Read(uint8_t registerAddress, uint8_t* buffer, size_t size); void Write(uint8_t registerAddress, const uint8_t* data, size_t size); diff --git a/src/systemtask/SystemTask.h b/src/systemtask/SystemTask.h index 600d13e..7104115 100644 --- a/src/systemtask/SystemTask.h +++ b/src/systemtask/SystemTask.h @@ -104,7 +104,9 @@ namespace Pinetime { Pinetime::Drivers::Watchdog& watchdog; Pinetime::Controllers::NotificationManager& notificationManager; Pinetime::Controllers::MotorController& motorController; + public: Pinetime::Drivers::Bma421& motionSensor; + private: Pinetime::Controllers::Settings& settingsController; Pinetime::Controllers::MotionController& motionController; -- cgit v0.10.2 From fa38eb8721d159623a344abae2bb510417b2f7a6 Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Sun, 27 Mar 2022 12:44:47 +0200 Subject: Adding back chimes and torch 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(this, settingsController); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; + case Apps::SettingChimes: + currentScreen = std::make_unique(this, settingsController); + ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); + break; + case Apps::FlashLight: + currentScreen = std::make_unique(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(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 +#include + +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 +#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(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 +#include +#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 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(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(); -- cgit v0.10.2 From 1434a3e01b53119dc221f558538cf9d48d841e8c Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Sun, 27 Mar 2022 12:57:03 +0200 Subject: Undocumented tweaks for chimes (12 minutes...) diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 3bfbdc7..8605176 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -89,12 +89,12 @@ void DateTime::UpdateTime(uint32_t systickCounter) { isHourAlreadyNotified = false; } - if ((minute == 0 || minute == 30) && !isHalfHourAlreadyNotified) { + if ((!(minute%12)) && !isHalfHourAlreadyNotified) { isHalfHourAlreadyNotified = true; if (systemTask != nullptr) { systemTask->PushMessage(System::Messages::OnNewHalfHour); } - } else if (minute != 0 && minute != 30) { + } else if (!!(minute%12)) { isHalfHourAlreadyNotified = false; } diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index 855513e..f357d61 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -349,7 +349,7 @@ void SystemTask::Work() { GoToRunning(); displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); } - motorController.RunForDuration(35); + motorController.RunForDuration(30); } break; case Messages::OnNewHalfHour: @@ -359,7 +359,7 @@ void SystemTask::Work() { GoToRunning(); displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); } - motorController.RunForDuration(35); + motorController.RunForDuration(10); } break; case Messages::OnChargingEvent: -- cgit v0.10.2 From 2fb00c8d012837af7afa93add7d895a34a588cab Mon Sep 17 00:00:00 2001 From: Michele Bini Date: Sun, 27 Mar 2022 13:19:23 +0200 Subject: Set chime to 5 minutes diff --git a/src/components/datetime/DateTimeController.cpp b/src/components/datetime/DateTimeController.cpp index 8605176..8bf5fb9 100644 --- a/src/components/datetime/DateTimeController.cpp +++ b/src/components/datetime/DateTimeController.cpp @@ -89,12 +89,12 @@ void DateTime::UpdateTime(uint32_t systickCounter) { isHourAlreadyNotified = false; } - if ((!(minute%12)) && !isHalfHourAlreadyNotified) { + if ((!(minute%5)) && !isHalfHourAlreadyNotified) { isHalfHourAlreadyNotified = true; if (systemTask != nullptr) { - systemTask->PushMessage(System::Messages::OnNewHalfHour); + systemTask->PushMessage(System::Messages::OnChime); } - } else if (!!(minute%12)) { + } else if (!!(minute%5)) { isHalfHourAlreadyNotified = false; } diff --git a/src/displayapp/screens/settings/SettingChimes.cpp b/src/displayapp/screens/settings/SettingChimes.cpp index 543b5e0..2a39eef 100644 --- a/src/displayapp/screens/settings/SettingChimes.cpp +++ b/src/displayapp/screens/settings/SettingChimes.cpp @@ -62,7 +62,7 @@ SettingChimes::SettingChimes(Pinetime::Applications::DisplayApp* app, Pinetime:: optionsTotal++; cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text_static(cbOption[optionsTotal], " Every 30 mins"); + lv_checkbox_set_text_static(cbOption[optionsTotal], " Every 5 mins"); cbOption[optionsTotal]->user_data = this; lv_obj_set_event_cb(cbOption[optionsTotal], event_handler); SetRadioButtonStyle(cbOption[optionsTotal]); diff --git a/src/systemtask/Messages.h b/src/systemtask/Messages.h index 4e818d0..c2a18e2 100644 --- a/src/systemtask/Messages.h +++ b/src/systemtask/Messages.h @@ -21,7 +21,7 @@ namespace Pinetime { DisableSleeping, OnNewDay, OnNewHour, - OnNewHalfHour, + OnChime, OnChargingEvent, StopRinging, MeasureBatteryTimerExpired, diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp index f357d61..7a0d151 100644 --- a/src/systemtask/SystemTask.cpp +++ b/src/systemtask/SystemTask.cpp @@ -343,23 +343,21 @@ 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(30); + motorController.RunForDuration(22); } break; - case Messages::OnNewHalfHour: - using Pinetime::Controllers::AlarmController; + case Messages::OnChime: if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours) { - if (isSleeping && !isWakingUp) { + if (false && isSleeping && !isWakingUp) { GoToRunning(); displayApp.PushMessage(Pinetime::Applications::Display::Messages::Clock); } - motorController.RunForDuration(10); + motorController.RunForDuration(11); } break; case Messages::OnChargingEvent: -- cgit v0.10.2