Skip to content

Commit 201e848

Browse files
jmlichvchigrin
andcommitted
Try to implement find my phone feature #343
Co-authored-by: Vyacheslav Chigrin <[email protected]>
1 parent 6b5235c commit 201e848

File tree

12 files changed

+135
-5
lines changed

12 files changed

+135
-5
lines changed

src/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ list(APPEND SOURCE_FILES
385385
displayapp/screens/Notifications.cpp
386386
displayapp/screens/Twos.cpp
387387
displayapp/screens/HeartRate.cpp
388+
displayapp/screens/FindMyPhone.cpp
388389
displayapp/screens/FlashLight.cpp
389390
displayapp/screens/List.cpp
390391
displayapp/screens/CheckboxList.cpp
@@ -606,6 +607,7 @@ set(INCLUDE_FILES
606607
displayapp/Apps.h
607608
displayapp/screens/Notifications.h
608609
displayapp/screens/HeartRate.h
610+
displayapp/screens/FindMyPhone.h
609611
displayapp/screens/Metronome.h
610612
displayapp/screens/Motion.h
611613
displayapp/screens/Timer.h
@@ -832,7 +834,7 @@ if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
832834
# add_definitions(-DCLOCK_CONFIG_LOG_LEVEL=4)
833835
# add_definitions(-DRTC_CONFIG_LOG_ENABLED=1)
834836
# add_definitions(-DRTC_CONFIG_LOG_LEVEL=4)
835-
837+
836838
# Nimble Logging
837839
add_definitions(-DMYNEWT_VAL_NEWT_FEATURE_LOGCFG=1)
838840
# add_definitions(-DMYNEWT_VAL_LOG_LEVEL=0)

src/components/ble/ImmediateAlertService.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,17 @@ int ImmediateAlertService::OnAlertLevelChanged(uint16_t attributeHandle, ble_gat
7373

7474
return 0;
7575
}
76+
77+
void ImmediateAlertService::sendImmediateAlert(ImmediateAlertService::Levels level) {
78+
79+
auto* om = ble_hs_mbuf_from_flat(&level, 1);
80+
81+
uint16_t connectionHandle = systemTask.nimble().connHandle();
82+
83+
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
84+
return;
85+
}
86+
87+
ble_gattc_notify_custom(connectionHandle, alertLevelHandle, om);
88+
89+
}

src/components/ble/ImmediateAlertService.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace Pinetime {
2121
void Init();
2222
int OnAlertLevelChanged(uint16_t attributeHandle, ble_gatt_access_ctxt* context);
2323

24+
void sendImmediateAlert(Levels level);
25+
2426
private:
2527
Pinetime::System::SystemTask& systemTask;
2628
NotificationManager& notificationManager;

src/components/ble/NimbleController.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
4545
musicService {*this},
4646
weatherService {dateTimeController},
4747
batteryInformationService {batteryController},
48-
immediateAlertService {systemTask, notificationManager},
48+
iaService {systemTask, notificationManager},
4949
heartRateService {*this, heartRateController},
5050
motionService {*this, motionController},
5151
fsService {systemTask, fs},
@@ -94,7 +94,7 @@ void NimbleController::Init() {
9494
anService.Init();
9595
dfuService.Init();
9696
batteryInformationService.Init();
97-
immediateAlertService.Init();
97+
iaService.Init();
9898
heartRateService.Init();
9999
motionService.Init();
100100
fsService.Init();

src/components/ble/NimbleController.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ namespace Pinetime {
7171
return weatherService;
7272
};
7373

74+
Pinetime::Controllers::ImmediateAlertService& immediateAlertService() {
75+
return iaService;
76+
}
77+
7478
uint16_t connHandle();
7579
void NotifyBatteryLevel(uint8_t level);
7680

@@ -102,7 +106,7 @@ namespace Pinetime {
102106
SimpleWeatherService weatherService;
103107
NavigationService navService;
104108
BatteryInformationService batteryInformationService;
105-
ImmediateAlertService immediateAlertService;
109+
ImmediateAlertService iaService;
106110
HeartRateService heartRateService;
107111
MotionService motionService;
108112
FSService fsService;

src/displayapp/DisplayApp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "displayapp/DisplayApp.h"
22
#include <libraries/log/nrf_log.h>
33
#include "displayapp/screens/HeartRate.h"
4+
#include "displayapp/screens/FindMyPhone.h"
45
#include "displayapp/screens/Motion.h"
56
#include "displayapp/screens/Timer.h"
67
#include "displayapp/screens/Alarm.h"

src/displayapp/apps/Apps.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace Pinetime {
4242
SettingChimes,
4343
SettingShakeThreshold,
4444
SettingBluetooth,
45+
FindMyPhone,
4546
Error
4647
};
4748

src/displayapp/apps/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ else ()
1313
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Dice")
1414
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Metronome")
1515
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Navigation")
16+
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::FindMyPhone")
1617
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Weather")
1718
#set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Motion")
1819
set(USERAPP_TYPES "${DEFAULT_USER_APP_TYPES}" CACHE STRING "List of user apps to build into the firmware")

src/displayapp/fonts/fonts.json

Lines changed: 1 addition & 1 deletion
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, 0xf0f3, 0xf522, 0xf743"
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, 0xf0f3, 0xf522, 0xf743, 0xf002"
1111
}
1212
],
1313
"bpp": 1,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include "displayapp/screens/FindMyPhone.h"
2+
#include <lvgl/lvgl.h>
3+
4+
#include "displayapp/DisplayApp.h"
5+
#include "displayapp/InfiniTimeTheme.h"
6+
7+
using namespace Pinetime::Applications::Screens;
8+
9+
namespace {
10+
void btnStartStopEventHandler(lv_obj_t* obj, lv_event_t event) {
11+
auto* screen = static_cast<FindMyPhone*>(obj->user_data);
12+
screen->OnStartStopEvent(event);
13+
}
14+
}
15+
16+
FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertService& immediateAlertService)
17+
: immediateAlertService {immediateAlertService} {
18+
isFindMyPhoneRunning = false;
19+
label_title = lv_label_create(lv_scr_act(), nullptr);
20+
21+
lv_label_set_text_static(label_title, "Find my phone");
22+
lv_obj_align(label_title, nullptr, LV_ALIGN_CENTER, 0, -40);
23+
24+
btn_startStop = lv_btn_create(lv_scr_act(), nullptr);
25+
btn_startStop->user_data = this;
26+
lv_obj_set_height(btn_startStop, 50);
27+
lv_obj_set_event_cb(btn_startStop, btnStartStopEventHandler);
28+
lv_obj_align(btn_startStop, label_title, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
29+
30+
label_startStop = lv_label_create(btn_startStop, nullptr);
31+
UpdateStartStopButton(isFindMyPhoneRunning);
32+
}
33+
34+
FindMyPhone::~FindMyPhone() {
35+
lv_obj_clean(lv_scr_act());
36+
}
37+
38+
void FindMyPhone::OnStartStopEvent(lv_event_t event) {
39+
if (event == LV_EVENT_CLICKED) {
40+
isFindMyPhoneRunning = !isFindMyPhoneRunning;
41+
UpdateStartStopButton(isFindMyPhoneRunning);
42+
}
43+
}
44+
45+
void FindMyPhone::UpdateStartStopButton(bool isRunning) {
46+
if (isRunning) {
47+
immediateAlertService.sendImmediateAlert(Pinetime::Controllers::ImmediateAlertService::Levels::HighAlert);
48+
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::highlight);
49+
lv_label_set_text_static(label_startStop, "Stop");
50+
} else {
51+
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
52+
lv_label_set_text_static(label_startStop, "Start");
53+
immediateAlertService.sendImmediateAlert(Pinetime::Controllers::ImmediateAlertService::Levels::NoAlert);
54+
}
55+
}

0 commit comments

Comments
 (0)