diff --git a/src/components/motion/MotionController.cpp b/src/components/motion/MotionController.cpp index ce959f0efb..ce37412d42 100644 --- a/src/components/motion/MotionController.cpp +++ b/src/components/motion/MotionController.cpp @@ -76,6 +76,9 @@ void MotionController::Update(int16_t x, int16_t y, int16_t z, uint32_t nbSteps) int32_t deltaSteps = nbSteps - oldSteps; if (deltaSteps > 0) { currentTripSteps += deltaSteps; + locomotionDecay = 100; // 10 seconds x 10Hz + } else if (locomotionDecay > 0) { + locomotionDecay--; } SetSteps(Days::Today, nbSteps); } diff --git a/src/components/motion/MotionController.h b/src/components/motion/MotionController.h index ed6cbbd144..f98063677a 100644 --- a/src/components/motion/MotionController.h +++ b/src/components/motion/MotionController.h @@ -74,6 +74,10 @@ namespace Pinetime { return service; } + bool Locomotion() const { + return (locomotionDecay != 0); + } + private: Utility::CircularBuffer nbSteps = {0}; uint32_t currentTripSteps = 0; @@ -112,6 +116,7 @@ namespace Pinetime { DeviceTypes deviceType = DeviceTypes::Unknown; Pinetime::Controllers::MotionService* service = nullptr; + uint8_t locomotionDecay = 0; }; } } diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 9133d3fea1..7c06768163 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -244,6 +244,17 @@ namespace Pinetime { return settings.alwaysOnDisplay; } + void SetMotionAutoBrightSetting(bool state) { + if (state != settings.motionAutoBright) { + settingsChanged = true; + } + settings.motionAutoBright = state; + } + + bool GetMotionAutoBrightSetting() const { + return settings.motionAutoBright; + } + void SetShakeThreshold(uint16_t thresh) { if (settings.shakeWakeThreshold != thresh) { settings.shakeWakeThreshold = thresh; @@ -362,6 +373,7 @@ namespace Pinetime { uint32_t screenTimeOut = 15000; bool alwaysOnDisplay = false; + bool motionAutoBright = false; ClockType clockType = ClockType::H24; WeatherFormat weatherFormat = WeatherFormat::Metric; diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 84fa603622..5c8aec0c71 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -568,6 +568,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio notificationManager, systemTask->nimble().alertService(), motorController, + brightnessController, + motionController, + settingsController, *systemTask, Screens::Notifications::Modes::Normal); break; @@ -576,6 +579,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio notificationManager, systemTask->nimble().alertService(), motorController, + brightnessController, + motionController, + settingsController, *systemTask, Screens::Notifications::Modes::Preview); break; diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 7d937c6d8a..f2ef2546e9 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -2,6 +2,8 @@ #include "displayapp/DisplayApp.h" #include "components/ble/MusicService.h" #include "components/ble/AlertNotificationService.h" +#include "components/brightness/BrightnessController.h" +#include "components/motion/MotionController.h" #include "displayapp/screens/Symbols.h" #include #include "displayapp/InfiniTimeTheme.h" @@ -14,12 +16,18 @@ Notifications::Notifications(DisplayApp* app, Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::AlertNotificationService& alertNotificationService, Pinetime::Controllers::MotorController& motorController, + Pinetime::Controllers::BrightnessController& brightnessController, + Pinetime::Controllers::MotionController& motionController, + Pinetime::Controllers::Settings& settingsController, System::SystemTask& systemTask, Modes mode) : app {app}, notificationManager {notificationManager}, alertNotificationService {alertNotificationService}, motorController {motorController}, + brightnessController {brightnessController}, + motionController {motionController}, + settingsController {settingsController}, wakeLock(systemTask), mode {mode} { @@ -58,6 +66,9 @@ Notifications::Notifications(DisplayApp* app, interacted = false; } + if (settingsController.GetMotionAutoBrightSetting() && motionController.Locomotion()) { + brightnessController.Set(Pinetime::Controllers::BrightnessController::Levels::High); + } taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this); } diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index 8488dc5bb2..1b23f35cf9 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -7,6 +7,9 @@ #include "displayapp/screens/Screen.h" #include "components/ble/NotificationManager.h" #include "components/motor/MotorController.h" +#include "components/brightness/BrightnessController.h" +#include "components/motion/MotionController.h" +#include #include "systemtask/SystemTask.h" #include "systemtask/WakeLock.h" @@ -25,6 +28,9 @@ namespace Pinetime { Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::AlertNotificationService& alertNotificationService, Pinetime::Controllers::MotorController& motorController, + Pinetime::Controllers::BrightnessController& brightnessController, + Pinetime::Controllers::MotionController& motionController, + Pinetime::Controllers::Settings& settingsController, System::SystemTask& systemTask, Modes mode); ~Notifications() override; @@ -74,6 +80,9 @@ namespace Pinetime { Pinetime::Controllers::NotificationManager& notificationManager; Pinetime::Controllers::AlertNotificationService& alertNotificationService; Pinetime::Controllers::MotorController& motorController; + Pinetime::Controllers::BrightnessController& brightnessController; + Pinetime::Controllers::MotionController& motionController; + Pinetime::Controllers::Settings& settingsController; System::WakeLock wakeLock; Modes mode = Modes::Normal; std::unique_ptr currentItem; diff --git a/src/displayapp/screens/settings/SettingDisplay.cpp b/src/displayapp/screens/settings/SettingDisplay.cpp index bbc188a9d7..787e5e4040 100644 --- a/src/displayapp/screens/settings/SettingDisplay.cpp +++ b/src/displayapp/screens/settings/SettingDisplay.cpp @@ -20,6 +20,13 @@ namespace { screen->ToggleAlwaysOn(); } } + + void MotionAutoBrightEventHandler(lv_obj_t* obj, lv_event_t event) { + if (event == LV_EVENT_VALUE_CHANGED) { + auto* screen = static_cast(obj->user_data); + screen->ToggleMotionAutoBright(); + } + } } constexpr std::array SettingDisplay::options; @@ -64,11 +71,18 @@ SettingDisplay::SettingDisplay(Pinetime::Controllers::Settings& settingsControll } alwaysOnCheckbox = lv_checkbox_create(container1, nullptr); - lv_checkbox_set_text(alwaysOnCheckbox, "Always On"); + lv_checkbox_set_text(alwaysOnCheckbox, "AOD"); lv_checkbox_set_checked(alwaysOnCheckbox, settingsController.GetAlwaysOnDisplaySetting()); lv_obj_add_state(alwaysOnCheckbox, LV_STATE_DEFAULT); alwaysOnCheckbox->user_data = this; lv_obj_set_event_cb(alwaysOnCheckbox, AlwaysOnEventHandler); + + motionAutoBrightCheckbox = lv_checkbox_create(container1, nullptr); + lv_checkbox_set_text(motionAutoBrightCheckbox, "MAB"); + lv_checkbox_set_checked(motionAutoBrightCheckbox, settingsController.GetMotionAutoBrightSetting()); + lv_obj_add_state(motionAutoBrightCheckbox, LV_STATE_DEFAULT); + motionAutoBrightCheckbox->user_data = this; + lv_obj_set_event_cb(motionAutoBrightCheckbox, MotionAutoBrightEventHandler); } SettingDisplay::~SettingDisplay() { @@ -81,6 +95,11 @@ void SettingDisplay::ToggleAlwaysOn() { lv_checkbox_set_checked(alwaysOnCheckbox, settingsController.GetAlwaysOnDisplaySetting()); } +void SettingDisplay::ToggleMotionAutoBright() { + settingsController.SetMotionAutoBrightSetting(!settingsController.GetMotionAutoBrightSetting()); + lv_checkbox_set_checked(motionAutoBrightCheckbox, settingsController.GetMotionAutoBrightSetting()); +} + void SettingDisplay::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (event == LV_EVENT_CLICKED) { for (unsigned int i = 0; i < options.size(); i++) { diff --git a/src/displayapp/screens/settings/SettingDisplay.h b/src/displayapp/screens/settings/SettingDisplay.h index 3bd10a62a4..c6109024ba 100644 --- a/src/displayapp/screens/settings/SettingDisplay.h +++ b/src/displayapp/screens/settings/SettingDisplay.h @@ -19,6 +19,7 @@ namespace Pinetime { void UpdateSelected(lv_obj_t* object, lv_event_t event); void ToggleAlwaysOn(); + void ToggleMotionAutoBright(); private: static constexpr std::array options = {5000, 7000, 10000, 15000, 20000, 30000}; @@ -26,6 +27,7 @@ namespace Pinetime { Controllers::Settings& settingsController; lv_obj_t* cbOption[options.size()]; lv_obj_t* alwaysOnCheckbox; + lv_obj_t* motionAutoBrightCheckbox; }; } }