Skip to content

Commit

Permalink
MotorController: Add ringing for X times
Browse files Browse the repository at this point in the history
  • Loading branch information
hatmajster committed Jan 27, 2022
1 parent 23ca635 commit e53415a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/components/motor/MotorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ void MotorController::Init() {
void MotorController::Ring(void* p_context) {
auto* motorController = static_cast<MotorController*>(p_context);
motorController->RunForDuration(50);
if (motorController->shouldStopRinging()) {
motorController->StopRinging();
}
}

void MotorController::RunForDuration(uint8_t motorDuration) {
Expand All @@ -29,6 +32,13 @@ void MotorController::RunForDuration(uint8_t motorDuration) {
}

void MotorController::StartRinging() {
timesToRing = -1;
Ring(this);
app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
}

void MotorController::StartRingingCoupleTimes(int8_t times) {
timesToRing = times;
Ring(this);
app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
}
Expand All @@ -41,3 +51,16 @@ void MotorController::StopRinging() {
void MotorController::StopMotor(void* p_context) {
nrf_gpio_pin_set(PinMap::Motor);
}

bool MotorController::shouldStopRinging(){
// repeat forever if timesToRing is negative
if (timesToRing < 0) {
return false;
}

if (timesToRing == 0) {
return true;
}
timesToRing--;
return false;
}
5 changes: 5 additions & 0 deletions src/components/motor/MotorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ namespace Pinetime {
void Init();
void RunForDuration(uint8_t motorDuration);
void StartRinging();
void StartRingingCoupleTimes(int8_t times);
static void StopRinging();

private:
bool shouldStopRinging();

static void Ring(void* p_context);
static void StopMotor(void* p_context);

int8_t timesToRing = 0;
};
}
}
2 changes: 1 addition & 1 deletion src/systemtask/SystemTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void SystemTask::Work() {
if (isSleeping && !isWakingUp) {
GoToRunning();
}
motorController.StartRinging();
motorController.StartRingingCoupleTimes(10);
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
break;
case Messages::SetOffAlarm:
Expand Down

0 comments on commit e53415a

Please sign in to comment.