Skip to content
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ list(APPEND SOURCE_FILES
components/settings/Settings.cpp
components/timer/TimerController.cpp
components/alarm/AlarmController.cpp
components/alert/AlertController.cpp
components/fs/FS.cpp
drivers/Cst816s.cpp
FreeRTOS/port.c
Expand Down Expand Up @@ -539,6 +540,7 @@ list(APPEND RECOVERY_SOURCE_FILES
components/settings/Settings.cpp
components/timer/TimerController.cpp
components/alarm/AlarmController.cpp
components/alert/AlertController.cpp
drivers/Cst816s.cpp
FreeRTOS/port.c
FreeRTOS/port_cmsis_systick.c
Expand Down Expand Up @@ -655,6 +657,7 @@ set(INCLUDE_FILES
components/settings/Settings.h
components/timer/TimerController.h
components/alarm/AlarmController.h
components/alert/AlertController.h
drivers/Cst816s.h
FreeRTOS/portmacro.h
FreeRTOS/portmacro_cmsis.h
Expand Down
2 changes: 1 addition & 1 deletion src/components/alarm/AlarmController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ void AlarmController::StopAlerting() {
// set next instance
ScheduleAlarm();
}
systemTask->PushMessage(System::Messages::StopRinging);
systemTask->PushMessage(System::Messages::StopAlarm);
}
74 changes: 74 additions & 0 deletions src/components/alert/AlertController.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "components/alert/AlertController.h"

using namespace Pinetime::Controllers;
using namespace Pinetime::Applications::Display;

AlertController::AlertController(MotorController& motorController) : motorController {motorController} {
}

// return true if a change has happened
bool AlertController::Update() {
if (motorController.IsVibrating())
return false;

bool ok = true;

if (phoneCallIsActive) {
ok = motorController.StartRinging(55);
} else if (timerIsActive) {
ok = motorController.StartRinging(50);
} else if (alarmIsActive) {
ok = motorController.StartRinging(45);
} else if (notificationIsActive) {
ok = motorController.SingleVibration(40);
}

return ok;
}

Messages AlertController::DisplayMessage() const {
if (timerIsActive) {
return Messages::TimerDone;
} else if (alarmIsActive) {
return Messages::AlarmTriggered;
}

return Messages::NewNotification;
}

void AlertController::ActivatePhoneCall() {
phoneCallIsActive = true;
};

void AlertController::ActivateTimer() {
timerIsActive = true;
};

void AlertController::ActivateAlarm() {
alarmIsActive = true;
};

void AlertController::ActivateNotification() {
notificationIsActive = true;
};

void AlertController::DeactivatePhoneCall() {
if (phoneCallIsActive) {
motorController.StopRinging();
}
phoneCallIsActive = false;
};

void AlertController::DeactivateTimer() {
if (!phoneCallIsActive && timerIsActive) {
motorController.StopRinging();
}
timerIsActive = false;
};

void AlertController::DeactivateAlarm() {
if (!phoneCallIsActive && !timerIsActive && alarmIsActive) {
motorController.StopRinging();
}
alarmIsActive = false;
};
38 changes: 38 additions & 0 deletions src/components/alert/AlertController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include "components/motor/MotorController.h"
#include "displayapp/Messages.h"

namespace Pinetime {
namespace Controllers {

class AlertController {
public:
AlertController(MotorController& motorController);

bool IsActive() const {
return phoneCallIsActive || timerIsActive || alarmIsActive || notificationIsActive;
}

void ActivatePhoneCall();
void ActivateTimer();
void ActivateAlarm();
void ActivateNotification();

void DeactivatePhoneCall();
void DeactivateTimer();
void DeactivateAlarm();

bool Update();
Pinetime::Applications::Display::Messages DisplayMessage() const;

private:
bool phoneCallIsActive = false;
bool timerIsActive = false;
bool alarmIsActive = false;
bool notificationIsActive = false;

MotorController& motorController;
};
}
}
24 changes: 21 additions & 3 deletions src/components/motor/MotorController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void MotorController::Init() {
nrf_gpio_cfg_output(PinMap::Motor);
nrf_gpio_pin_set(PinMap::Motor);

shortVib = xTimerCreate("shortVib", 1, pdFALSE, nullptr, StopMotor);
shortVib = xTimerCreate("shortVib", 1, pdFALSE, this, StopMotor);
longVib = xTimerCreate("longVib", pdMS_TO_TICKS(1000), pdTRUE, this, Ring);
}

Expand All @@ -20,20 +20,38 @@ void MotorController::Ring(TimerHandle_t xTimer) {

void MotorController::RunForDuration(uint8_t motorDuration) {
if (motorDuration > 0 && xTimerChangePeriod(shortVib, pdMS_TO_TICKS(motorDuration), 0) == pdPASS && xTimerStart(shortVib, 0) == pdPASS) {
isShortVibrating = true;
nrf_gpio_pin_clear(PinMap::Motor);
}
}

void MotorController::StartRinging() {
RunForDuration(50);
bool MotorController::StartRinging(uint8_t Duration) {
if (IsVibrating()) {
return false;
}
isLongVibrating = true;
RunForDuration(Duration);
xTimerStart(longVib, 0);
return true;
}

void MotorController::StopRinging() {
xTimerStop(longVib, 0);
nrf_gpio_pin_set(PinMap::Motor);
isLongVibrating = false;
}

void MotorController::StopMotor(TimerHandle_t xTimer) {
auto* motorController = static_cast<MotorController*>(pvTimerGetTimerID(xTimer));
nrf_gpio_pin_set(PinMap::Motor);
motorController->isShortVibrating = false;
}

// CAUTION: this one will not trigger a vibration if another one is already running!
bool MotorController::SingleVibration(uint8_t Duration) {
if (IsVibrating()) {
return false;
}
RunForDuration(Duration);
return true;
}
17 changes: 15 additions & 2 deletions src/components/motor/MotorController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,28 @@ namespace Pinetime {
MotorController() = default;

void Init();
void RunForDuration(uint8_t motorDuration);
void StartRinging();

// SingleVibration and StartRinging do nothing when a vibration is already running.
// they return false in this case.
// if everything went good they return true.
bool SingleVibration(uint8_t Duration);
bool StartRinging(uint8_t Duration);
void StopRinging();

bool IsVibrating() {
return isShortVibrating || isLongVibrating;
};

private:
void RunForDuration(uint8_t motorDuration);

static void Ring(TimerHandle_t xTimer);
static void StopMotor(TimerHandle_t xTimer);
TimerHandle_t shortVib;
TimerHandle_t longVib;

bool isShortVibrating = false;
bool isLongVibrating = false;
};
}
}
4 changes: 4 additions & 0 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
Pinetime::Controllers::MotionController& motionController,
Pinetime::Controllers::TimerController& timerController,
Pinetime::Controllers::AlarmController& alarmController,
Pinetime::Controllers::AlertController& alertController,
Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Controllers::TouchHandler& touchHandler,
Pinetime::Controllers::FS& filesystem)
Expand All @@ -91,6 +92,7 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
motionController {motionController},
timerController {timerController},
alarmController {alarmController},
alertController {alertController},
brightnessController {brightnessController},
touchHandler {touchHandler},
filesystem {filesystem} {
Expand Down Expand Up @@ -384,6 +386,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
notificationManager,
systemTask->nimble().alertService(),
motorController,
alertController,
*systemTask,
Screens::Notifications::Modes::Normal);
break;
Expand All @@ -392,6 +395,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
notificationManager,
systemTask->nimble().alertService(),
motorController,
alertController,
*systemTask,
Screens::Notifications::Modes::Preview);
break;
Expand Down
3 changes: 3 additions & 0 deletions src/displayapp/DisplayApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "displayapp/screens/Screen.h"
#include "components/timer/TimerController.h"
#include "components/alarm/AlarmController.h"
#include "components/alert/AlertController.h"
#include "touchhandler/TouchHandler.h"

