Created basic alarm app
This commit is contained in:
parent
6f9f0e8b0e
commit
1fb5757655
|
@ -418,6 +418,7 @@ list(APPEND SOURCE_FILES
|
||||||
displayapp/screens/BatteryInfo.cpp
|
displayapp/screens/BatteryInfo.cpp
|
||||||
displayapp/screens/Steps.cpp
|
displayapp/screens/Steps.cpp
|
||||||
displayapp/screens/Timer.cpp
|
displayapp/screens/Timer.cpp
|
||||||
|
displayapp/screens/Alarm.cpp
|
||||||
displayapp/Colors.cpp
|
displayapp/Colors.cpp
|
||||||
|
|
||||||
## Settings
|
## Settings
|
||||||
|
@ -474,6 +475,7 @@ list(APPEND SOURCE_FILES
|
||||||
components/motor/MotorController.cpp
|
components/motor/MotorController.cpp
|
||||||
components/settings/Settings.cpp
|
components/settings/Settings.cpp
|
||||||
components/timer/TimerController.cpp
|
components/timer/TimerController.cpp
|
||||||
|
components/alarm/AlarmController.cpp
|
||||||
components/fs/FS.cpp
|
components/fs/FS.cpp
|
||||||
drivers/Cst816s.cpp
|
drivers/Cst816s.cpp
|
||||||
FreeRTOS/port.c
|
FreeRTOS/port.c
|
||||||
|
@ -540,6 +542,7 @@ list(APPEND RECOVERY_SOURCE_FILES
|
||||||
components/firmwarevalidator/FirmwareValidator.cpp
|
components/firmwarevalidator/FirmwareValidator.cpp
|
||||||
components/settings/Settings.cpp
|
components/settings/Settings.cpp
|
||||||
components/timer/TimerController.cpp
|
components/timer/TimerController.cpp
|
||||||
|
components/alarm/AlarmController.cpp
|
||||||
drivers/Cst816s.cpp
|
drivers/Cst816s.cpp
|
||||||
FreeRTOS/port.c
|
FreeRTOS/port.c
|
||||||
FreeRTOS/port_cmsis_systick.c
|
FreeRTOS/port_cmsis_systick.c
|
||||||
|
@ -612,6 +615,7 @@ set(INCLUDE_FILES
|
||||||
displayapp/screens/Metronome.h
|
displayapp/screens/Metronome.h
|
||||||
displayapp/screens/Motion.h
|
displayapp/screens/Motion.h
|
||||||
displayapp/screens/Timer.h
|
displayapp/screens/Timer.h
|
||||||
|
displayapp/screens/Alarm.h
|
||||||
displayapp/Colors.h
|
displayapp/Colors.h
|
||||||
drivers/St7789.h
|
drivers/St7789.h
|
||||||
drivers/SpiNorFlash.h
|
drivers/SpiNorFlash.h
|
||||||
|
@ -643,6 +647,7 @@ set(INCLUDE_FILES
|
||||||
components/ble/HeartRateService.h
|
components/ble/HeartRateService.h
|
||||||
components/settings/Settings.h
|
components/settings/Settings.h
|
||||||
components/timer/TimerController.h
|
components/timer/TimerController.h
|
||||||
|
components/alarm/AlarmController.h
|
||||||
drivers/Cst816s.h
|
drivers/Cst816s.h
|
||||||
FreeRTOS/portmacro.h
|
FreeRTOS/portmacro.h
|
||||||
FreeRTOS/portmacro_cmsis.h
|
FreeRTOS/portmacro_cmsis.h
|
||||||
|
|
118
src/components/alarm/AlarmController.cpp
Normal file
118
src/components/alarm/AlarmController.cpp
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
//
|
||||||
|
// Created by mrussell on 30.08.21.
|
||||||
|
//
|
||||||
|
// Copied from Florian's Timer app
|
||||||
|
|
||||||
|
#include "AlarmController.h"
|
||||||
|
#include "systemtask/SystemTask.h"
|
||||||
|
#include "app_timer.h"
|
||||||
|
#include "task.h"
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
using namespace Pinetime::Controllers;
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
AlarmController::AlarmController(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} {
|
||||||
|
}
|
||||||
|
|
||||||
|
APP_TIMER_DEF(alarmAppTimer);
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
void SetOffAlarm(void* p_context) {
|
||||||
|
auto* controller = static_cast<Pinetime::Controllers::AlarmController*>(p_context);
|
||||||
|
if (controller != nullptr)
|
||||||
|
controller->SetOffAlarmNow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AlarmController::Init() {
|
||||||
|
app_timer_create(&alarmAppTimer, APP_TIMER_MODE_SINGLE_SHOT, SetOffAlarm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AlarmController::SetAlarm(uint8_t alarmHr, uint8_t alarmMin) {
|
||||||
|
hours = alarmHr;
|
||||||
|
minutes = alarmMin;
|
||||||
|
state = AlarmState::Set;
|
||||||
|
scheduleAlarm();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AlarmController::scheduleAlarm() {
|
||||||
|
// Determine the next time the alarm needs to go off and set the app_timer
|
||||||
|
app_timer_stop(alarmAppTimer);
|
||||||
|
|
||||||
|
auto now = dateTimeController.CurrentDateTime();
|
||||||
|
alarmTime = now;
|
||||||
|
time_t ttAlarmTime = std::chrono::system_clock::to_time_t(alarmTime);
|
||||||
|
tm* tmAlarmTime = std::localtime(&ttAlarmTime);
|
||||||
|
|
||||||
|
// If the time being set has already passed today,the alarm should be set for tomorrow
|
||||||
|
if (hours < dateTimeController.Hours() || (hours == dateTimeController.Hours() && minutes <= dateTimeController.Minutes())) {
|
||||||
|
tmAlarmTime->tm_mday += 1;
|
||||||
|
// tm_wday doesn't update automatically
|
||||||
|
tmAlarmTime->tm_wday = (tmAlarmTime->tm_wday + 1) % 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
tmAlarmTime->tm_hour = hours;
|
||||||
|
tmAlarmTime->tm_min = minutes;
|
||||||
|
tmAlarmTime->tm_sec = 0;
|
||||||
|
|
||||||
|
// if alarm is in weekday-only mode, make sure it shifts to the next weekday
|
||||||
|
if (recurrence == RecurType::Weekdays) {
|
||||||
|
if (tmAlarmTime->tm_wday == 0) { // Sunday, shift 1 day
|
||||||
|
tmAlarmTime->tm_mday += 1;
|
||||||
|
} else if (tmAlarmTime->tm_wday == 6) { // Saturday, shift 2 days
|
||||||
|
tmAlarmTime->tm_mday += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tmAlarmTime->tm_isdst = -1; // use system timezone setting to determine DST
|
||||||
|
|
||||||
|
// now can convert back to a time_point
|
||||||
|
alarmTime = std::chrono::system_clock::from_time_t(std::mktime(tmAlarmTime));
|
||||||
|
auto mSecToAlarm = std::chrono::duration_cast<std::chrono::milliseconds>(alarmTime - now).count();
|
||||||
|
app_timer_start(alarmAppTimer, APP_TIMER_TICKS(mSecToAlarm), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t AlarmController::SecondsToAlarm() {
|
||||||
|
return std::chrono::duration_cast<std::chrono::seconds>(alarmTime - dateTimeController.CurrentDateTime()).count();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AlarmController::DisableAlarm() {
|
||||||
|
app_timer_stop(alarmAppTimer);
|
||||||
|
state = AlarmState::Not_Set;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AlarmController::SetOffAlarmNow() {
|
||||||
|
state = AlarmState::Alerting;
|
||||||
|
if (systemTask != nullptr) {
|
||||||
|
systemTask->PushMessage(System::Messages::SetOffAlarm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AlarmController::StopAlerting() {
|
||||||
|
if (systemTask != nullptr) {
|
||||||
|
systemTask->PushMessage(System::Messages::StopRinging);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alarm state is off unless this is a recurring alarm
|
||||||
|
if (recurrence == RecurType::None) {
|
||||||
|
state = AlarmState::Not_Set;
|
||||||
|
} else {
|
||||||
|
state = AlarmState::Set;
|
||||||
|
// set next instance
|
||||||
|
scheduleAlarm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AlarmController::ToggleRecurrence() {
|
||||||
|
if (recurrence == AlarmController::RecurType::None) {
|
||||||
|
recurrence = AlarmController::RecurType::Daily;
|
||||||
|
} else if (recurrence == AlarmController::RecurType::Daily) {
|
||||||
|
recurrence = AlarmController::RecurType::Weekdays;
|
||||||
|
} else {
|
||||||
|
recurrence = AlarmController::RecurType::None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AlarmController::Register(Pinetime::System::SystemTask* systemTask) {
|
||||||
|
this->systemTask = systemTask;
|
||||||
|
}
|
50
src/components/alarm/AlarmController.h
Normal file
50
src/components/alarm/AlarmController.h
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include "app_timer.h"
|
||||||
|
#include "components/datetime/DateTimeController.h"
|
||||||
|
|
||||||
|
namespace Pinetime {
|
||||||
|
namespace System {
|
||||||
|
class SystemTask;
|
||||||
|
}
|
||||||
|
namespace Controllers {
|
||||||
|
class AlarmController {
|
||||||
|
public:
|
||||||
|
AlarmController(Controllers::DateTime& dateTimeController);
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
void SetAlarm(uint8_t alarmHr, uint8_t alarmMin);
|
||||||
|
void DisableAlarm();
|
||||||
|
void SetOffAlarmNow();
|
||||||
|
uint32_t SecondsToAlarm();
|
||||||
|
void StopAlerting();
|
||||||
|
void Register(System::SystemTask* systemTask);
|
||||||
|
enum class AlarmState { Not_Set, Set, Alerting };
|
||||||
|
enum class RecurType { None, Daily, Weekdays };
|
||||||
|
void ToggleRecurrence();
|
||||||
|
uint8_t Hours() const {
|
||||||
|
return hours;
|
||||||
|
}
|
||||||
|
uint8_t Minutes() const {
|
||||||
|
return minutes;
|
||||||
|
}
|
||||||
|
AlarmState State() const {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
RecurType Recurrence() const {
|
||||||
|
return recurrence;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Controllers::DateTime& dateTimeController;
|
||||||
|
System::SystemTask* systemTask = nullptr;
|
||||||
|
uint8_t hours;
|
||||||
|
uint8_t minutes;
|
||||||
|
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> alarmTime;
|
||||||
|
AlarmState state = AlarmState::Not_Set;
|
||||||
|
RecurType recurrence = RecurType::None;
|
||||||
|
void scheduleAlarm();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -42,6 +42,12 @@ void MotorController::StartRinging() {
|
||||||
app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
|
app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function is the same as StartRinging(), but will ring even if notifications are turned off in Settings
|
||||||
|
void MotorController::StartRingingDisregardSettings() {
|
||||||
|
Ring(this);
|
||||||
|
app_timer_start(longVibTimer, APP_TIMER_TICKS(1000), this);
|
||||||
|
}
|
||||||
|
|
||||||
void MotorController::StopRinging() {
|
void MotorController::StopRinging() {
|
||||||
app_timer_stop(longVibTimer);
|
app_timer_stop(longVibTimer);
|
||||||
nrf_gpio_pin_set(pinMotor);
|
nrf_gpio_pin_set(pinMotor);
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace Pinetime {
|
||||||
void RunForDuration(uint8_t motorDuration);
|
void RunForDuration(uint8_t motorDuration);
|
||||||
void StartRinging();
|
void StartRinging();
|
||||||
static void StopRinging();
|
static void StopRinging();
|
||||||
|
void StartRingingDisregardSettings();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void Ring(void* p_context);
|
static void Ring(void* p_context);
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace Pinetime {
|
||||||
NotificationsPreview,
|
NotificationsPreview,
|
||||||
Notifications,
|
Notifications,
|
||||||
Timer,
|
Timer,
|
||||||
|
Alarm,
|
||||||
FlashLight,
|
FlashLight,
|
||||||
BatteryInfo,
|
BatteryInfo,
|
||||||
Music,
|
Music,
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <displayapp/screens/HeartRate.h>
|
#include <displayapp/screens/HeartRate.h>
|
||||||
#include <displayapp/screens/Motion.h>
|
#include <displayapp/screens/Motion.h>
|
||||||
#include <displayapp/screens/Timer.h>
|
#include <displayapp/screens/Timer.h>
|
||||||
|
#include <displayapp/screens/Alarm.h>
|
||||||
#include "components/battery/BatteryController.h"
|
#include "components/battery/BatteryController.h"
|
||||||
#include "components/ble/BleController.h"
|
#include "components/ble/BleController.h"
|
||||||
#include "components/datetime/DateTimeController.h"
|
#include "components/datetime/DateTimeController.h"
|
||||||
|
@ -90,6 +91,7 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
||||||
Pinetime::Controllers::MotorController& motorController,
|
Pinetime::Controllers::MotorController& motorController,
|
||||||
Pinetime::Controllers::MotionController& motionController,
|
Pinetime::Controllers::MotionController& motionController,
|
||||||
Pinetime::Controllers::TimerController& timerController,
|
Pinetime::Controllers::TimerController& timerController,
|
||||||
|
Pinetime::Controllers::AlarmController& alarmController,
|
||||||
Pinetime::Controllers::TouchHandler& touchHandler)
|
Pinetime::Controllers::TouchHandler& touchHandler)
|
||||||
: lcd {lcd},
|
: lcd {lcd},
|
||||||
lvgl {lvgl},
|
lvgl {lvgl},
|
||||||
|
@ -104,6 +106,7 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
||||||
motorController {motorController},
|
motorController {motorController},
|
||||||
motionController {motionController},
|
motionController {motionController},
|
||||||
timerController {timerController},
|
timerController {timerController},
|
||||||
|
alarmController {alarmController},
|
||||||
touchHandler {touchHandler} {
|
touchHandler {touchHandler} {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,6 +211,13 @@ void DisplayApp::Refresh() {
|
||||||
LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down);
|
LoadApp(Apps::Timer, DisplayApp::FullRefreshDirections::Down);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case Messages::AlarmTriggered:
|
||||||
|
if (currentApp == Apps::Alarm) {
|
||||||
|
auto* alarm = static_cast<Screens::Alarm*>(currentScreen.get());
|
||||||
|
alarm->SetAlerting();
|
||||||
|
} else {
|
||||||
|
LoadApp(Apps::Alarm, DisplayApp::FullRefreshDirections::None);
|
||||||
|
}
|
||||||
case Messages::TouchEvent: {
|
case Messages::TouchEvent: {
|
||||||
if (state != States::Running) {
|
if (state != States::Running) {
|
||||||
break;
|
break;
|
||||||
|
@ -340,6 +350,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
|
||||||
case Apps::Timer:
|
case Apps::Timer:
|
||||||
currentScreen = std::make_unique<Screens::Timer>(this, timerController);
|
currentScreen = std::make_unique<Screens::Timer>(this, timerController);
|
||||||
break;
|
break;
|
||||||
|
case Apps::Alarm:
|
||||||
|
currentScreen = std::make_unique<Screens::Alarm>(this, alarmController);
|
||||||
|
break;
|
||||||
|
|
||||||
// Settings
|
// Settings
|
||||||
case Apps::QuickSettings:
|
case Apps::QuickSettings:
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
#include "components/settings/Settings.h"
|
#include "components/settings/Settings.h"
|
||||||
#include "displayapp/screens/Screen.h"
|
#include "displayapp/screens/Screen.h"
|
||||||
#include "components/timer/TimerController.h"
|
#include "components/timer/TimerController.h"
|
||||||
|
#include "components/alarm/AlarmController.h"
|
||||||
#include "touchhandler/TouchHandler.h"
|
#include "touchhandler/TouchHandler.h"
|
||||||
|
|
||||||
#include "Messages.h"
|
#include "Messages.h"
|
||||||
|
|
||||||
namespace Pinetime {
|
namespace Pinetime {
|
||||||
|
@ -57,6 +59,7 @@ namespace Pinetime {
|
||||||
Pinetime::Controllers::MotorController& motorController,
|
Pinetime::Controllers::MotorController& motorController,
|
||||||
Pinetime::Controllers::MotionController& motionController,
|
Pinetime::Controllers::MotionController& motionController,
|
||||||
Pinetime::Controllers::TimerController& timerController,
|
Pinetime::Controllers::TimerController& timerController,
|
||||||
|
Pinetime::Controllers::AlarmController& alarmController,
|
||||||
Pinetime::Controllers::TouchHandler& touchHandler);
|
Pinetime::Controllers::TouchHandler& touchHandler);
|
||||||
void Start();
|
void Start();
|
||||||
void PushMessage(Display::Messages msg);
|
void PushMessage(Display::Messages msg);
|
||||||
|
@ -82,6 +85,7 @@ namespace Pinetime {
|
||||||
Pinetime::Controllers::MotorController& motorController;
|
Pinetime::Controllers::MotorController& motorController;
|
||||||
Pinetime::Controllers::MotionController& motionController;
|
Pinetime::Controllers::MotionController& motionController;
|
||||||
Pinetime::Controllers::TimerController& timerController;
|
Pinetime::Controllers::TimerController& timerController;
|
||||||
|
Pinetime::Controllers::AlarmController& alarmController;
|
||||||
Pinetime::Controllers::TouchHandler& touchHandler;
|
Pinetime::Controllers::TouchHandler& touchHandler;
|
||||||
|
|
||||||
Pinetime::Controllers::FirmwareValidator validator;
|
Pinetime::Controllers::FirmwareValidator validator;
|
||||||
|
|
|
@ -15,7 +15,8 @@ namespace Pinetime {
|
||||||
BleFirmwareUpdateStarted,
|
BleFirmwareUpdateStarted,
|
||||||
UpdateTimeOut,
|
UpdateTimeOut,
|
||||||
DimScreen,
|
DimScreen,
|
||||||
RestoreBrightness
|
RestoreBrightness,
|
||||||
|
AlarmTriggered
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
225
src/displayapp/screens/Alarm.cpp
Normal file
225
src/displayapp/screens/Alarm.cpp
Normal file
|
@ -0,0 +1,225 @@
|
||||||
|
#include "Alarm.h"
|
||||||
|
#include "Screen.h"
|
||||||
|
#include "Symbols.h"
|
||||||
|
|
||||||
|
using namespace Pinetime::Applications::Screens;
|
||||||
|
using Pinetime::Controllers::AlarmController;
|
||||||
|
|
||||||
|
static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
|
||||||
|
Alarm* screen = static_cast<Alarm*>(obj->user_data);
|
||||||
|
screen->OnButtonEvent(obj, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController)
|
||||||
|
: Screen(app), running {true}, alarmController {alarmController} {
|
||||||
|
|
||||||
|
time = lv_label_create(lv_scr_act(), nullptr);
|
||||||
|
lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
|
||||||
|
lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
||||||
|
|
||||||
|
alarmHours = alarmController.Hours();
|
||||||
|
alarmMinutes = alarmController.Minutes();
|
||||||
|
lv_label_set_text_fmt(time, "%02lu:%02lu", alarmHours, alarmMinutes);
|
||||||
|
|
||||||
|
lv_obj_align(time, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 0, -20);
|
||||||
|
|
||||||
|
btnHoursUp = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
|
btnHoursUp->user_data = this;
|
||||||
|
lv_obj_set_event_cb(btnHoursUp, btnEventHandler);
|
||||||
|
lv_obj_align(btnHoursUp, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, -80);
|
||||||
|
lv_obj_set_height(btnHoursUp, 40);
|
||||||
|
lv_obj_set_width(btnHoursUp, 60);
|
||||||
|
txtHrUp = lv_label_create(btnHoursUp, nullptr);
|
||||||
|
lv_label_set_text(txtHrUp, "+");
|
||||||
|
|
||||||
|
btnHoursDown = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
|
btnHoursDown->user_data = this;
|
||||||
|
lv_obj_set_event_cb(btnHoursDown, btnEventHandler);
|
||||||
|
lv_obj_align(btnHoursDown, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, +40);
|
||||||
|
lv_obj_set_height(btnHoursDown, 40);
|
||||||
|
lv_obj_set_width(btnHoursDown, 60);
|
||||||
|
txtHrDown = lv_label_create(btnHoursDown, nullptr);
|
||||||
|
lv_label_set_text(txtHrDown, "-");
|
||||||
|
|
||||||
|
btnMinutesUp = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
|
btnMinutesUp->user_data = this;
|
||||||
|
lv_obj_set_event_cb(btnMinutesUp, btnEventHandler);
|
||||||
|
lv_obj_align(btnMinutesUp, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 10, -80);
|
||||||
|
lv_obj_set_height(btnMinutesUp, 40);
|
||||||
|
lv_obj_set_width(btnMinutesUp, 60);
|
||||||
|
txtMinUp = lv_label_create(btnMinutesUp, nullptr);
|
||||||
|
lv_label_set_text(txtMinUp, "+");
|
||||||
|
|
||||||
|
btnMinutesDown = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
|
btnMinutesDown->user_data = this;
|
||||||
|
lv_obj_set_event_cb(btnMinutesDown, btnEventHandler);
|
||||||
|
lv_obj_align(btnMinutesDown, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, 10, +40);
|
||||||
|
lv_obj_set_height(btnMinutesDown, 40);
|
||||||
|
lv_obj_set_width(btnMinutesDown, 60);
|
||||||
|
txtMinDown = lv_label_create(btnMinutesDown, nullptr);
|
||||||
|
lv_label_set_text(txtMinDown, "-");
|
||||||
|
|
||||||
|
btnEnable = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
|
btnEnable->user_data = this;
|
||||||
|
lv_obj_set_event_cb(btnEnable, btnEventHandler);
|
||||||
|
lv_obj_align(btnEnable, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 3, -10);
|
||||||
|
lv_obj_set_height(btnEnable, 40);
|
||||||
|
txtEnable = lv_label_create(btnEnable, nullptr);
|
||||||
|
setEnableButtonState();
|
||||||
|
|
||||||
|
btnRecur = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
|
btnRecur->user_data = this;
|
||||||
|
lv_obj_set_event_cb(btnRecur, btnEventHandler);
|
||||||
|
lv_obj_align(btnRecur, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, -3, -10);
|
||||||
|
lv_obj_set_height(btnRecur, 40);
|
||||||
|
txtRecur = lv_label_create(btnRecur, nullptr);
|
||||||
|
setRecurButtonState();
|
||||||
|
|
||||||
|
btnInfo = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
|
btnInfo->user_data = this;
|
||||||
|
lv_obj_set_event_cb(btnInfo, btnEventHandler);
|
||||||
|
lv_obj_align(btnInfo, lv_scr_act(), LV_ALIGN_CENTER, 30, -80);
|
||||||
|
lv_obj_set_height(btnInfo, 40);
|
||||||
|
lv_obj_set_width(btnInfo, 30);
|
||||||
|
txtInfo = lv_label_create(btnInfo, nullptr);
|
||||||
|
lv_label_set_text(txtInfo, "i");
|
||||||
|
}
|
||||||
|
|
||||||
|
Alarm::~Alarm() {
|
||||||
|
lv_obj_clean(lv_scr_act());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
|
||||||
|
using Pinetime::Controllers::AlarmController;
|
||||||
|
if (event == LV_EVENT_CLICKED) {
|
||||||
|
if (obj == btnEnable) {
|
||||||
|
if (alarmController.State() == AlarmController::AlarmState::Alerting) {
|
||||||
|
alarmController.StopAlerting();
|
||||||
|
} else if (alarmController.State() == AlarmController::AlarmState::Set) {
|
||||||
|
alarmController.DisableAlarm();
|
||||||
|
} else {
|
||||||
|
alarmController.SetAlarm(alarmHours, alarmMinutes);
|
||||||
|
}
|
||||||
|
setEnableButtonState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (obj == btnInfo) {
|
||||||
|
showInfo();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (obj == btnMessage) {
|
||||||
|
lv_obj_del(txtMessage);
|
||||||
|
lv_obj_del(btnMessage);
|
||||||
|
txtMessage = nullptr;
|
||||||
|
btnMessage = nullptr;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// If any other button was pressed, disable the alarm
|
||||||
|
// this is to make it clear that the alarm won't be set until it is turned back on
|
||||||
|
// this avoids calling the AlarmController to change the alarm time every time the user hits minute-up or minute-down;
|
||||||
|
// can just do it once when the alarm is re-enabled
|
||||||
|
if (alarmController.State() == AlarmController::AlarmState::Set) {
|
||||||
|
alarmController.DisableAlarm();
|
||||||
|
setEnableButtonState();
|
||||||
|
}
|
||||||
|
if (obj == btnMinutesUp) {
|
||||||
|
if (alarmMinutes >= 59) {
|
||||||
|
alarmMinutes = 0;
|
||||||
|
} else {
|
||||||
|
alarmMinutes++;
|
||||||
|
}
|
||||||
|
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (obj == btnMinutesDown) {
|
||||||
|
if (alarmMinutes == 0) {
|
||||||
|
alarmMinutes = 59;
|
||||||
|
} else {
|
||||||
|
alarmMinutes--;
|
||||||
|
}
|
||||||
|
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (obj == btnHoursUp) {
|
||||||
|
if (alarmHours >= 23) {
|
||||||
|
alarmHours = 0;
|
||||||
|
} else {
|
||||||
|
alarmHours++;
|
||||||
|
}
|
||||||
|
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (obj == btnHoursDown) {
|
||||||
|
if (alarmHours == 0) {
|
||||||
|
alarmHours = 23;
|
||||||
|
} else {
|
||||||
|
alarmHours--;
|
||||||
|
}
|
||||||
|
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (obj == btnRecur) {
|
||||||
|
alarmController.ToggleRecurrence();
|
||||||
|
setRecurButtonState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Alarm::SetAlerting() {
|
||||||
|
setEnableButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Alarm::setEnableButtonState() {
|
||||||
|
switch (alarmController.State()) {
|
||||||
|
case AlarmController::AlarmState::Set:
|
||||||
|
lv_label_set_text(txtEnable, "ON");
|
||||||
|
lv_obj_set_style_local_bg_color(btnEnable, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
|
||||||
|
break;
|
||||||
|
case AlarmController::AlarmState::Not_Set:
|
||||||
|
lv_label_set_text(txtEnable, "OFF");
|
||||||
|
lv_obj_set_style_local_bg_color(btnEnable, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
||||||
|
break;
|
||||||
|
case AlarmController::AlarmState::Alerting:
|
||||||
|
lv_label_set_text(txtEnable, Symbols::stop);
|
||||||
|
lv_obj_set_style_local_bg_color(btnEnable, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Alarm::showInfo() {
|
||||||
|
btnMessage = lv_btn_create(lv_scr_act(), nullptr);
|
||||||
|
btnMessage->user_data = this;
|
||||||
|
lv_obj_set_event_cb(btnMessage, btnEventHandler);
|
||||||
|
lv_obj_set_height(btnMessage, 200);
|
||||||
|
lv_obj_set_width(btnMessage, 150);
|
||||||
|
lv_obj_align(btnMessage, lv_scr_act(), LV_ALIGN_CENTER, 0, 0);
|
||||||
|
txtMessage = lv_label_create(btnMessage, nullptr);
|
||||||
|
lv_obj_set_style_local_bg_color(btnMessage, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_NAVY);
|
||||||
|
|
||||||
|
if (alarmController.State() == AlarmController::AlarmState::Set) {
|
||||||
|
auto timeToAlarm = alarmController.SecondsToAlarm();
|
||||||
|
|
||||||
|
auto daysToAlarm = timeToAlarm / 86400;
|
||||||
|
auto hrsToAlarm = (timeToAlarm % 86400) / 3600;
|
||||||
|
auto minToAlarm = (timeToAlarm % 3600) / 60;
|
||||||
|
auto secToAlarm = timeToAlarm % 60;
|
||||||
|
|
||||||
|
lv_label_set_text_fmt(
|
||||||
|
txtMessage, "Time to\nalarm:\n%2d Days\n%2d Hours\n%2d Minutes\n%2d Seconds", daysToAlarm, hrsToAlarm, minToAlarm, secToAlarm);
|
||||||
|
} else {
|
||||||
|
lv_label_set_text(txtMessage, "Alarm\nis not\nset.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Alarm::setRecurButtonState() {
|
||||||
|
using Pinetime::Controllers::AlarmController;
|
||||||
|
switch (alarmController.Recurrence()) {
|
||||||
|
case AlarmController::RecurType::None:
|
||||||
|
lv_label_set_text(txtRecur, "ONCE");
|
||||||
|
break;
|
||||||
|
case AlarmController::RecurType::Daily:
|
||||||
|
lv_label_set_text(txtRecur, "DAILY");
|
||||||
|
break;
|
||||||
|
case AlarmController::RecurType::Weekdays:
|
||||||
|
lv_label_set_text(txtRecur, "WKDAYS");
|
||||||
|
}
|
||||||
|
}
|
31
src/displayapp/screens/Alarm.h
Normal file
31
src/displayapp/screens/Alarm.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Screen.h"
|
||||||
|
#include "systemtask/SystemTask.h"
|
||||||
|
#include "../LittleVgl.h"
|
||||||
|
#include "components/alarm/AlarmController.h"
|
||||||
|
|
||||||
|
namespace Pinetime::Applications::Screens {
|
||||||
|
class Alarm : public Screen {
|
||||||
|
public:
|
||||||
|
Alarm(DisplayApp* app, Controllers::AlarmController& alarmController);
|
||||||
|
~Alarm() override;
|
||||||
|
void SetAlerting();
|
||||||
|
void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool running;
|
||||||
|
uint8_t alarmHours = 0;
|
||||||
|
uint8_t alarmMinutes = 0;
|
||||||
|
Controllers::AlarmController& alarmController;
|
||||||
|
|
||||||
|
lv_obj_t *time, *btnEnable, *txtEnable, *btnMinutesUp, *btnMinutesDown, *btnHoursUp, *btnHoursDown, *txtMinUp, *txtMinDown, *txtHrUp,
|
||||||
|
*txtHrDown, *btnRecur, *txtRecur, *btnMessage, *txtMessage, *btnInfo, *txtInfo;
|
||||||
|
|
||||||
|
enum class EnableButtonState { On, Off, Alerting };
|
||||||
|
void setEnableButtonState();
|
||||||
|
void setRecurButtonState();
|
||||||
|
void setAlarm();
|
||||||
|
void showInfo();
|
||||||
|
};
|
||||||
|
}
|
|
@ -58,7 +58,7 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
|
||||||
{"2", Apps::Twos},
|
{"2", Apps::Twos},
|
||||||
{Symbols::chartLine, Apps::Motion},
|
{Symbols::chartLine, Apps::Motion},
|
||||||
{Symbols::drum, Apps::Metronome},
|
{Symbols::drum, Apps::Metronome},
|
||||||
{"", Apps::None},
|
{Symbols::clock, Apps::Alarm},
|
||||||
}};
|
}};
|
||||||
|
|
||||||
return std::make_unique<Screens::Tile>(1, 2, app, settingsController, batteryController, dateTimeController, applications);
|
return std::make_unique<Screens::Tile>(1, 2, app, settingsController, batteryController, dateTimeController, applications);
|
||||||
|
|
|
@ -119,6 +119,7 @@ Pinetime::Drivers::WatchdogView watchdogView(watchdog);
|
||||||
Pinetime::Controllers::NotificationManager notificationManager;
|
Pinetime::Controllers::NotificationManager notificationManager;
|
||||||
Pinetime::Controllers::MotionController motionController;
|
Pinetime::Controllers::MotionController motionController;
|
||||||
Pinetime::Controllers::TimerController timerController;
|
Pinetime::Controllers::TimerController timerController;
|
||||||
|
Pinetime::Controllers::AlarmController alarmController {dateTimeController};
|
||||||
Pinetime::Controllers::TouchHandler touchHandler(touchPanel, lvgl);
|
Pinetime::Controllers::TouchHandler touchHandler(touchPanel, lvgl);
|
||||||
|
|
||||||
Pinetime::Controllers::FS fs {spiNorFlash};
|
Pinetime::Controllers::FS fs {spiNorFlash};
|
||||||
|
@ -139,6 +140,7 @@ Pinetime::Applications::DisplayApp displayApp(lcd,
|
||||||
motorController,
|
motorController,
|
||||||
motionController,
|
motionController,
|
||||||
timerController,
|
timerController,
|
||||||
|
alarmController,
|
||||||
touchHandler);
|
touchHandler);
|
||||||
|
|
||||||
Pinetime::System::SystemTask systemTask(spi,
|
Pinetime::System::SystemTask systemTask(spi,
|
||||||
|
@ -151,6 +153,7 @@ Pinetime::System::SystemTask systemTask(spi,
|
||||||
bleController,
|
bleController,
|
||||||
dateTimeController,
|
dateTimeController,
|
||||||
timerController,
|
timerController,
|
||||||
|
alarmController,
|
||||||
watchdog,
|
watchdog,
|
||||||
notificationManager,
|
notificationManager,
|
||||||
motorController,
|
motorController,
|
||||||
|
|
|
@ -20,7 +20,9 @@ namespace Pinetime {
|
||||||
EnableSleeping,
|
EnableSleeping,
|
||||||
DisableSleeping,
|
DisableSleeping,
|
||||||
OnNewDay,
|
OnNewDay,
|
||||||
OnChargingEvent
|
OnChargingEvent,
|
||||||
|
SetOffAlarm,
|
||||||
|
StopRinging
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,6 +57,7 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
|
||||||
Controllers::Ble& bleController,
|
Controllers::Ble& bleController,
|
||||||
Controllers::DateTime& dateTimeController,
|
Controllers::DateTime& dateTimeController,
|
||||||
Controllers::TimerController& timerController,
|
Controllers::TimerController& timerController,
|
||||||
|
Controllers::AlarmController& alarmController,
|
||||||
Drivers::Watchdog& watchdog,
|
Drivers::Watchdog& watchdog,
|
||||||
Pinetime::Controllers::NotificationManager& notificationManager,
|
Pinetime::Controllers::NotificationManager& notificationManager,
|
||||||
Pinetime::Controllers::MotorController& motorController,
|
Pinetime::Controllers::MotorController& motorController,
|
||||||
|
@ -79,6 +80,7 @@ SystemTask::SystemTask(Drivers::SpiMaster& spi,
|
||||||
bleController {bleController},
|
bleController {bleController},
|
||||||
dateTimeController {dateTimeController},
|
dateTimeController {dateTimeController},
|
||||||
timerController {timerController},
|
timerController {timerController},
|
||||||
|
alarmController {alarmController},
|
||||||
watchdog {watchdog},
|
watchdog {watchdog},
|
||||||
notificationManager {notificationManager},
|
notificationManager {notificationManager},
|
||||||
motorController {motorController},
|
motorController {motorController},
|
||||||
|
@ -132,6 +134,8 @@ void SystemTask::Work() {
|
||||||
motionSensor.SoftReset();
|
motionSensor.SoftReset();
|
||||||
timerController.Register(this);
|
timerController.Register(this);
|
||||||
timerController.Init();
|
timerController.Init();
|
||||||
|
alarmController.Register(this);
|
||||||
|
alarmController.Init();
|
||||||
|
|
||||||
// Reset the TWI device because the motion sensor chip most probably crashed it...
|
// Reset the TWI device because the motion sensor chip most probably crashed it...
|
||||||
twiMaster.Sleep();
|
twiMaster.Sleep();
|
||||||
|
@ -275,6 +279,16 @@ void SystemTask::Work() {
|
||||||
motorController.RunForDuration(35);
|
motorController.RunForDuration(35);
|
||||||
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::TimerDone);
|
||||||
break;
|
break;
|
||||||
|
case Messages::SetOffAlarm:
|
||||||
|
if (isSleeping && !isWakingUp) {
|
||||||
|
GoToRunning();
|
||||||
|
}
|
||||||
|
motorController.StartRingingDisregardSettings();
|
||||||
|
displayApp.PushMessage(Pinetime::Applications::Display::Messages::AlarmTriggered);
|
||||||
|
break;
|
||||||
|
case Messages::StopRinging:
|
||||||
|
motorController.StopRinging();
|
||||||
|
break;
|
||||||
case Messages::BleConnected:
|
case Messages::BleConnected:
|
||||||
ReloadIdleTimer();
|
ReloadIdleTimer();
|
||||||
isBleDiscoveryTimerRunning = true;
|
isBleDiscoveryTimerRunning = true;
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "components/ble/NotificationManager.h"
|
#include "components/ble/NotificationManager.h"
|
||||||
#include "components/motor/MotorController.h"
|
#include "components/motor/MotorController.h"
|
||||||
#include "components/timer/TimerController.h"
|
#include "components/timer/TimerController.h"
|
||||||
|
#include "components/alarm/AlarmController.h"
|
||||||
#include "components/fs/FS.h"
|
#include "components/fs/FS.h"
|
||||||
#include "touchhandler/TouchHandler.h"
|
#include "touchhandler/TouchHandler.h"
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ namespace Pinetime {
|
||||||
Controllers::Ble& bleController,
|
Controllers::Ble& bleController,
|
||||||
Controllers::DateTime& dateTimeController,
|
Controllers::DateTime& dateTimeController,
|
||||||
Controllers::TimerController& timerController,
|
Controllers::TimerController& timerController,
|
||||||
|
Controllers::AlarmController& alarmController,
|
||||||
Drivers::Watchdog& watchdog,
|
Drivers::Watchdog& watchdog,
|
||||||
Pinetime::Controllers::NotificationManager& notificationManager,
|
Pinetime::Controllers::NotificationManager& notificationManager,
|
||||||
Pinetime::Controllers::MotorController& motorController,
|
Pinetime::Controllers::MotorController& motorController,
|
||||||
|
@ -100,6 +102,7 @@ namespace Pinetime {
|
||||||
Pinetime::Controllers::Ble& bleController;
|
Pinetime::Controllers::Ble& bleController;
|
||||||
Pinetime::Controllers::DateTime& dateTimeController;
|
Pinetime::Controllers::DateTime& dateTimeController;
|
||||||
Pinetime::Controllers::TimerController& timerController;
|
Pinetime::Controllers::TimerController& timerController;
|
||||||
|
Pinetime::Controllers::AlarmController& alarmController;
|
||||||
QueueHandle_t systemTasksMsgQueue;
|
QueueHandle_t systemTasksMsgQueue;
|
||||||
std::atomic<bool> isSleeping {false};
|
std::atomic<bool> isSleeping {false};
|
||||||
std::atomic<bool> isGoingToSleep {false};
|
std::atomic<bool> isGoingToSleep {false};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user