Skip to content

Commit b8b54f4

Browse files
authored
Merge pull request #813 from SteveAmor/chimes
Chimes option
2 parents e0013e7 + 15c3807 commit b8b54f4

12 files changed

Lines changed: 193 additions & 5 deletions

File tree

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ list(APPEND SOURCE_FILES
447447
displayapp/screens/settings/SettingSteps.cpp
448448
displayapp/screens/settings/SettingSetDate.cpp
449449
displayapp/screens/settings/SettingSetTime.cpp
450+
displayapp/screens/settings/SettingChimes.cpp
450451

451452
## Watch faces
452453
displayapp/icons/bg_clock.c

src/components/datetime/DateTimeController.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ void DateTime::UpdateTime(uint32_t systickCounter) {
7575
minute = time.minutes().count();
7676
second = time.seconds().count();
7777

78+
if (minute == 0 && !isHourAlreadyNotified) {
79+
isHourAlreadyNotified = true;
80+
if (systemTask != nullptr) {
81+
systemTask->PushMessage(System::Messages::OnNewHour);
82+
}
83+
} else if (minute != 0) {
84+
isHourAlreadyNotified = false;
85+
}
86+
87+
if ((minute == 0 || minute == 30) && !isHalfHourAlreadyNotified) {
88+
isHalfHourAlreadyNotified = true;
89+
if (systemTask != nullptr) {
90+
systemTask->PushMessage(System::Messages::OnNewHalfHour);
91+
}
92+
} else if (minute != 0 && minute != 30) {
93+
isHalfHourAlreadyNotified = false;
94+
}
95+
7896
// Notify new day to SystemTask
7997
if (hour == 0 and not isMidnightAlreadyNotified) {
8098
isMidnightAlreadyNotified = true;
@@ -100,4 +118,3 @@ const char* DateTime::MonthShortToStringLow(Months month) {
100118
void DateTime::Register(Pinetime::System::SystemTask* systemTask) {
101119
this->systemTask = systemTask;
102120
}
103-

src/components/datetime/DateTimeController.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ namespace Pinetime {
8686
std::chrono::seconds uptime {0};
8787

8888
bool isMidnightAlreadyNotified = false;
89+
bool isHourAlreadyNotified = true;
90+
bool isHalfHourAlreadyNotified = true;
8991
System::SystemTask* systemTask = nullptr;
9092
};
9193
}

src/components/settings/Settings.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace Pinetime {
1111
public:
1212
enum class ClockType : uint8_t { H24, H12 };
1313
enum class Notification : uint8_t { ON, OFF };
14+
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
1415
enum class WakeUpMode : uint8_t {
1516
SingleTap = 0,
1617
DoubleTap = 1,
@@ -40,6 +41,16 @@ namespace Pinetime {
4041
return settings.clockFace;
4142
};
4243

44+
void SetChimeOption(ChimesOption chimeOption) {
45+
if (chimeOption != settings.chimesOption) {
46+
settingsChanged = true;
47+
}
48+
settings.chimesOption = chimeOption;
49+
};
50+
ChimesOption GetChimeOption() const {
51+
return settings.chimesOption;
52+
};
53+
4354
void SetPTSColorTime(Colors colorTime) {
4455
if (colorTime != settings.PTS.ColorTime)
4556
settingsChanged = true;
@@ -162,7 +173,7 @@ namespace Pinetime {
162173
private:
163174
Pinetime::Controllers::FS& fs;
164175

165-
static constexpr uint32_t settingsVersion = 0x0002;
176+
static constexpr uint32_t settingsVersion = 0x0003;
166177
struct SettingsData {
167178
uint32_t version = settingsVersion;
168179
uint32_t stepsGoal = 10000;
@@ -172,6 +183,7 @@ namespace Pinetime {
172183
Notification notificationStatus = Notification::ON;
173184

174185
uint8_t clockFace = 0;
186+
ChimesOption chimesOption = ChimesOption::None;
175187

176188
PineTimeStyle PTS;
177189

src/displayapp/Apps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace Pinetime {
3636
SettingSteps,
3737
SettingSetDate,
3838
SettingSetTime,
39+
SettingChimes,
3940
Error,
4041
};
4142
}

src/displayapp/DisplayApp.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "displayapp/screens/settings/SettingSteps.h"
4848
#include "displayapp/screens/settings/SettingSetDate.h"
4949
#include "displayapp/screens/settings/SettingSetTime.h"
50+
#include "displayapp/screens/settings/SettingChimes.h"
5051

5152
#include "libs/lv_conf.h"
5253

@@ -292,6 +293,9 @@ void DisplayApp::Refresh() {
292293
// Added to remove warning
293294
// What should happen here?
294295
break;
296+
case Messages::Clock:
297+
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
298+
break;
295299
}
296300
}
297301

@@ -415,6 +419,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
415419
currentScreen = std::make_unique<Screens::SettingSetTime>(this, dateTimeController);
416420
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
417421
break;
422+
case Apps::SettingChimes:
423+
currentScreen = std::make_unique<Screens::SettingChimes>(this, settingsController);
424+
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
425+
break;
418426
case Apps::BatteryInfo:
419427
currentScreen = std::make_unique<Screens::BatteryInfo>(this, batteryController);
420428
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);

src/displayapp/Messages.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ namespace Pinetime {
2020
DimScreen,
2121
RestoreBrightness,
2222
ShowPairingKey,
23-
AlarmTriggered
23+
AlarmTriggered,
24+
Clock
2425
};
2526
}
2627
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include "displayapp/screens/settings/SettingChimes.h"
2+
#include <lvgl/lvgl.h>
3+
#include "displayapp/DisplayApp.h"
4+
#include "displayapp/screens/Screen.h"
5+
#include "displayapp/screens/Symbols.h"
6+
7+
using namespace Pinetime::Applications::Screens;
8+
9+
namespace {
10+
static void event_handler(lv_obj_t* obj, lv_event_t event) {
11+
SettingChimes* screen = static_cast<SettingChimes*>(obj->user_data);
12+
screen->UpdateSelected(obj, event);
13+
}
14+
}
15+
16+
SettingChimes::SettingChimes(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
17+
: Screen(app), settingsController {settingsController} {
18+
19+
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), nullptr);
20+
21+
lv_obj_set_style_local_bg_opa(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
22+
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
23+
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
24+
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
25+
26+
lv_obj_set_pos(container1, 10, 60);
27+
lv_obj_set_width(container1, LV_HOR_RES - 20);
28+
lv_obj_set_height(container1, LV_VER_RES - 50);
29+
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
30+
31+
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
32+
lv_label_set_text_static(title, "Chimes");
33+
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
34+
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 10, 15);
35+
36+
lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr);
37+
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
38+
lv_label_set_text_static(icon, Symbols::clock);
39+
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
40+
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
41+
42+
optionsTotal = 0;
43+
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
44+
lv_checkbox_set_text_static(cbOption[optionsTotal], " Off");
45+
cbOption[optionsTotal]->user_data = this;
46+
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
47+
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::None) {
48+
lv_checkbox_set_checked(cbOption[optionsTotal], true);
49+
}
50+
51+
optionsTotal++;
52+
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
53+
lv_checkbox_set_text_static(cbOption[optionsTotal], " Every hour");
54+
cbOption[optionsTotal]->user_data = this;
55+
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
56+
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::Hours) {
57+
lv_checkbox_set_checked(cbOption[optionsTotal], true);
58+
}
59+
60+
optionsTotal++;
61+
cbOption[optionsTotal] = lv_checkbox_create(container1, nullptr);
62+
lv_checkbox_set_text_static(cbOption[optionsTotal], " Every 30 mins");
63+
cbOption[optionsTotal]->user_data = this;
64+
lv_obj_set_event_cb(cbOption[optionsTotal], event_handler);
65+
if (settingsController.GetChimeOption() == Controllers::Settings::ChimesOption::HalfHours) {
66+
lv_checkbox_set_checked(cbOption[optionsTotal], true);
67+
}
68+
69+
optionsTotal++;
70+
}
71+
72+
SettingChimes::~SettingChimes() {
73+
lv_obj_clean(lv_scr_act());
74+
settingsController.SaveSettings();
75+
}
76+
77+
void SettingChimes::UpdateSelected(lv_obj_t* object, lv_event_t event) {
78+
if (event == LV_EVENT_VALUE_CHANGED) {
79+
for (uint8_t i = 0; i < optionsTotal; i++) {
80+
if (object == cbOption[i]) {
81+
lv_checkbox_set_checked(cbOption[i], true);
82+
if (i == 0) {
83+
settingsController.SetChimeOption(Controllers::Settings::ChimesOption::None);
84+
}
85+
if (i == 1) {
86+
settingsController.SetChimeOption(Controllers::Settings::ChimesOption::Hours);
87+
}
88+
if (i == 2) {
89+
settingsController.SetChimeOption(Controllers::Settings::ChimesOption::HalfHours);
90+
}
91+
} else {
92+
lv_checkbox_set_checked(cbOption[i], false);
93+
}
94+
}
95+
}
96+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include <cstdint>
4+
#include <lvgl/lvgl.h>
5+
#include "components/settings/Settings.h"
6+
#include "displayapp/screens/Screen.h"
7+
8+
namespace Pinetime {
9+
10+
namespace Applications {
11+
namespace Screens {
12+
13+
class SettingChimes : public Screen {
14+
public:
15+
SettingChimes(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
16+
~SettingChimes() override;
17+
18+
void UpdateSelected(lv_obj_t* object, lv_event_t event);
19+
20+
private:
21+
Controllers::Settings& settingsController;
22+
uint8_t optionsTotal;
23+
lv_obj_t* cbOption[2];
24+
};
25+
}
26+
}
27+
}

src/displayapp/screens/settings/Settings.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ std::unique_ptr<Screen> Settings::CreateScreen2() {
6060
std::unique_ptr<Screen> Settings::CreateScreen3() {
6161

6262
std::array<Screens::List::Applications, 4> applications {{
63+
64+
{Symbols::clock, "Chimes", Apps::SettingChimes},
6365
{Symbols::check, "Firmware", Apps::FirmwareValidation},
6466
{Symbols::list, "About", Apps::SysInfo},
65-
{Symbols::none, "None", Apps::None},
6667
{Symbols::none, "None", Apps::None}
6768
}};
6869

6970
return std::make_unique<Screens::List>(2, 3, app, settingsController, applications);
70-
}
71+
}

0 commit comments

Comments
 (0)