Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
currentScreen = std::make_unique<Screens::Timer>(this, timerController);
break;
case Apps::Alarm:
currentScreen = std::make_unique<Screens::Alarm>(this, alarmController, settingsController, *systemTask);
currentScreen = std::make_unique<Screens::Alarm>(this, alarmController, settingsController.GetClockType(), *systemTask);
break;

// Settings
Expand Down
184 changes: 66 additions & 118 deletions src/displayapp/screens/Alarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
using namespace Pinetime::Applications::Screens;
using Pinetime::Controllers::AlarmController;

namespace {
void ValueChangedHandler(void* userData) {
auto* screen = static_cast<Alarm*>(userData);
screen->OnValueChanged();
}
}

static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
auto* screen = static_cast<Alarm*>(obj->user_data);
screen->OnButtonEvent(obj, event);
Expand All @@ -34,58 +41,33 @@ static void StopAlarmTaskCallback(lv_task_t* task) {

Alarm::Alarm(DisplayApp* app,
Controllers::AlarmController& alarmController,
Pinetime::Controllers::Settings& settingsController,
Controllers::Settings::ClockType clockType,
System::SystemTask& systemTask)
: Screen(app), alarmController {alarmController}, settingsController {settingsController}, systemTask {systemTask} {

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_MAKE(0xb0, 0xb0, 0xb0));

alarmHours = alarmController.Hours();
alarmMinutes = alarmController.Minutes();
lv_label_set_text_fmt(time, "%02hhu:%02hhu", alarmHours, alarmMinutes);

lv_obj_align(time, lv_scr_act(), LV_ALIGN_CENTER, 0, -25);

lblampm = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
lv_obj_set_style_local_text_color(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0));
lv_label_set_text_static(lblampm, " ");
lv_label_set_align(lblampm, LV_LABEL_ALIGN_CENTER);
lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, 0, 30);

btnHoursUp = lv_btn_create(lv_scr_act(), nullptr);
btnHoursUp->user_data = this;
lv_obj_set_event_cb(btnHoursUp, btnEventHandler);
lv_obj_set_size(btnHoursUp, 60, 40);
lv_obj_align(btnHoursUp, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, -85);
txtHrUp = lv_label_create(btnHoursUp, nullptr);
lv_label_set_text_static(txtHrUp, "+");

btnHoursDown = lv_btn_create(lv_scr_act(), nullptr);
btnHoursDown->user_data = this;
lv_obj_set_event_cb(btnHoursDown, btnEventHandler);
lv_obj_set_size(btnHoursDown, 60, 40);
lv_obj_align(btnHoursDown, lv_scr_act(), LV_ALIGN_IN_LEFT_MID, 20, 35);
txtHrDown = lv_label_create(btnHoursDown, nullptr);
lv_label_set_text_static(txtHrDown, "-");

btnMinutesUp = lv_btn_create(lv_scr_act(), nullptr);
btnMinutesUp->user_data = this;
lv_obj_set_event_cb(btnMinutesUp, btnEventHandler);
lv_obj_set_size(btnMinutesUp, 60, 40);
lv_obj_align(btnMinutesUp, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, -85);
txtMinUp = lv_label_create(btnMinutesUp, nullptr);
lv_label_set_text_static(txtMinUp, "+");

btnMinutesDown = lv_btn_create(lv_scr_act(), nullptr);
btnMinutesDown->user_data = this;
lv_obj_set_event_cb(btnMinutesDown, btnEventHandler);
lv_obj_set_size(btnMinutesDown, 60, 40);
lv_obj_align(btnMinutesDown, lv_scr_act(), LV_ALIGN_IN_RIGHT_MID, -20, 35);
txtMinDown = lv_label_create(btnMinutesDown, nullptr);
lv_label_set_text_static(txtMinDown, "-");
: Screen(app), alarmController {alarmController}, systemTask {systemTask} {

hourCounter.Create();
lv_obj_align(hourCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
if (clockType == Controllers::Settings::ClockType::H12) {
hourCounter.EnableTwelveHourMode();

lblampm = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
lv_label_set_text_static(lblampm, "AM");
lv_label_set_align(lblampm, LV_LABEL_ALIGN_CENTER);
lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, 0, 30);
}
hourCounter.SetValue(alarmController.Hours());
hourCounter.SetValueChangedEventCallback(this, ValueChangedHandler);

minuteCounter.Create();
lv_obj_align(minuteCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0);
minuteCounter.SetValue(alarmController.Minutes());
minuteCounter.SetValueChangedEventCallback(this, ValueChangedHandler);

lv_obj_t* colonLabel = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
lv_label_set_text_static(colonLabel, ":");
lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29);

