Skip to content

Commit

Permalink
Refactor watch face to enum (#1339)
Browse files Browse the repository at this point in the history
change watch face from int to enum

---------

Co-authored-by: minacode <[email protected]>
  • Loading branch information
minacode and minacode authored Apr 30, 2023
1 parent 5f19f68 commit 020a7fd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ set(INCLUDE_FILES
displayapp/screens/ApplicationList.h
displayapp/screens/CheckboxList.h
displayapp/Apps.h
displayapp/WatchFaces.h
displayapp/screens/Notifications.h
displayapp/screens/HeartRate.h
displayapp/screens/Metronome.h
Expand Down
13 changes: 7 additions & 6 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <bitset>
#include "components/brightness/BrightnessController.h"
#include "components/fs/FS.h"
#include "displayapp/WatchFaces.h"

namespace Pinetime {
namespace Controllers {
Expand Down Expand Up @@ -61,15 +62,15 @@ namespace Pinetime {
void Init();
void SaveSettings();

void SetClockFace(uint8_t face) {
if (face != settings.clockFace) {
void SetWatchFace(Pinetime::Applications::WatchFace face) {
if (face != settings.watchFace) {
settingsChanged = true;
}
settings.clockFace = face;
settings.watchFace = face;
};

uint8_t GetClockFace() const {
return settings.clockFace;
Pinetime::Applications::WatchFace GetWatchFace() const {
return settings.watchFace;
};

void SetChimeOption(ChimesOption chimeOption) {
Expand Down Expand Up @@ -276,7 +277,7 @@ namespace Pinetime {
ClockType clockType = ClockType::H24;
Notification notificationStatus = Notification::On;

uint8_t clockFace = 0;
Pinetime::Applications::WatchFace watchFace = Pinetime::Applications::WatchFace::Digital;
ChimesOption chimesOption = ChimesOption::None;

PineTimeStyle PTS;
Expand Down
14 changes: 14 additions & 0 deletions src/displayapp/WatchFaces.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

namespace Pinetime {
namespace Applications {
enum class WatchFace : uint8_t {
Digital = 0,
Analog = 1,
PineTimeStyle = 2,
Terminal = 3,
Infineat = 4,
CasioStyleG7710 = 5,
};
}
}
15 changes: 8 additions & 7 deletions src/displayapp/screens/Clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"

using namespace Pinetime::Applications::Screens;
using namespace Pinetime::Applications;

Clock::Clock(Controllers::DateTime& dateTimeController,
const Controllers::Battery& batteryController,
Expand All @@ -33,23 +34,23 @@ Clock::Clock(Controllers::DateTime& dateTimeController,
motionController {motionController},
filesystem {filesystem},
screen {[this, &settingsController]() {
switch (settingsController.GetClockFace()) {
case 0:
switch (settingsController.GetWatchFace()) {
case WatchFace::Digital:
return WatchFaceDigitalScreen();
break;
case 1:
case WatchFace::Analog:
return WatchFaceAnalogScreen();
break;
case 2:
case WatchFace::PineTimeStyle:
return WatchFacePineTimeStyleScreen();
break;
case 3:
case WatchFace::Terminal:
return WatchFaceTerminalScreen();
break;
case 4:
case WatchFace::Infineat:
return WatchFaceInfineatScreen();
break;
case 5:
case WatchFace::CasioStyleG7710:
return WatchFaceCasioStyleG7710();
break;
}
Expand Down
7 changes: 4 additions & 3 deletions src/displayapp/screens/settings/SettingWatchFace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/Screen.h"
#include "components/settings/Settings.h"
#include "displayapp/WatchFaces.h"

using namespace Pinetime::Applications::Screens;

Expand Down Expand Up @@ -47,9 +48,9 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen(unsigned int screenNum) c
nScreens,
title,
symbol,
settingsController.GetClockFace(),
[&settings = settingsController](uint32_t clockFace) {
settings.SetClockFace(clockFace);
static_cast<uint32_t>(settingsController.GetWatchFace()),
[&settings = settingsController](uint32_t index) {
settings.SetWatchFace(static_cast<WatchFace>(index));
settings.SaveSettings();
},
watchfacesOnThisScreen);
Expand Down

0 comments on commit 020a7fd

Please sign in to comment.