Skip to content

Commit

Permalink
Added alarm 12 hour interface
Browse files Browse the repository at this point in the history
  • Loading branch information
eliwss0 committed Jan 16, 2022
1 parent 26ae828 commit de41205
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,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);
currentScreen = std::make_unique<Screens::Alarm>(this, alarmController, settingsController);
break;

// Settings
Expand Down Expand Up @@ -425,7 +425,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingShakeThreshold:
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(this, settingsController,motionController,*systemTask);
currentScreen = std::make_unique<Screens::SettingShakeThreshold>(this, settingsController, motionController, *systemTask);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::BatteryInfo:
Expand Down
43 changes: 39 additions & 4 deletions src/displayapp/screens/Alarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
screen->OnButtonEvent(obj, event);
}

Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController)
: Screen(app), running {true}, alarmController {alarmController} {
Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController, Pinetime::Controllers::Settings& settingsController)
: Screen(app), running {true}, alarmController {alarmController}, settingsController {settingsController} {

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);
Expand All @@ -40,6 +40,13 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController)

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_GRAY);
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);
Expand Down Expand Up @@ -95,6 +102,8 @@ Alarm::Alarm(DisplayApp* app, Controllers::AlarmController& alarmController)
lv_obj_align(btnInfo, lv_scr_act(), LV_ALIGN_CENTER, 0, -85);
txtInfo = lv_label_create(btnInfo, nullptr);
lv_label_set_text_static(txtInfo, "i");

UpdateAlarmTime();
}

Alarm::~Alarm() {
Expand Down Expand Up @@ -180,8 +189,34 @@ bool Alarm::OnButtonPushed() {
}

void Alarm::UpdateAlarmTime() {
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
alarmController.SetAlarmTime(alarmHours, alarmMinutes);
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);
alarmController.SetAlarmTime(0, alarmMinutes);
break;
case 1 ... 11:
lv_label_set_text_static(lblampm, "AM");
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
alarmController.SetAlarmTime(alarmHours, alarmMinutes);
break;
case 12:
lv_label_set_text_static(lblampm, "PM");
lv_label_set_text_fmt(time, "%02d:%02d", 12, alarmMinutes);
alarmController.SetAlarmTime(12, alarmMinutes);
break;
case 13 ... 23:
lv_label_set_text_static(lblampm, "PM");
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours - 12, alarmMinutes);
alarmController.SetAlarmTime(alarmHours, alarmMinutes);
break;
}
} else {
lv_label_set_text_static(lblampm, " ");
lv_label_set_text_fmt(time, "%02d:%02d", alarmHours, alarmMinutes);
alarmController.SetAlarmTime(alarmHours, alarmMinutes);
}
}

void Alarm::SetAlerting() {
Expand Down
7 changes: 4 additions & 3 deletions src/displayapp/screens/Alarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Pinetime {
namespace Screens {
class Alarm : public Screen {
public:
Alarm(DisplayApp* app, Controllers::AlarmController& alarmController);
Alarm(DisplayApp* app, Controllers::AlarmController& alarmController, Pinetime::Controllers::Settings& settingsController);
~Alarm() override;
void SetAlerting();
void OnButtonEvent(lv_obj_t* obj, lv_event_t event);
Expand All @@ -38,9 +38,10 @@ namespace Pinetime {
uint8_t alarmHours;
uint8_t alarmMinutes;
Controllers::AlarmController& alarmController;
Controllers::Settings& settingsController;

lv_obj_t *time, *btnEnable, *txtEnable, *btnMinutesUp, *btnMinutesDown, *btnHoursUp, *btnHoursDown, *txtMinUp, *txtMinDown,
*txtHrUp, *txtHrDown, *btnRecur, *txtRecur, *btnInfo, *txtInfo;
lv_obj_t *time, *lblampm, *btnEnable, *txtEnable, *btnMinutesUp, *btnMinutesDown, *btnHoursUp, *btnHoursDown, *txtMinUp,
*txtMinDown, *txtHrUp, *txtHrDown, *btnRecur, *txtRecur, *btnInfo, *txtInfo;
lv_obj_t* txtMessage = nullptr;
lv_obj_t* btnMessage = nullptr;

Expand Down

0 comments on commit de41205

Please sign in to comment.