btnStop = lv_btn_create(lv_scr_act(), nullptr);
btnStop->user_data = this;
Expand All @@ -97,20 +79,27 @@ Alarm::Alarm(DisplayApp* app,
lv_label_set_text_static(txtStop, Symbols::stop);
lv_obj_set_hidden(btnStop, true);

static constexpr lv_color_t bgColor = LV_COLOR_MAKE(0x38, 0x38, 0x38);

btnRecur = lv_btn_create(lv_scr_act(), nullptr);
btnRecur->user_data = this;
lv_obj_set_event_cb(btnRecur, btnEventHandler);
lv_obj_set_size(btnRecur, 115, 50);
lv_obj_align(btnRecur, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
txtRecur = lv_label_create(btnRecur, nullptr);
SetRecurButtonState();
lv_obj_set_style_local_bg_color(btnRecur, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, bgColor);

btnInfo = lv_btn_create(lv_scr_act(), nullptr);
btnInfo->user_data = this;
lv_obj_set_event_cb(btnInfo, btnEventHandler);
lv_obj_set_size(btnInfo, 50, 40);
lv_obj_align(btnInfo, lv_scr_act(), LV_ALIGN_CENTER, 0, -85);
txtInfo = lv_label_create(btnInfo, nullptr);
lv_obj_set_size(btnInfo, 50, 50);
lv_obj_align(btnInfo, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 0, -4);
lv_obj_set_style_local_bg_color(btnInfo, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, bgColor);
lv_obj_set_style_local_border_width(btnInfo, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, 4);
lv_obj_set_style_local_border_color(btnInfo, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);

lv_obj_t* txtInfo = lv_label_create(btnInfo, nullptr);
lv_label_set_text_static(txtInfo, "i");

enableSwitch = lv_switch_create(lv_scr_act(), nullptr);
Expand All @@ -119,6 +108,7 @@ Alarm::Alarm(DisplayApp* app,
lv_obj_set_size(enableSwitch, 100, 50);
// Align to the center of 115px from edge
lv_obj_align(enableSwitch, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 7, 0);
lv_obj_set_style_local_bg_color(enableSwitch, LV_SWITCH_PART_BG, LV_STATE_DEFAULT, bgColor);

UpdateAlarmTime();

Expand All @@ -136,8 +126,14 @@ Alarm::~Alarm() {
lv_obj_clean(lv_scr_act());
}

void Alarm::DisableAlarm() {
if (alarmController.State() == AlarmController::AlarmState::Set) {
alarmController.DisableAlarm();
lv_switch_off(enableSwitch, LV_ANIM_ON);
}
}

void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
using Pinetime::Controllers::AlarmController;
if (event == LV_EVENT_CLICKED) {
if (obj == btnStop) {
StopAlerting();
Expand All @@ -159,49 +155,8 @@ void Alarm::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
}
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
if (alarmController.State() == AlarmController::AlarmState::Set) {
alarmController.DisableAlarm();
lv_switch_off(enableSwitch, LV_ANIM_ON);
}
if (obj == btnMinutesUp) {
if (alarmMinutes >= 59) {
alarmMinutes = 0;
} else {
alarmMinutes++;
}
UpdateAlarmTime();
return;
}
if (obj == btnMinutesDown) {
if (alarmMinutes == 0) {
alarmMinutes = 59;
} else {
alarmMinutes--;
}
UpdateAlarmTime();
return;
}
if (obj == btnHoursUp) {
if (alarmHours >= 23) {
alarmHours = 0;
} else {
alarmHours++;
}
UpdateAlarmTime();
return;
}
if (obj == btnHoursDown) {
if (alarmHours == 0) {
alarmHours = 23;
} else {
alarmHours--;
}
UpdateAlarmTime();
return;
}
if (obj == btnRecur) {
DisableAlarm();
ToggleRecurrence();
}
}
Expand All @@ -224,30 +179,20 @@ bool Alarm::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
return alarmController.State() == AlarmController::AlarmState::Alerting && event == TouchEvents::SwipeDown;
}

void Alarm::OnValueChanged() {
DisableAlarm();
UpdateAlarmTime();
}

void Alarm::UpdateAlarmTime() {
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
switch (alarmHours) {
case 0:
lv_label_set_text_static(lblampm, "AM");
lv_label_set_text_fmt(time, "%02d:%02d", 12, alarmMinutes);
break;
case 1 ... 11:
lv_label_set_text_static(lblampm, "AM");
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
break;
case 12:
lv_label_set_text_static(lblampm, "PM");
lv_label_set_text_fmt(time, "%02d:%02d", 12, alarmMinutes);
break;
case 13 ... 23:
lv_label_set_text_static(lblampm, "PM");
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours - 12, alarmMinutes);
break;
if (lblampm != nullptr) {
if (hourCounter.GetValue() >= 12) {
lv_label_set_text_static(lblampm, "PM");
} else {
lv_label_set_text_static(lblampm, "AM");
}
} else {
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
}
alarmController.SetAlarmTime(alarmHours, alarmMinutes);
alarmController.SetAlarmTime(hourCounter.GetValue(), minuteCounter.GetValue());
}

void Alarm::SetAlerting() {
Expand Down Expand Up @@ -283,6 +228,9 @@ void Alarm::SetSwitchState(lv_anim_enable_t anim) {
}

void Alarm::ShowInfo() {
if (btnMessage != nullptr) {
return;
}
btnMessage = lv_btn_create(lv_scr_act(), nullptr);
btnMessage->user_data = this;
lv_obj_set_event_cb(btnMessage, btnEventHandler);
Expand Down
14 changes: 8 additions & 6 deletions src/displayapp/screens/Alarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "systemtask/SystemTask.h"
#include "displayapp/LittleVgl.h"
#include "components/alarm/AlarmController.h"
#include "displayapp/widgets/Counter.h"

namespace Pinetime {
namespace Applications {
Expand All @@ -29,36 +30,37 @@ namespace Pinetime {
public:
Alarm(DisplayApp* app,
Controllers::AlarmController& alarmController,
Pinetime::Controllers::Settings& settingsController,
Controllers::Settings::ClockType clockType,
System::SystemTask& systemTask);
~Alarm() override;
void SetAlerting();
void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
bool OnButtonPushed() override;
bool OnTouchEvent(TouchEvents event) override;
void OnValueChanged();
void StopAlerting();

private:
uint8_t alarmHours;
uint8_t alarmMinutes;
Controllers::AlarmController& alarmController;
Controllers::Settings& settingsController;
System::SystemTask& systemTask;

lv_obj_t *time, *lblampm, *btnStop, *txtStop, *btnMinutesUp, *btnMinutesDown, *btnHoursUp, *btnHoursDown, *txtMinUp, *txtMinDown,
*txtHrUp, *txtHrDown, *btnRecur, *txtRecur, *btnInfo, *txtInfo, *enableSwitch;
lv_obj_t *btnStop, *txtStop, *btnRecur, *txtRecur, *btnInfo, *enableSwitch;
lv_obj_t* lblampm = nullptr;
lv_obj_t* txtMessage = nullptr;
lv_obj_t* btnMessage = nullptr;
lv_task_t* taskStopAlarm = nullptr;

enum class EnableButtonState { On, Off, Alerting };
void DisableAlarm();
void SetRecurButtonState();
void SetSwitchState(lv_anim_enable_t anim);
void SetAlarm();
void ShowInfo();
void HideInfo();
void ToggleRecurrence();
void UpdateAlarmTime();
Widgets::Counter hourCounter = Widgets::Counter(0, 23, jetbrains_mono_76);
Widgets::Counter minuteCounter = Widgets::Counter(0, 59, jetbrains_mono_76);
};
};
};
Expand Down