Skip to content

Commit d889f3e

Browse files
FintasticManJF002
authored andcommitted
settings: Add settings item for weather format
1 parent c04813b commit d889f3e

File tree

8 files changed

+114
-4
lines changed

8 files changed

+114
-4
lines changed

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ list(APPEND SOURCE_FILES
405405
displayapp/screens/settings/Settings.cpp
406406
displayapp/screens/settings/SettingWatchFace.cpp
407407
displayapp/screens/settings/SettingTimeFormat.cpp
408+
displayapp/screens/settings/SettingWeatherFormat.cpp
408409
displayapp/screens/settings/SettingWakeUp.cpp
409410
displayapp/screens/settings/SettingDisplay.cpp
410411
displayapp/screens/settings/SettingSteps.cpp

src/components/settings/Settings.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace Pinetime {
1010
class Settings {
1111
public:
1212
enum class ClockType : uint8_t { H24, H12 };
13+
enum class WeatherFormat : uint8_t { Metric, Imperial };
1314
enum class Notification : uint8_t { On, Off, Sleep };
1415
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
1516
enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 };
@@ -180,6 +181,17 @@ namespace Pinetime {
180181
return settings.clockType;
181182
};
182183

184+
void SetWeatherFormat(WeatherFormat weatherFormat) {
185+
if (weatherFormat != settings.weatherFormat) {
186+
settingsChanged = true;
187+
}
188+
settings.weatherFormat = weatherFormat;
189+
};
190+
191+
WeatherFormat GetWeatherFormat() const {
192+
return settings.weatherFormat;
193+
};
194+
183195
void SetNotificationStatus(Notification status) {
184196
if (status != settings.notificationStatus) {
185197
settingsChanged = true;
@@ -274,14 +286,15 @@ namespace Pinetime {
274286
private:
275287
Pinetime::Controllers::FS& fs;
276288

277-
static constexpr uint32_t settingsVersion = 0x0006;
289+
static constexpr uint32_t settingsVersion = 0x0007;
278290

279291
struct SettingsData {
280292
uint32_t version = settingsVersion;
281293
uint32_t stepsGoal = 10000;
282294
uint32_t screenTimeOut = 15000;
283295

284296
ClockType clockType = ClockType::H24;
297+
WeatherFormat weatherFormat = WeatherFormat::Metric;
285298
Notification notificationStatus = Notification::On;
286299

287300
Pinetime::Applications::WatchFace watchFace = Pinetime::Applications::WatchFace::Digital;

src/displayapp/DisplayApp.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "displayapp/screens/settings/Settings.h"
4040
#include "displayapp/screens/settings/SettingWatchFace.h"
4141
#include "displayapp/screens/settings/SettingTimeFormat.h"
42+
#include "displayapp/screens/settings/SettingWeatherFormat.h"
4243
#include "displayapp/screens/settings/SettingWakeUp.h"
4344
#include "displayapp/screens/settings/SettingDisplay.h"
4445
#include "displayapp/screens/settings/SettingSteps.h"
@@ -498,6 +499,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
498499
case Apps::SettingTimeFormat:
499500
currentScreen = std::make_unique<Screens::SettingTimeFormat>(settingsController);
500501
break;
502+
case Apps::SettingWeatherFormat:
503+
currentScreen = std::make_unique<Screens::SettingWeatherFormat>(settingsController);
504+
break;
501505
case Apps::SettingWakeUp:
502506
currentScreen = std::make_unique<Screens::SettingWakeUp>(settingsController);
503507
break;

src/displayapp/apps/Apps.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace Pinetime {
3232
Settings,
3333
SettingWatchFace,
3434
SettingTimeFormat,
35+
SettingWeatherFormat,
3536
SettingDisplay,
3637
SettingWakeUp,
3738
SettingSteps,

src/displayapp/fonts/fonts.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
{
99
"file": "FontAwesome5-Solid+Brands+Regular.woff",
10-
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c"
10+
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf743"
1111
}
1212
],
1313
"bpp": 1,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include "displayapp/screens/settings/SettingWeatherFormat.h"
2+
3+
#include <lvgl/lvgl.h>
4+
5+
#include "displayapp/DisplayApp.h"
6+
#include "displayapp/screens/Styles.h"
7+
#include "displayapp/screens/Screen.h"
8+
#include "displayapp/screens/Symbols.h"
9+
10+
using namespace Pinetime::Applications::Screens;
11+
12+
namespace {
13+
struct Option {
14+
Pinetime::Controllers::Settings::WeatherFormat weatherFormat;
15+
const char* name;
16+
};
17+
18+
constexpr std::array<Option, 2> options = {{
19+
{Pinetime::Controllers::Settings::WeatherFormat::Metric, "Metric"},
20+
{Pinetime::Controllers::Settings::WeatherFormat::Imperial, "Imperial"},
21+
}};
22+
23+
std::array<CheckboxList::Item, CheckboxList::MaxItems> CreateOptionArray() {
24+
std::array<Pinetime::Applications::Screens::CheckboxList::Item, CheckboxList::MaxItems> optionArray;
25+
for (size_t i = 0; i < CheckboxList::MaxItems; i++) {
26+
if (i >= options.size()) {
27+
optionArray[i].name = "";
28+
optionArray[i].enabled = false;
29+
} else {
30+
optionArray[i].name = options[i].name;
31+
optionArray[i].enabled = true;
32+
}
33+
}
34+
return optionArray;
35+
}
36+
37+
uint32_t GetDefaultOption(Pinetime::Controllers::Settings::WeatherFormat currentOption) {
38+
for (size_t i = 0; i < options.size(); i++) {
39+
if (options[i].weatherFormat == currentOption) {
40+
return i;
41+
}
42+
}
43+
return 0;
44+
}
45+
}
46+
47+
SettingWeatherFormat::SettingWeatherFormat(Pinetime::Controllers::Settings& settingsController)
48+
: checkboxList(
49+
0,
50+
1,
51+
"Weather format",
52+
Symbols::clock,
53+
GetDefaultOption(settingsController.GetWeatherFormat()),
54+
[&settings = settingsController](uint32_t index) {
55+
settings.SetWeatherFormat(options[index].weatherFormat);
56+
settings.SaveSettings();
57+
},
58+
CreateOptionArray()) {
59+
}
60+
61+
SettingWeatherFormat::~SettingWeatherFormat() {
62+
lv_obj_clean(lv_scr_act());
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <array>
4+
#include <cstdint>
5+
#include <lvgl/lvgl.h>
6+
7+
#include "components/settings/Settings.h"
8+
#include "displayapp/screens/Screen.h"
9+
#include "displayapp/screens/CheckboxList.h"
10+
11+
namespace Pinetime {
12+
13+
namespace Applications {
14+
namespace Screens {
15+
16+
class SettingWeatherFormat : public Screen {
17+
public:
18+
explicit SettingWeatherFormat(Pinetime::Controllers::Settings& settingsController);
19+
~SettingWeatherFormat() override;
20+
21+
private:
22+
CheckboxList checkboxList;
23+
};
24+
}
25+
}
26+
}

src/displayapp/screens/settings/Settings.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace Pinetime {
2929
static constexpr int entriesPerScreen = 4;
3030

3131
// Increment this when more space is needed
32-
static constexpr int nScreens = 3;
32+
static constexpr int nScreens = 4;
3333

3434
static constexpr std::array<List::Applications, entriesPerScreen * nScreens> entries {{
3535
{Symbols::sun, "Display", Apps::SettingDisplay},
@@ -39,12 +39,14 @@ namespace Pinetime {
3939

4040
{Symbols::shoe, "Steps", Apps::SettingSteps},
4141
{Symbols::clock, "Date&Time", Apps::SettingSetDateTime},
42+
{Symbols::cloudSunRain, "Weather", Apps::SettingWeatherFormat},
4243
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
43-
{Symbols::clock, "Chimes", Apps::SettingChimes},
4444

45+
{Symbols::clock, "Chimes", Apps::SettingChimes},
4546
{Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
4647
{Symbols::check, "Firmware", Apps::FirmwareValidation},
4748
{Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
49+
4850
{Symbols::list, "About", Apps::SysInfo},
4951

5052
// {Symbols::none, "None", Apps::None},

0 commit comments

Comments
 (0)