From 8ff6bd9cae64a901fc362780c083c109fdcc5dde Mon Sep 17 00:00:00 2001 From: tofasthacker Date: Fri, 6 Oct 2023 21:04:42 -0400 Subject: [PATCH 1/5] changed chime --- src/displayapp/DisplayApp.cpp | 13 ++++++++++++- src/displayapp/DisplayApp.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index a547cfbc..4c670a8e 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -389,7 +389,18 @@ void DisplayApp::Refresh() { break; case Messages::Chime: LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None); - motorController.RunForDuration(35); + time_var = dateTimeController.Minutes(); + if (time_var == 30){ + NRF_LOG_INFO("Short: %d", time_var); + motorController.RunForDuration(25); + } + else + { + NRF_LOG_INFO("Long: %d", time_var); + motorController.RunForDuration(200); + } + + break; case Messages::OnChargingEvent: RestoreBrightness(); diff --git a/src/displayapp/DisplayApp.h b/src/displayapp/DisplayApp.h index f537651d..2c8a3b64 100644 --- a/src/displayapp/DisplayApp.h +++ b/src/displayapp/DisplayApp.h @@ -128,6 +128,7 @@ namespace Pinetime { Utility::StaticStack returnAppStack; Utility::StaticStack appStackDirections; + int time_var; bool isDimmed = false; }; } From 9d749434b560babd05611a8edac9d82f26de6351 Mon Sep 17 00:00:00 2001 From: tofasthacker Date: Sat, 7 Oct 2023 11:41:36 -0400 Subject: [PATCH 2/5] added red flashlight --- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/FlashLight.cpp | 51 +++++++++++++++++++++++---- src/displayapp/screens/FlashLight.h | 6 ++-- 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 4c670a8e..0d3cc441 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -556,7 +556,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio touchPanel); break; case Apps::FlashLight: - currentScreen = std::make_unique(*systemTask, brightnessController); + currentScreen = std::make_unique(*systemTask, brightnessController, dateTimeController); break; case Apps::StopWatch: currentScreen = std::make_unique(*systemTask); diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp index 16f25df0..62c36805 100644 --- a/src/displayapp/screens/FlashLight.cpp +++ b/src/displayapp/screens/FlashLight.cpp @@ -2,6 +2,7 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/Symbols.h" #include "displayapp/InfiniTimeTheme.h" +#include using namespace Pinetime::Applications::Screens; @@ -14,11 +15,24 @@ namespace { } } -FlashLight::FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightnessController) - : systemTask {systemTask}, brightnessController {brightnessController} { +FlashLight::FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightnessController, Controllers::DateTime& dateTimeController) + : systemTask {systemTask}, brightnessController {brightnessController}, dateTimeController {dateTimeController} { brightnessController.Set(Controllers::BrightnessController::Levels::Low); + + + + int time_var = dateTimeController.Hours(); + if(time_var > 21 || time_var < 6){ + State_l = 1; + NRF_LOG_INFO("Loop Hour Red: %d", time_var); + } + else { + State_l = 0; + NRF_LOG_INFO("Loop Hour White: %d", time_var); + } + 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::flashlight); @@ -58,8 +72,17 @@ FlashLight::~FlashLight() { } void FlashLight::SetColors() { - lv_color_t bgColor = isOn ? LV_COLOR_WHITE : LV_COLOR_BLACK; - lv_color_t fgColor = isOn ? Colors::lightGray : LV_COLOR_WHITE; + lv_color_t bgColor = LV_COLOR_BLACK; + if(State_l == 0){ + bgColor = LV_COLOR_BLACK; + } else if (State_l == 1){ + bgColor = LV_COLOR_WHITE; + } + else { + bgColor = lv_color_hex(0xff0000); + } + + lv_color_t fgColor = State_l ? Colors::lightGray : LV_COLOR_WHITE; lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, bgColor); lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fgColor); @@ -86,9 +109,11 @@ void FlashLight::SetIndicators() { } void FlashLight::Toggle() { - isOn = !isOn; + State_l++; + if(State_l > 2) + State_l = 0; SetColors(); - if (isOn) { + if (State_l) { brightnessController.Set(brightnessLevel); } else { brightnessController.Set(Controllers::BrightnessController::Levels::Low); @@ -99,7 +124,7 @@ bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { using namespace Pinetime::Controllers; auto SetState = [this]() { - if (isOn) { + if (State_l) { brightnessController.Set(brightnessLevel); } SetIndicators(); @@ -128,3 +153,15 @@ bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { return false; } +/* + time_var = dateTimeController.Minutes(); + if (time_var == 30){ + NRF_LOG_INFO("Short: %d", time_var); + motorController.RunForDuration(25); + } + else + { + NRF_LOG_INFO("Long: %d", time_var); + motorController.RunForDuration(200); + } +*/ \ No newline at end of file diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h index 2b710ed5..1481838e 100644 --- a/src/displayapp/screens/FlashLight.h +++ b/src/displayapp/screens/FlashLight.h @@ -2,6 +2,7 @@ #include "displayapp/screens/Screen.h" #include "components/brightness/BrightnessController.h" +#include "components/datetime/DateTimeController.h" #include "systemtask/SystemTask.h" #include #include @@ -13,7 +14,7 @@ namespace Pinetime { class FlashLight : public Screen { public: - FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightness); + FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightness, Controllers::DateTime& dateTimeController); ~FlashLight() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; @@ -25,13 +26,14 @@ namespace Pinetime { Pinetime::System::SystemTask& systemTask; Controllers::BrightnessController& brightnessController; + Controllers::DateTime& dateTimeController; Controllers::BrightnessController::Levels brightnessLevel = Controllers::BrightnessController::Levels::High; lv_obj_t* flashLight; lv_obj_t* backgroundAction; lv_obj_t* indicators[3]; - bool isOn = false; + int State_l = 1; }; } } From 3d75a7dc9f29bc01942fb74cae8dc02b456de539 Mon Sep 17 00:00:00 2001 From: Riku Isokoski Date: Thu, 16 Feb 2023 11:21:21 +0200 Subject: [PATCH 3/5] added motor pattern --- src/components/motor/MotorController.cpp | 53 ++++++++++++++++++++++++ src/components/motor/MotorController.h | 3 ++ 2 files changed, 56 insertions(+) diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 4e392416..96963381 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -5,14 +5,58 @@ using namespace Pinetime::Controllers; +namespace { + TimerHandle_t vibTimer; + + void PatternStep(TimerHandle_t xTimer) { + /* Vibration pattern format: + * { + * durationOfVibration, + * durationOfPause, + * durationOfVibration, + * durationOfPause, + * ..., + * durationOfVibration, + * zeroTerminator + * } + * + * Patterns can be any length + * The pattern must end with a duration of vibration and a terminator. + */ + + static constexpr uint8_t vibrationPattern[] = {30, 150, 30, 150, 30, 0}; + + static size_t patternPosition = 0; + if (vibrationPattern[patternPosition] != 0 && xTimerChangePeriod(vibTimer, vibrationPattern[patternPosition] << 1, 0) == pdPASS && + xTimerStart(vibTimer, 0) == pdPASS) { + if (patternPosition % 2 == 0) { + nrf_gpio_pin_clear(Pinetime::PinMap::Motor); + } else { + nrf_gpio_pin_set(Pinetime::PinMap::Motor); + } + patternPosition++; + } else { + patternPosition = 0; + nrf_gpio_pin_set(Pinetime::PinMap::Motor); + auto* motorController = static_cast(pvTimerGetTimerID(xTimer)); + motorController->PatternFinished(); + } + } +} + void MotorController::Init() { nrf_gpio_cfg_output(PinMap::Motor); nrf_gpio_pin_set(PinMap::Motor); + vibTimer = xTimerCreate("vibration", 1, pdFALSE, this, PatternStep); shortVib = xTimerCreate("shortVib", 1, pdFALSE, nullptr, StopMotor); longVib = xTimerCreate("longVib", pdMS_TO_TICKS(1000), pdTRUE, this, Ring); } +void MotorController::PatternFinished() { + patternPlaying = false; +} + void MotorController::Ring(TimerHandle_t xTimer) { auto* motorController = static_cast(pvTimerGetTimerID(xTimer)); motorController->RunForDuration(50); @@ -24,6 +68,15 @@ void MotorController::RunForDuration(uint8_t motorDuration) { } } +bool MotorController::StartPattern() { + if (!patternPlaying) { + patternPlaying = true; + PatternStep(vibTimer); + return true; + } + return false; +} + void MotorController::StartRinging() { RunForDuration(50); xTimerStart(longVib, 0); diff --git a/src/components/motor/MotorController.h b/src/components/motor/MotorController.h index 6dea6d1f..2f6ca59b 100644 --- a/src/components/motor/MotorController.h +++ b/src/components/motor/MotorController.h @@ -15,10 +15,13 @@ namespace Pinetime { void RunForDuration(uint8_t motorDuration); void StartRinging(); void StopRinging(); + void PatternFinished(); + bool StartPattern(); private: static void Ring(TimerHandle_t xTimer); static void StopMotor(TimerHandle_t xTimer); + bool patternPlaying; TimerHandle_t shortVib; TimerHandle_t longVib; }; From bf8c4dfef8a0445f25966ca2f2b7aea9f3df6cbf Mon Sep 17 00:00:00 2001 From: tofasthacker Date: Sat, 14 Oct 2023 22:50:41 -0400 Subject: [PATCH 4/5] change motor patern on half hour --- src/components/motor/MotorController.cpp | 2 +- src/displayapp/DisplayApp.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/motor/MotorController.cpp b/src/components/motor/MotorController.cpp index 96963381..2bbd2a03 100644 --- a/src/components/motor/MotorController.cpp +++ b/src/components/motor/MotorController.cpp @@ -24,7 +24,7 @@ namespace { * The pattern must end with a duration of vibration and a terminator. */ - static constexpr uint8_t vibrationPattern[] = {30, 150, 30, 150, 30, 0}; + static constexpr uint8_t vibrationPattern[] = {10, 100, 50, 200, 10, 0}; static size_t patternPosition = 0; if (vibrationPattern[patternPosition] != 0 && xTimerChangePeriod(vibTimer, vibrationPattern[patternPosition] << 1, 0) == pdPASS && diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 0d3cc441..46375698 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -392,7 +392,7 @@ void DisplayApp::Refresh() { time_var = dateTimeController.Minutes(); if (time_var == 30){ NRF_LOG_INFO("Short: %d", time_var); - motorController.RunForDuration(25); + motorController.StartPattern(); } else { From 270d15a8ea3fc52fcc4d83f8f9498941784684a9 Mon Sep 17 00:00:00 2001 From: tofasthacker Date: Sat, 14 Oct 2023 22:55:41 -0400 Subject: [PATCH 5/5] switched red flash light off night default --- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/FlashLight.cpp | 31 +++------------------------ src/displayapp/screens/FlashLight.h | 7 +++--- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 46375698..1ae59f05 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -556,7 +556,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio touchPanel); break; case Apps::FlashLight: - currentScreen = std::make_unique(*systemTask, brightnessController, dateTimeController); + currentScreen = std::make_unique(*systemTask, brightnessController); break; case Apps::StopWatch: currentScreen = std::make_unique(*systemTask); diff --git a/src/displayapp/screens/FlashLight.cpp b/src/displayapp/screens/FlashLight.cpp index 62c36805..f560fef7 100644 --- a/src/displayapp/screens/FlashLight.cpp +++ b/src/displayapp/screens/FlashLight.cpp @@ -15,24 +15,11 @@ namespace { } } -FlashLight::FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightnessController, Controllers::DateTime& dateTimeController) - : systemTask {systemTask}, brightnessController {brightnessController}, dateTimeController {dateTimeController} { +FlashLight::FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightnessController) + : systemTask {systemTask}, brightnessController {brightnessController} { brightnessController.Set(Controllers::BrightnessController::Levels::Low); - - - - int time_var = dateTimeController.Hours(); - if(time_var > 21 || time_var < 6){ - State_l = 1; - NRF_LOG_INFO("Loop Hour Red: %d", time_var); - } - else { - State_l = 0; - NRF_LOG_INFO("Loop Hour White: %d", time_var); - } - 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::flashlight); @@ -152,16 +139,4 @@ bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) { } return false; -} -/* - time_var = dateTimeController.Minutes(); - if (time_var == 30){ - NRF_LOG_INFO("Short: %d", time_var); - motorController.RunForDuration(25); - } - else - { - NRF_LOG_INFO("Long: %d", time_var); - motorController.RunForDuration(200); - } -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/displayapp/screens/FlashLight.h b/src/displayapp/screens/FlashLight.h index 1481838e..4f5d4ac3 100644 --- a/src/displayapp/screens/FlashLight.h +++ b/src/displayapp/screens/FlashLight.h @@ -2,7 +2,6 @@ #include "displayapp/screens/Screen.h" #include "components/brightness/BrightnessController.h" -#include "components/datetime/DateTimeController.h" #include "systemtask/SystemTask.h" #include #include @@ -14,7 +13,7 @@ namespace Pinetime { class FlashLight : public Screen { public: - FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightness, Controllers::DateTime& dateTimeController); + FlashLight(System::SystemTask& systemTask, Controllers::BrightnessController& brightness); ~FlashLight() override; bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; @@ -26,14 +25,14 @@ namespace Pinetime { Pinetime::System::SystemTask& systemTask; Controllers::BrightnessController& brightnessController; - Controllers::DateTime& dateTimeController; + Controllers::BrightnessController::Levels brightnessLevel = Controllers::BrightnessController::Levels::High; lv_obj_t* flashLight; lv_obj_t* backgroundAction; lv_obj_t* indicators[3]; - int State_l = 1; + int State_l = 0; }; } }