#include "displayapp/Messages.h"
Expand Down Expand Up @@ -65,6 +66,7 @@ namespace Pinetime {
Pinetime::Controllers::MotionController& motionController,
Pinetime::Controllers::TimerController& timerController,
Pinetime::Controllers::AlarmController& alarmController,
Pinetime::Controllers::AlertController& alertController,
Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Controllers::TouchHandler& touchHandler,
Pinetime::Controllers::FS& filesystem);
Expand Down Expand Up @@ -93,6 +95,7 @@ namespace Pinetime {
Pinetime::Controllers::MotionController& motionController;
Pinetime::Controllers::TimerController& timerController;
Pinetime::Controllers::AlarmController& alarmController;
Pinetime::Controllers::AlertController& alertController;
Pinetime::Controllers::BrightnessController& brightnessController;
Pinetime::Controllers::TouchHandler& touchHandler;
Pinetime::Controllers::FS& filesystem;
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/DisplayAppRecovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
Pinetime::Controllers::MotionController& motionController,
Pinetime::Controllers::TimerController& timerController,
Pinetime::Controllers::AlarmController& alarmController,
Pinetime::Controllers::AlertController& alertController,
Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Controllers::TouchHandler& touchHandler,
Pinetime::Controllers::FS& filesystem)
Expand Down
2 changes: 2 additions & 0 deletions src/displayapp/DisplayAppRecovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <date/date.h>
#include <drivers/Watchdog.h>
#include <components/motor/MotorController.h>
#include <components/alert/AlertController.h>
#include "BootErrors.h"
#include "displayapp/TouchEvents.h"
#include "displayapp/Apps.h"
Expand Down Expand Up @@ -60,6 +61,7 @@ namespace Pinetime {
Pinetime::Controllers::MotionController& motionController,
Pinetime::Controllers::TimerController& timerController,
Pinetime::Controllers::AlarmController& alarmController,
Pinetime::Controllers::AlertController& alertController,
Pinetime::Controllers::BrightnessController& brightnessController,
Pinetime::Controllers::TouchHandler& touchHandler,
Pinetime::Controllers::FS& filesystem);
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/InfiniPaint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool InfiniPaint::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
}

std::fill(b, b + bufferSize, selectColor);
motor.RunForDuration(35);
motor.SingleVibration(35);
return true;
default:
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/displayapp/screens/Metronome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ void Metronome::Refresh() {
counter--;
if (counter == 0) {
counter = bpb;
motorController.RunForDuration(90);
motorController.SingleVibration(90);
} else {
motorController.RunForDuration(30);
motorController.SingleVibration(30);
}
}
}
Expand Down
Loading