Merge branch 'motor_pattern'
This commit is contained in:
commit
6bbdb581cc
@ -5,14 +5,58 @@
|
|||||||
|
|
||||||
using namespace Pinetime::Controllers;
|
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[] = {10, 100, 50, 200, 10, 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<MotorController*>(pvTimerGetTimerID(xTimer));
|
||||||
|
motorController->PatternFinished();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MotorController::Init() {
|
void MotorController::Init() {
|
||||||
nrf_gpio_cfg_output(PinMap::Motor);
|
nrf_gpio_cfg_output(PinMap::Motor);
|
||||||
nrf_gpio_pin_set(PinMap::Motor);
|
nrf_gpio_pin_set(PinMap::Motor);
|
||||||
|
|
||||||
|
vibTimer = xTimerCreate("vibration", 1, pdFALSE, this, PatternStep);
|
||||||
shortVib = xTimerCreate("shortVib", 1, pdFALSE, nullptr, StopMotor);
|
shortVib = xTimerCreate("shortVib", 1, pdFALSE, nullptr, StopMotor);
|
||||||
longVib = xTimerCreate("longVib", pdMS_TO_TICKS(1000), pdTRUE, this, Ring);
|
longVib = xTimerCreate("longVib", pdMS_TO_TICKS(1000), pdTRUE, this, Ring);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MotorController::PatternFinished() {
|
||||||
|
patternPlaying = false;
|
||||||
|
}
|
||||||
|
|
||||||
void MotorController::Ring(TimerHandle_t xTimer) {
|
void MotorController::Ring(TimerHandle_t xTimer) {
|
||||||
auto* motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer));
|
auto* motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer));
|
||||||
motorController->RunForDuration(50);
|
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() {
|
void MotorController::StartRinging() {
|
||||||
RunForDuration(50);
|
RunForDuration(50);
|
||||||
xTimerStart(longVib, 0);
|
xTimerStart(longVib, 0);
|
||||||
|
@ -15,10 +15,13 @@ namespace Pinetime {
|
|||||||
void RunForDuration(uint8_t motorDuration);
|
void RunForDuration(uint8_t motorDuration);
|
||||||
void StartRinging();
|
void StartRinging();
|
||||||
void StopRinging();
|
void StopRinging();
|
||||||
|
void PatternFinished();
|
||||||
|
bool StartPattern();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void Ring(TimerHandle_t xTimer);
|
static void Ring(TimerHandle_t xTimer);
|
||||||
static void StopMotor(TimerHandle_t xTimer);
|
static void StopMotor(TimerHandle_t xTimer);
|
||||||
|
bool patternPlaying;
|
||||||
TimerHandle_t shortVib;
|
TimerHandle_t shortVib;
|
||||||
TimerHandle_t longVib;
|
TimerHandle_t longVib;
|
||||||
};
|
};
|
||||||
|
@ -389,7 +389,18 @@ void DisplayApp::Refresh() {
|
|||||||
break;
|
break;
|
||||||
case Messages::Chime:
|
case Messages::Chime:
|
||||||
LoadNewScreen(Apps::Clock, DisplayApp::FullRefreshDirections::None);
|
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.StartPattern();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NRF_LOG_INFO("Long: %d", time_var);
|
||||||
|
motorController.RunForDuration(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Messages::OnChargingEvent:
|
case Messages::OnChargingEvent:
|
||||||
RestoreBrightness();
|
RestoreBrightness();
|
||||||
|
@ -128,6 +128,7 @@ namespace Pinetime {
|
|||||||
Utility::StaticStack<Apps, returnAppStackSize> returnAppStack;
|
Utility::StaticStack<Apps, returnAppStackSize> returnAppStack;
|
||||||
Utility::StaticStack<FullRefreshDirections, returnAppStackSize> appStackDirections;
|
Utility::StaticStack<FullRefreshDirections, returnAppStackSize> appStackDirections;
|
||||||
|
|
||||||
|
int time_var;
|
||||||
bool isDimmed = false;
|
bool isDimmed = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include "displayapp/DisplayApp.h"
|
#include "displayapp/DisplayApp.h"
|
||||||
#include "displayapp/screens/Symbols.h"
|
#include "displayapp/screens/Symbols.h"
|
||||||
#include "displayapp/InfiniTimeTheme.h"
|
#include "displayapp/InfiniTimeTheme.h"
|
||||||
|
#include <libraries/log/nrf_log.h>
|
||||||
|
|
||||||
using namespace Pinetime::Applications::Screens;
|
using namespace Pinetime::Applications::Screens;
|
||||||
|
|
||||||
@ -58,8 +59,17 @@ FlashLight::~FlashLight() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FlashLight::SetColors() {
|
void FlashLight::SetColors() {
|
||||||
lv_color_t bgColor = isOn ? LV_COLOR_WHITE : LV_COLOR_BLACK;
|
lv_color_t bgColor = LV_COLOR_BLACK;
|
||||||
lv_color_t fgColor = isOn ? Colors::lightGray : LV_COLOR_WHITE;
|
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_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);
|
lv_obj_set_style_local_text_color(flashLight, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, fgColor);
|
||||||
@ -86,9 +96,11 @@ void FlashLight::SetIndicators() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FlashLight::Toggle() {
|
void FlashLight::Toggle() {
|
||||||
isOn = !isOn;
|
State_l++;
|
||||||
|
if(State_l > 2)
|
||||||
|
State_l = 0;
|
||||||
SetColors();
|
SetColors();
|
||||||
if (isOn) {
|
if (State_l) {
|
||||||
brightnessController.Set(brightnessLevel);
|
brightnessController.Set(brightnessLevel);
|
||||||
} else {
|
} else {
|
||||||
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
|
brightnessController.Set(Controllers::BrightnessController::Levels::Low);
|
||||||
@ -99,7 +111,7 @@ bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
|||||||
using namespace Pinetime::Controllers;
|
using namespace Pinetime::Controllers;
|
||||||
|
|
||||||
auto SetState = [this]() {
|
auto SetState = [this]() {
|
||||||
if (isOn) {
|
if (State_l) {
|
||||||
brightnessController.Set(brightnessLevel);
|
brightnessController.Set(brightnessLevel);
|
||||||
}
|
}
|
||||||
SetIndicators();
|
SetIndicators();
|
||||||
@ -127,4 +139,4 @@ bool FlashLight::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
@ -26,12 +26,13 @@ namespace Pinetime {
|
|||||||
Pinetime::System::SystemTask& systemTask;
|
Pinetime::System::SystemTask& systemTask;
|
||||||
Controllers::BrightnessController& brightnessController;
|
Controllers::BrightnessController& brightnessController;
|
||||||
|
|
||||||
|
|
||||||
Controllers::BrightnessController::Levels brightnessLevel = Controllers::BrightnessController::Levels::High;
|
Controllers::BrightnessController::Levels brightnessLevel = Controllers::BrightnessController::Levels::High;
|
||||||
|
|
||||||
lv_obj_t* flashLight;
|
lv_obj_t* flashLight;
|
||||||
lv_obj_t* backgroundAction;
|
lv_obj_t* backgroundAction;
|
||||||
lv_obj_t* indicators[3];
|
lv_obj_t* indicators[3];
|
||||||
bool isOn = false;
|
int State_l = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user