Skip to content

Commit 020a7fd

Browse files
minacodeminacode
and
minacode
authored
Refactor watch face to enum (#1339)
change watch face from int to enum --------- Co-authored-by: minacode <minamoto9@web.de>
1 parent 5f19f68 commit 020a7fd

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ set(INCLUDE_FILES
604604
displayapp/screens/ApplicationList.h
605605
displayapp/screens/CheckboxList.h
606606
displayapp/Apps.h
607+
displayapp/WatchFaces.h
607608
displayapp/screens/Notifications.h
608609
displayapp/screens/HeartRate.h
609610
displayapp/screens/Metronome.h

src/components/settings/Settings.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <bitset>
44
#include "components/brightness/BrightnessController.h"
55
#include "components/fs/FS.h"
6+
#include "displayapp/WatchFaces.h"
67

78
namespace Pinetime {
89
namespace Controllers {
@@ -61,15 +62,15 @@ namespace Pinetime {
6162
void Init();
6263
void SaveSettings();
6364

64-
void SetClockFace(uint8_t face) {
65-
if (face != settings.clockFace) {
65+
void SetWatchFace(Pinetime::Applications::WatchFace face) {
66+
if (face != settings.watchFace) {
6667
settingsChanged = true;
6768
}
68-
settings.clockFace = face;
69+
settings.watchFace = face;
6970
};
7071

71-
uint8_t GetClockFace() const {
72-
return settings.clockFace;
72+
Pinetime::Applications::WatchFace GetWatchFace() const {
73+
return settings.watchFace;
7374
};
7475

7576
void SetChimeOption(ChimesOption chimeOption) {
@@ -276,7 +277,7 @@ namespace Pinetime {
276277
ClockType clockType = ClockType::H24;
277278
Notification notificationStatus = Notification::On;
278279

279-
uint8_t clockFace = 0;
280+
Pinetime::Applications::WatchFace watchFace = Pinetime::Applications::WatchFace::Digital;
280281
ChimesOption chimesOption = ChimesOption::None;
281282

282283
PineTimeStyle PTS;

src/displayapp/WatchFaces.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
namespace Pinetime {
4+
namespace Applications {
5+
enum class WatchFace : uint8_t {
6+
Digital = 0,
7+
Analog = 1,
8+
PineTimeStyle = 2,
9+
Terminal = 3,
10+
Infineat = 4,
11+
CasioStyleG7710 = 5,
12+
};
13+
}
14+
}

src/displayapp/screens/Clock.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
1616

1717
using namespace Pinetime::Applications::Screens;
18+
using namespace Pinetime::Applications;
1819

1920
Clock::Clock(Controllers::DateTime& dateTimeController,
2021
const Controllers::Battery& batteryController,
@@ -33,23 +34,23 @@ Clock::Clock(Controllers::DateTime& dateTimeController,
3334
motionController {motionController},
3435
filesystem {filesystem},
3536
screen {[this, &settingsController]() {
36-
switch (settingsController.GetClockFace()) {
37-
case 0:
37+
switch (settingsController.GetWatchFace()) {
38+
case WatchFace::Digital:
3839
return WatchFaceDigitalScreen();
3940
break;
40-
case 1:
41+
case WatchFace::Analog:
4142
return WatchFaceAnalogScreen();
4243
break;
43-
case 2:
44+
case WatchFace::PineTimeStyle:
4445
return WatchFacePineTimeStyleScreen();
4546
break;
46-
case 3:
47+
case WatchFace::Terminal:
4748
return WatchFaceTerminalScreen();
4849
break;
49-
case 4:
50+
case WatchFace::Infineat:
5051
return WatchFaceInfineatScreen();
5152
break;
52-
case 5:
53+
case WatchFace::CasioStyleG7710:
5354
return WatchFaceCasioStyleG7710();
5455
break;
5556
}

src/displayapp/screens/settings/SettingWatchFace.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "displayapp/DisplayApp.h"
44
#include "displayapp/screens/Screen.h"
55
#include "components/settings/Settings.h"
6+
#include "displayapp/WatchFaces.h"
67

78
using namespace Pinetime::Applications::Screens;
89

@@ -47,9 +48,9 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen(unsigned int screenNum) c
4748
nScreens,
4849
title,
4950
symbol,
50-
settingsController.GetClockFace(),
51-
[&settings = settingsController](uint32_t clockFace) {
52-
settings.SetClockFace(clockFace);
51+
static_cast<uint32_t>(settingsController.GetWatchFace()),
52+
[&settings = settingsController](uint32_t index) {
53+
settings.SetWatchFace(static_cast<WatchFace>(index));
5354
settings.SaveSettings();
5455
},
5556
watchfacesOnThisScreen);

0 commit comments

Comments
 (0)