diff --git a/.gitignore b/.gitignore index 81e49ae083..14872a71c1 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,5 @@ src/arm-none-eabi # clangd .cache/ + +node_modules/ \ No newline at end of file diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 602de3a585..3d419fad8e 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -34,6 +34,7 @@ namespace Pinetime { Orange, Pink }; + enum class VibrationStrength : uint8_t { Weak = 15, Normal = 35, Strong = 75 }; enum class PTSGaugeStyle : uint8_t { Full, Half, Numeric }; enum class PTSWeather : uint8_t { On, Off }; @@ -298,6 +299,28 @@ namespace Pinetime { return bleRadioEnabled; }; + void SetNotifVibration(VibrationStrength strength) { + if (strength != settings.notifVibration) { + settingsChanged = true; + } + settings.notifVibration = strength; + }; + + VibrationStrength GetNotifVibration() const { + return settings.notifVibration; + } + + void SetChimeVibration(VibrationStrength strength) { + if (strength != settings.chimeVibration) { + settingsChanged = true; + } + settings.chimeVibration = strength; + }; + + VibrationStrength GetChimeVibration() const { + return settings.chimeVibration; + } + private: Pinetime::Controllers::FS& fs; @@ -325,6 +348,9 @@ namespace Pinetime { uint16_t shakeWakeThreshold = 150; Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium; + + VibrationStrength notifVibration = VibrationStrength::Normal; + VibrationStrength chimeVibration = VibrationStrength::Normal; }; SettingsData settings; diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 6671ac9e51..59bb7c2460 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -49,6 +49,8 @@ #include "displayapp/screens/settings/SettingChimes.h" #include "displayapp/screens/settings/SettingShakeThreshold.h" #include "displayapp/screens/settings/SettingBluetooth.h" +#include "displayapp/screens/settings/SettingNotifVibration.h" +#include "displayapp/screens/settings/SettingChimeVibration.h" #include "libs/lv_conf.h" #include "UserApps.h" @@ -372,7 +374,7 @@ void DisplayApp::Refresh() { } else { LoadNewScreen(Apps::Timer, DisplayApp::FullRefreshDirections::Up); } - motorController.RunForDuration(35); + motorController.RunForDuration(static_cast(settingsController.GetNotifVibration())); break; case Messages::AlarmTriggered: if (currentApp == Apps::Alarm) { @@ -384,7 +386,7 @@ void DisplayApp::Refresh() { break; case Messages::ShowPairingKey: LoadNewScreen(Apps::PassKey, DisplayApp::FullRefreshDirections::Up); - motorController.RunForDuration(35); + motorController.RunForDuration(static_cast(settingsController.GetNotifVibration())); break; case Messages::TouchEvent: { if (state != States::Running) { @@ -473,7 +475,7 @@ void DisplayApp::Refresh() { break; case Messages::Chime: LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None); - motorController.RunForDuration(35); + motorController.RunForDuration(static_cast(settingsController.GetChimeVibration())); break; case Messages::OnChargingEvent: motorController.RunForDuration(15); @@ -563,6 +565,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio notificationManager, systemTask->nimble().alertService(), motorController, + settingsController, *systemTask, Screens::Notifications::Modes::Normal); break; @@ -571,6 +574,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio notificationManager, systemTask->nimble().alertService(), motorController, + settingsController, *systemTask, Screens::Notifications::Modes::Preview); break; @@ -623,6 +627,12 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio case Apps::SettingBluetooth: currentScreen = std::make_unique(this, settingsController); break; + case Apps::SettingNotifVibration: + currentScreen = std::make_unique(settingsController, motorController); + break; + case Apps::SettingChimeVibration: + currentScreen = std::make_unique(settingsController, motorController); + break; case Apps::BatteryInfo: currentScreen = std::make_unique(batteryController); break; diff --git a/src/displayapp/apps/Apps.h.in b/src/displayapp/apps/Apps.h.in index 2104a267c0..3f40137507 100644 --- a/src/displayapp/apps/Apps.h.in +++ b/src/displayapp/apps/Apps.h.in @@ -42,6 +42,8 @@ namespace Pinetime { SettingChimes, SettingShakeThreshold, SettingBluetooth, + SettingNotifVibration, + SettingChimeVibration, Error }; diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 837c4683aa..8b50ff42d3 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -14,6 +14,7 @@ Notifications::Notifications(DisplayApp* app, Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::AlertNotificationService& alertNotificationService, Pinetime::Controllers::MotorController& motorController, + Pinetime::Controllers::Settings& settingsController, System::SystemTask& systemTask, Modes mode) : app {app}, @@ -44,7 +45,7 @@ Notifications::Notifications(DisplayApp* app, if (notification.category == Controllers::NotificationManager::Categories::IncomingCall) { motorController.StartRinging(); } else { - motorController.RunForDuration(35); + motorController.RunForDuration(static_cast(settingsController.GetNotifVibration())); } timeoutLine = lv_line_create(lv_scr_act(), nullptr); diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index 8488dc5bb2..c122d92305 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -25,6 +25,7 @@ namespace Pinetime { Pinetime::Controllers::NotificationManager& notificationManager, Pinetime::Controllers::AlertNotificationService& alertNotificationService, Pinetime::Controllers::MotorController& motorController, + Pinetime::Controllers::Settings& settingsController, System::SystemTask& systemTask, Modes mode); ~Notifications() override; diff --git a/src/displayapp/screens/settings/SettingChimeVibration.cpp b/src/displayapp/screens/settings/SettingChimeVibration.cpp new file mode 100644 index 0000000000..ad129cfebb --- /dev/null +++ b/src/displayapp/screens/settings/SettingChimeVibration.cpp @@ -0,0 +1,68 @@ +#include "displayapp/screens/settings/SettingChimeVibration.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 { + struct Option { + Pinetime::Controllers::Settings::VibrationStrength vibrationStrength; + const char* name; + }; + + constexpr std::array options = {{ + {Pinetime::Controllers::Settings::VibrationStrength::Weak, "Weak"}, + {Pinetime::Controllers::Settings::VibrationStrength::Normal, "Normal"}, + {Pinetime::Controllers::Settings::VibrationStrength::Strong, "Strong"}, + }}; + + std::array CreateOptionArray() { + std::array optionArray; + for (size_t i = 0; i < CheckboxList::MaxItems; i++) { + if (i >= options.size()) { + optionArray[i].name = ""; + optionArray[i].enabled = false; + } else { + optionArray[i].name = options[i].name; + optionArray[i].enabled = true; + } + } + return optionArray; + } + + uint32_t GetDefaultOption(Pinetime::Controllers::Settings::VibrationStrength currentOption) { + for (size_t i = 0; i < options.size(); i++) { + if (options[i].vibrationStrength == currentOption) { + return i; + } + } + return 0; + } +} + +SettingChimeVibration::SettingChimeVibration(Pinetime::Controllers::Settings& settingsController, + Pinetime::Controllers::MotorController& motorController) + : checkboxList( + 0, + 1, + "Chime strength", + Symbols::tachometer, + GetDefaultOption(settingsController.GetChimeVibration()), + [&settings = settingsController, &motor = motorController](uint32_t index) { + // Preview current setting + motor.RunForDuration(static_cast(options[index].vibrationStrength)); + + settings.SetChimeVibration(options[index].vibrationStrength); + settings.SaveSettings(); + }, + CreateOptionArray()) { +} + +SettingChimeVibration::~SettingChimeVibration() { + lv_obj_clean(lv_scr_act()); +} diff --git a/src/displayapp/screens/settings/SettingChimeVibration.h b/src/displayapp/screens/settings/SettingChimeVibration.h new file mode 100644 index 0000000000..3ab5088ef4 --- /dev/null +++ b/src/displayapp/screens/settings/SettingChimeVibration.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include + +#include "components/settings/Settings.h" +#include "components/motor/MotorController.h" +#include "displayapp/screens/Screen.h" +#include "displayapp/screens/CheckboxList.h" + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class SettingChimeVibration : public Screen { + public: + explicit SettingChimeVibration(Pinetime::Controllers::Settings& settingsController, + Pinetime::Controllers::MotorController& motorController); + ~SettingChimeVibration() override; + + private: + CheckboxList checkboxList; + }; + } + } +} diff --git a/src/displayapp/screens/settings/SettingNotifVibration.cpp b/src/displayapp/screens/settings/SettingNotifVibration.cpp new file mode 100644 index 0000000000..35cd83da0d --- /dev/null +++ b/src/displayapp/screens/settings/SettingNotifVibration.cpp @@ -0,0 +1,67 @@ +#include "displayapp/screens/settings/SettingNotifVibration.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 { + struct Option { + Pinetime::Controllers::Settings::VibrationStrength vibrationStrength; + const char* name; + }; + + constexpr std::array options = {{ + {Pinetime::Controllers::Settings::VibrationStrength::Weak, "Weak"}, + {Pinetime::Controllers::Settings::VibrationStrength::Normal, "Normal"}, + {Pinetime::Controllers::Settings::VibrationStrength::Strong, "Strong"}, + }}; + + std::array CreateOptionArray() { + std::array optionArray; + for (size_t i = 0; i < CheckboxList::MaxItems; i++) { + if (i >= options.size()) { + optionArray[i].name = ""; + optionArray[i].enabled = false; + } else { + optionArray[i].name = options[i].name; + optionArray[i].enabled = true; + } + } + return optionArray; + } + + uint32_t GetDefaultOption(Pinetime::Controllers::Settings::VibrationStrength currentOption) { + for (size_t i = 0; i < options.size(); i++) { + if (options[i].vibrationStrength == currentOption) { + return i; + } + } + return 0; + } +} + +SettingNotifVibration::SettingNotifVibration(Pinetime::Controllers::Settings& settingsController, + Pinetime::Controllers::MotorController& motorController) + : checkboxList( + 0, + 1, + "Notif. strength", + Symbols::tachometer, + GetDefaultOption(settingsController.GetNotifVibration()), + [&settings = settingsController, &motor = motorController](uint32_t index) { + motor.RunForDuration(static_cast(options[index].vibrationStrength)); + + settings.SetNotifVibration(options[index].vibrationStrength); + settings.SaveSettings(); + }, + CreateOptionArray()) { +} + +SettingNotifVibration::~SettingNotifVibration() { + lv_obj_clean(lv_scr_act()); +} diff --git a/src/displayapp/screens/settings/SettingNotifVibration.h b/src/displayapp/screens/settings/SettingNotifVibration.h new file mode 100644 index 0000000000..12df0733fd --- /dev/null +++ b/src/displayapp/screens/settings/SettingNotifVibration.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include + +#include "components/settings/Settings.h" +#include "components/motor/MotorController.h" +#include "displayapp/screens/Screen.h" +#include "displayapp/screens/CheckboxList.h" + +namespace Pinetime { + + namespace Applications { + namespace Screens { + + class SettingNotifVibration : public Screen { + public: + explicit SettingNotifVibration(Pinetime::Controllers::Settings& settingsController, + Pinetime::Controllers::MotorController& motorController); + ~SettingNotifVibration() override; + + private: + CheckboxList checkboxList; + }; + } + } +} diff --git a/src/displayapp/screens/settings/Settings.h b/src/displayapp/screens/settings/Settings.h index 3722c2be39..6f00ef325f 100644 --- a/src/displayapp/screens/settings/Settings.h +++ b/src/displayapp/screens/settings/Settings.h @@ -43,10 +43,12 @@ namespace Pinetime { {Symbols::batteryHalf, "Battery", Apps::BatteryInfo}, {Symbols::clock, "Chimes", Apps::SettingChimes}, + {Symbols::tachometer, "Notif. str.", Apps::SettingNotifVibration}, + {Symbols::tachometer, "Chime strength", Apps::SettingChimeVibration}, {Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold}, + {Symbols::check, "Firmware", Apps::FirmwareValidation}, {Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth}, - {Symbols::list, "About", Apps::SysInfo}, // {Symbols::none, "None", Apps::None},