Skip to content

Commit 5932391

Browse files
committed
Chimes option
1 parent 0aa73c2 commit 5932391

12 files changed

Lines changed: 179 additions & 2 deletions

File tree

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ list(APPEND SOURCE_FILES
436436
displayapp/screens/settings/SettingPineTimeStyle.cpp
437437
displayapp/screens/settings/SettingSetDate.cpp
438438
displayapp/screens/settings/SettingSetTime.cpp
439+
displayapp/screens/settings/SettingChimes.cpp
439440

440441
## Watch faces
441442
displayapp/icons/bg_clock.c

src/components/datetime/DateTimeController.cpp

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

78+
if(minute == 0 and not isHourAlreadyNotified) {
79+
isHourAlreadyNotified = true;
80+
if(systemTask != nullptr)
81+
systemTask->PushMessage(System::Messages::OnNewHour);
82+
} else if (minute != 0) {
83+
isHourAlreadyNotified = false;
84+
}
85+
86+
if((minute == 0 or minute == 30) and not isHalfHourAlreadyNotified) {
87+
isHalfHourAlreadyNotified = true;
88+
if(systemTask != nullptr)
89+
systemTask->PushMessage(System::Messages::OnNewHalfHour);
90+
} else if (minute != 0 and minute != 30) {
91+
isHalfHourAlreadyNotified = false;
92+
}
93+
7894
// Notify new day to SystemTask
7995
if (hour == 0 and not isMidnightAlreadyNotified) {
8096
isMidnightAlreadyNotified = true;

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ namespace Pinetime {
4141
return settings.clockFace;
4242
};
4343

44+
void SetChimesState(uint8_t state) {
45+
if (state != settings.chimesState) {
46+
settingsChanged = true;
47+
}
48+
settings.chimesState = state;
49+
};
50+
uint8_t GetChimesState() const {
51+
return settings.chimesState;
52+
};
53+
4454
void SetPTSColorTime(Colors colorTime) {
4555
if (colorTime != settings.PTS.ColorTime)
4656
settingsChanged = true;
@@ -173,6 +183,7 @@ namespace Pinetime {
173183
Notification notificationStatus = Notification::ON;
174184

175185
uint8_t clockFace = 0;
186+
uint8_t chimesState = 0;
176187

177188
PineTimeStyle PTS;
178189

src/displayapp/Apps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace Pinetime {
3535
SettingPineTimeStyle,
3636
SettingSetDate,
3737
SettingSetTime,
38+
SettingChimes,
3839
Error,
3940
};
4041
}

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/SettingPineTimeStyle.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

@@ -268,6 +269,9 @@ void DisplayApp::Refresh() {
268269
// Added to remove warning
269270
// What should happen here?
270271
break;
272+
case Messages::Clock:
273+
LoadApp(Apps::Clock, DisplayApp::FullRefreshDirections::None);
274+
break;
271275
}
272276
}
273277

@@ -386,6 +390,10 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
386390
currentScreen = std::make_unique<Screens::SettingSetTime>(this, dateTimeController);
387391
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
388392
break;
393+
case Apps::SettingChimes:
394+
currentScreen = std::make_unique<Screens::SettingChimes>(this, settingsController);
395+
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
396+
break;
389397
case Apps::SettingPineTimeStyle:
390398
currentScreen = std::make_unique<Screens::SettingPineTimeStyle>(this, settingsController);
391399
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
@@ -15,7 +15,8 @@ namespace Pinetime {
1515
UpdateTimeOut,
1616
DimScreen,
1717
RestoreBrightness,
18-
AlarmTriggered
18+
AlarmTriggered,
19+
Clock
1920
};
2021
}
2122
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#include "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.GetChimesState() == 0) {
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.GetChimesState() == 1) {
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.GetChimesState() == 2) {
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+
settingsController.SetChimesState(i);
83+
} else {
84+
lv_checkbox_set_checked(cbOption[i], false);
85+
}
86+
}
87+
}
88+
}
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ std::unique_ptr<Screen> Settings::CreateScreen2() {
6060
std::unique_ptr<Screen> Settings::CreateScreen3() {
6161

6262
std::array<Screens::List::Applications, 4> applications {{
63+
{Symbols::clock, "Chimes", Apps::SettingChimes},
6364
{Symbols::paintbrush, "PTS Colors", Apps::SettingPineTimeStyle},
6465
{Symbols::check, "Firmware", Apps::FirmwareValidation},
6566
{Symbols::list, "About", Apps::SysInfo},
66-
{Symbols::none, "None", Apps::None},
6767
}};
6868

6969
return std::make_unique<Screens::List>(2, 3, app, settingsController, applications);

0 commit comments

Comments
 (0)