Skip to content

Commit e73ac92

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 93d7da1 commit e73ac92

File tree

9 files changed

+124
-4
lines changed

9 files changed

+124
-4
lines changed

src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ list(APPEND SOURCE_FILES
417417
displayapp/screens/settings/SettingChimes.cpp
418418
displayapp/screens/settings/SettingShakeThreshold.cpp
419419
displayapp/screens/settings/SettingBluetooth.cpp
420+
displayapp/screens/settings/SettingDoubleClick.cpp
420421

421422
## Watch faces
422423
displayapp/screens/WatchFaceAnalog.cpp

src/components/settings/Settings.h

+12
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Pinetime {
1414
enum class Notification : uint8_t { On, Off, Sleep };
1515
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
1616
enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 };
17+
enum class DoubleClickAction : uint8_t { GoToNotifications, AudioNext };
1718
enum class Colors : uint8_t {
1819
White,
1920
Silver,
@@ -249,6 +250,16 @@ namespace Pinetime {
249250
return settings.wakeUpMode;
250251
}
251252

253+
void SetDoubleClickAction(DoubleClickAction action) {
254+
if (settings.doubleClickAction != action)
255+
settingsChanged = true;
256+
settings.doubleClickAction = action;
257+
}
258+
259+
DoubleClickAction GetDoubleClickAction() {
260+
return settings.doubleClickAction;
261+
}
262+
252263
bool isWakeUpModeOn(const WakeUpMode mode) const {
253264
return getWakeUpModes()[static_cast<size_t>(mode)];
254265
}
@@ -308,6 +319,7 @@ namespace Pinetime {
308319
uint16_t shakeWakeThreshold = 150;
309320

310321
Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
322+
DoubleClickAction doubleClickAction;
311323
};
312324

313325
SettingsData settings;

src/displayapp/DisplayApp.cpp

+19-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
#include "UserApps.h"
@@ -360,9 +362,7 @@ void DisplayApp::Refresh() {
360362
LoadNewScreen(Apps::SysInfo, DisplayApp::FullRefreshDirections::Up);
361363
break;
362364
case Messages::ButtonDoubleClicked:
363-
if (currentApp != Apps::Notifications && currentApp != Apps::NotificationsPreview) {
364-
LoadNewScreen(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
365-
}
365+
HandleDoubleClick();
366366
break;
367367

368368
case Messages::BleFirmwareUpdateStarted:
@@ -507,6 +507,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
507507
case Apps::SettingWakeUp:
508508
currentScreen = std::make_unique<Screens::SettingWakeUp>(settingsController);
509509
break;
510+
case Apps::SettingDoubleClick:
511+
currentScreen = std::make_unique<Screens::SettingDoubleClick>(settingsController);
512+
break;
510513
case Apps::SettingDisplay:
511514
currentScreen = std::make_unique<Screens::SettingDisplay>(this, settingsController);
512515
break;
@@ -632,3 +635,16 @@ void DisplayApp::ApplyBrightness() {
632635
}
633636
brightnessController.Set(brightness);
634637
}
638+
639+
void DisplayApp::HandleDoubleClick() {
640+
switch (settingsController.GetDoubleClickAction()) {
641+
case Controllers::Settings::DoubleClickAction::GoToNotifications:
642+
if (currentApp != Apps::Notifications && currentApp != Apps::NotificationsPreview) {
643+
LoadNewScreen(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
644+
}
645+
break;
646+
case Controllers::Settings::DoubleClickAction::AudioNext:
647+
systemTask->nimble().music().event(Controllers::MusicService::EVENT_MUSIC_NEXT);
648+
break;
649+
}
650+
}

src/displayapp/DisplayApp.h

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ namespace Pinetime {
129129
DisplayApp::FullRefreshDirections nextDirection;
130130
System::BootErrors bootError;
131131
void ApplyBrightness();
132+
void HandleDoubleClick();
132133

133134
static constexpr size_t returnAppStackSize = 10;
134135
Utility::StaticStack<Apps, returnAppStackSize> returnAppStack;

src/displayapp/apps/Apps.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ namespace Pinetime {
4141
SettingChimes,
4242
SettingShakeThreshold,
4343
SettingBluetooth,
44+
SettingsDoubleClick,
4445
Error,
4546
Weather
4647
};

src/displayapp/screens/Symbols.h

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ namespace Pinetime {
3939
static constexpr const char* eye = "\xEF\x81\xAE";
4040
static constexpr const char* home = "\xEF\x80\x95";
4141
static constexpr const char* sleep = "\xEE\xBD\x84";
42+
static constexpr const char* angleDoubleRight = "\xEF\x84\x81";
4243

4344
// fontawesome_weathericons.c
4445
// 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

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ namespace Pinetime {
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::cloudSunRain, "Weather", Apps::SettingWeatherFormat},

0 commit comments

Comments
 (0)