Skip to content

Commit 7400590

Browse files
committed
Settings: Add double click action settings
This patch adds a global setting determining the executed action upon a double click on the physical watch button.
1 parent 39d5b5c commit 7400590

File tree

10 files changed

+130
-8
lines changed

10 files changed

+130
-8
lines changed

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ list(APPEND SOURCE_FILES
425425
displayapp/screens/settings/SettingChimes.cpp
426426
displayapp/screens/settings/SettingShakeThreshold.cpp
427427
displayapp/screens/settings/SettingBluetooth.cpp
428+
displayapp/screens/settings/SettingDoubleClick.cpp
428429

429430
## Watch faces
430431
displayapp/icons/bg_clock.c

src/components/settings/Settings.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace Pinetime {
1818
RaiseWrist = 2,
1919
Shake = 3,
2020
};
21+
enum class DoubleClickAction : uint8_t { GoToNotifications, AudioNext };
2122
enum class Colors : uint8_t {
2223
White,
2324
Silver,
@@ -242,6 +243,16 @@ namespace Pinetime {
242243
return settings.wakeUpMode;
243244
}
244245

246+
void SetDoubleClickAction(DoubleClickAction action) {
247+
if (settings.doubleClickAction != action)
248+
settingsChanged = true;
249+
settings.doubleClickAction = action;
250+
}
251+
252+
DoubleClickAction GetDoubleClickAction() {
253+
return settings.doubleClickAction;
254+
}
255+
245256
bool isWakeUpModeOn(const WakeUpMode mode) const {
246257
return getWakeUpModes()[static_cast<size_t>(mode)];
247258
}
@@ -279,7 +290,7 @@ namespace Pinetime {
279290
private:
280291
Pinetime::Controllers::FS& fs;
281292

282-
static constexpr uint32_t settingsVersion = 0x0005;
293+
static constexpr uint32_t settingsVersion = 0x0006;
283294

284295
struct SettingsData {
285296
uint32_t version = settingsVersion;
@@ -299,6 +310,7 @@ namespace Pinetime {
299310
std::bitset<4> wakeUpMode {0};
300311
uint16_t shakeWakeThreshold = 150;
301312
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
313+
DoubleClickAction doubleClickAction;
302314
};
303315

304316
SettingsData settings;

src/displayapp/Apps.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace Pinetime {
3737
SettingChimes,
3838
SettingShakeThreshold,
3939
SettingBluetooth,
40+
SettingDoubleClick,
4041
Error
4142
};
4243
}

src/displayapp/DisplayApp.cpp

+20-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "components/ble/BleController.h"
99
#include "components/datetime/DateTimeController.h"
1010
#include "components/ble/NotificationManager.h"
11+
#include "components/ble/MusicService.h"
1112
#include "components/motion/MotionController.h"
1213
#include "components/motor/MotorController.h"
1314
#include "displayapp/screens/ApplicationList.h"
@@ -48,6 +49,7 @@
4849
#include "displayapp/screens/settings/SettingChimes.h"
4950
#include "displayapp/screens/settings/SettingShakeThreshold.h"
5051
#include "displayapp/screens/settings/SettingBluetooth.h"
52+
#include "displayapp/screens/settings/SettingDoubleClick.h"
5153

5254
#include "libs/lv_conf.h"
5355

@@ -341,9 +343,7 @@ void DisplayApp::Refresh() {
341343
LoadNewScreen(Apps::SysInfo, DisplayApp::FullRefreshDirections::Up);
342344
break;
343345
case Messages::ButtonDoubleClicked:
344-
if (currentApp != Apps::Notifications && currentApp != Apps::NotificationsPreview) {
345-
LoadNewScreen(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
346-
}
346+
HandleDoubleClick();
347347
break;
348348

349349
case Messages::BleFirmwareUpdateStarted:
@@ -482,6 +482,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
482482
case Apps::SettingWakeUp:
483483
currentScreen = std::make_unique<Screens::SettingWakeUp>(settingsController);
484484
break;
485+
case Apps::SettingDoubleClick:
486+
currentScreen = std::make_unique<Screens::SettingDoubleClick>(settingsController);
487+
break;
485488
case Apps::SettingDisplay:
486489
currentScreen = std::make_unique<Screens::SettingDisplay>(this, settingsController);
487490
break;
@@ -607,3 +610,17 @@ void DisplayApp::ApplyBrightness() {
607610
}
608611
brightnessController.Set(brightness);
609612
}
613+
614+
void DisplayApp::HandleDoubleClick()
615+
{
616+
switch(settingsController.GetDoubleClickAction()){
617+
case Controllers::Settings::DoubleClickAction::GoToNotifications:
618+
if (currentApp != Apps::Notifications && currentApp != Apps::NotificationsPreview) {
619+
LoadNewScreen(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
620+
}
621+
break;
622+
case Controllers::Settings::DoubleClickAction::AudioNext:
623+
systemTask->nimble().music().event(Controllers::MusicService::EVENT_MUSIC_NEXT);
624+
break;
625+
}
626+
}

src/displayapp/DisplayApp.h

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ namespace Pinetime {
123123
DisplayApp::FullRefreshDirections nextDirection;
124124
System::BootErrors bootError;
125125
void ApplyBrightness();
126+
void HandleDoubleClick();
126127

127128
static constexpr size_t returnAppStackSize = 10;
128129
Utility::StaticStack<Apps, returnAppStackSize> returnAppStack;

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, 0xf101"
1111
}
1212
],
1313
"bpp": 1,

src/displayapp/screens/Symbols.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace Pinetime {
3737
static constexpr const char* eye = "\xEF\x81\xAE";
3838
static constexpr const char* home = "\xEF\x80\x95";
3939
static constexpr const char* sleep = "\xEE\xBD\x84";
40+
static constexpr const char* angleDoubleRight = "\xEF\x84\x81";
4041

4142
// fontawesome_weathericons.c
4243
// static constexpr const char* sun = "\xEF\x86\x85";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "displayapp/screens/settings/SettingDoubleClick.h"
2+
#include <lvgl/lvgl.h>
3+
#include "displayapp/DisplayApp.h"
4+
#include "displayapp/screens/Styles.h"
5+
#include "displayapp/screens/Screen.h"
6+
#include "displayapp/screens/Symbols.h"
7+
8+
using namespace Pinetime::Applications::Screens;
9+
10+
namespace {
11+
struct Option {
12+
Pinetime::Controllers::Settings::DoubleClickAction action;
13+
const char* name;
14+
};
15+
16+
constexpr std::array<Option, 2> options = {{
17+
{Pinetime::Controllers::Settings::DoubleClickAction::GoToNotifications, "Notifications"},
18+
{Pinetime::Controllers::Settings::DoubleClickAction::AudioNext, "Audio Next"},
19+
}};
20+
21+
std::array<CheckboxList::Item, CheckboxList::MaxItems> CreateOptionArray() {
22+
std::array<Pinetime::Applications::Screens::CheckboxList::Item, CheckboxList::MaxItems> optionArray;
23+
for (size_t i = 0; i < CheckboxList::MaxItems; i++) {
24+
if (i >= options.size()) {
25+
optionArray[i].name = "";
26+
optionArray[i].enabled = false;
27+
} else {
28+
optionArray[i].name = options[i].name;
29+
optionArray[i].enabled = true;
30+
}
31+
}
32+
return optionArray;
33+
}
34+
35+
uint32_t GetDefaultOption(Pinetime::Controllers::Settings::DoubleClickAction currentOption) {
36+
for (size_t i = 0; i < options.size(); i++) {
37+
if (options[i].action == currentOption) {
38+
return i;
39+
}
40+
}
41+
return 0;
42+
}
43+
}
44+
45+
SettingDoubleClick::SettingDoubleClick(Pinetime::Controllers::Settings& settingsController)
46+
: checkboxList(
47+
0,
48+
1,
49+
"Double Click",
50+
Symbols::angleDoubleRight,
51+
GetDefaultOption(settingsController.GetDoubleClickAction()),
52+
[&settings = settingsController](uint32_t index) {
53+
settings.SetDoubleClickAction(options[index].action);
54+
settings.SaveSettings();
55+
},
56+
CreateOptionArray()) {
57+
}
58+
59+
SettingDoubleClick::~SettingDoubleClick() {
60+
lv_obj_clean(lv_scr_act());
61+
}
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 SettingDoubleClick : public Screen {
17+
public:
18+
SettingDoubleClick(Pinetime::Controllers::Settings& settingsController);
19+
~SettingDoubleClick() override;
20+
21+
private:
22+
CheckboxList checkboxList;
23+
};
24+
}
25+
}
26+
}

src/displayapp/screens/settings/Settings.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,24 @@ 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},
3636
{Symbols::eye, "Wake Up", Apps::SettingWakeUp},
37+
{Symbols::angleDoubleRight, "Double Click", Apps::SettingDoubleClick},
3738
{Symbols::clock, "Time format", Apps::SettingTimeFormat},
38-
{Symbols::home, "Watch face", Apps::SettingWatchFace},
3939

40+
{Symbols::home, "Watch face", Apps::SettingWatchFace},
4041
{Symbols::shoe, "Steps", Apps::SettingSteps},
4142
{Symbols::clock, "Date&Time", Apps::SettingSetDateTime},
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)