Try to implement find my phone feature #343

Co-authored-by: Vyacheslav Chigrin <vyacheslav.chigrin@izba.dev>
This commit is contained in:
Jozef Mlich 2023-10-19 07:54:22 +02:00 committed by Vyacheslav Chigrin
parent f8f8993fac
commit 0e1a074720
12 changed files with 135 additions and 5 deletions

View file

@ -385,6 +385,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/Notifications.cpp
displayapp/screens/Twos.cpp
displayapp/screens/HeartRate.cpp
displayapp/screens/FindMyPhone.cpp
displayapp/screens/FlashLight.cpp
displayapp/screens/List.cpp
displayapp/screens/CheckboxList.cpp
@ -606,6 +607,7 @@ set(INCLUDE_FILES
displayapp/Apps.h
displayapp/screens/Notifications.h
displayapp/screens/HeartRate.h
displayapp/screens/FindMyPhone.h
displayapp/screens/Metronome.h
displayapp/screens/Motion.h
displayapp/screens/Timer.h
@ -832,7 +834,7 @@ if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
# add_definitions(-DCLOCK_CONFIG_LOG_LEVEL=4)
# add_definitions(-DRTC_CONFIG_LOG_ENABLED=1)
# add_definitions(-DRTC_CONFIG_LOG_LEVEL=4)
# Nimble Logging
add_definitions(-DMYNEWT_VAL_NEWT_FEATURE_LOGCFG=1)
# add_definitions(-DMYNEWT_VAL_LOG_LEVEL=0)

View file

@ -73,3 +73,17 @@ int ImmediateAlertService::OnAlertLevelChanged(uint16_t attributeHandle, ble_gat
return 0;
}
void ImmediateAlertService::sendImmediateAlert(ImmediateAlertService::Levels level) {
auto* om = ble_hs_mbuf_from_flat(&level, 1);
uint16_t connectionHandle = systemTask.nimble().connHandle();
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
return;
}
ble_gattc_notify_custom(connectionHandle, alertLevelHandle, om);
}

View file

@ -21,6 +21,8 @@ namespace Pinetime {
void Init();
int OnAlertLevelChanged(uint16_t attributeHandle, ble_gatt_access_ctxt* context);
void sendImmediateAlert(Levels level);
private:
Pinetime::System::SystemTask& systemTask;
NotificationManager& notificationManager;

View file

@ -45,7 +45,7 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
musicService {*this},
weatherService {dateTimeController},
batteryInformationService {batteryController},
immediateAlertService {systemTask, notificationManager},
iaService {systemTask, notificationManager},
heartRateService {*this, heartRateController},
motionService {*this, motionController},
fsService {systemTask, fs},
@ -94,7 +94,7 @@ void NimbleController::Init() {
anService.Init();
dfuService.Init();
batteryInformationService.Init();
immediateAlertService.Init();
iaService.Init();
heartRateService.Init();
motionService.Init();
fsService.Init();

View file

@ -71,6 +71,10 @@ namespace Pinetime {
return weatherService;
};
Pinetime::Controllers::ImmediateAlertService& immediateAlertService() {
return iaService;
}
uint16_t connHandle();
void NotifyBatteryLevel(uint8_t level);
@ -102,7 +106,7 @@ namespace Pinetime {
SimpleWeatherService weatherService;
NavigationService navService;
BatteryInformationService batteryInformationService;
ImmediateAlertService immediateAlertService;
ImmediateAlertService iaService;
HeartRateService heartRateService;
MotionService motionService;
FSService fsService;

View file

@ -1,6 +1,7 @@
#include "displayapp/DisplayApp.h"
#include <libraries/log/nrf_log.h>
#include "displayapp/screens/HeartRate.h"
#include "displayapp/screens/FindMyPhone.h"
#include "displayapp/screens/Motion.h"
#include "displayapp/screens/Timer.h"
#include "displayapp/screens/Alarm.h"

View file

@ -42,6 +42,7 @@ namespace Pinetime {
SettingChimes,
SettingShakeThreshold,
SettingBluetooth,
FindMyPhone,
Error
};

View file

@ -13,6 +13,7 @@ else ()
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Dice")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Metronome")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Navigation")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::FindMyPhone")
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Weather")
#set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Motion")
set(USERAPP_TYPES "${DEFAULT_USER_APP_TYPES}" CACHE STRING "List of user apps to build into the firmware")

View file

@ -7,7 +7,7 @@
},
{
"file": "FontAwesome5-Solid+Brands+Regular.woff",
"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"
"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"
}
],
"bpp": 1,

View file

@ -0,0 +1,55 @@
#include "displayapp/screens/FindMyPhone.h"
#include <lvgl/lvgl.h>
#include "displayapp/DisplayApp.h"
#include "displayapp/InfiniTimeTheme.h"
using namespace Pinetime::Applications::Screens;
namespace {
void btnStartStopEventHandler(lv_obj_t* obj, lv_event_t event) {
auto* screen = static_cast<FindMyPhone*>(obj->user_data);
screen->OnStartStopEvent(event);
}
}
FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertService& immediateAlertService)
: immediateAlertService {immediateAlertService} {
isFindMyPhoneRunning = false;
label_title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(label_title, "Find my phone");
lv_obj_align(label_title, nullptr, LV_ALIGN_CENTER, 0, -40);
btn_startStop = lv_btn_create(lv_scr_act(), nullptr);
btn_startStop->user_data = this;
lv_obj_set_height(btn_startStop, 50);
lv_obj_set_event_cb(btn_startStop, btnStartStopEventHandler);
lv_obj_align(btn_startStop, label_title, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
label_startStop = lv_label_create(btn_startStop, nullptr);
UpdateStartStopButton(isFindMyPhoneRunning);
}
FindMyPhone::~FindMyPhone() {
lv_obj_clean(lv_scr_act());
}
void FindMyPhone::OnStartStopEvent(lv_event_t event) {
if (event == LV_EVENT_CLICKED) {
isFindMyPhoneRunning = !isFindMyPhoneRunning;
UpdateStartStopButton(isFindMyPhoneRunning);
}
}
void FindMyPhone::UpdateStartStopButton(bool isRunning) {
if (isRunning) {
immediateAlertService.sendImmediateAlert(Pinetime::Controllers::ImmediateAlertService::Levels::HighAlert);
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::highlight);
lv_label_set_text_static(label_startStop, "Stop");
} else {
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
lv_label_set_text_static(label_startStop, "Start");
immediateAlertService.sendImmediateAlert(Pinetime::Controllers::ImmediateAlertService::Levels::NoAlert);
}
}

View file

@ -0,0 +1,49 @@
#pragma once
#include <cstdint>
#include <chrono>
#include "displayapp/screens/Screen.h"
#include "Symbols.h"
#include "systemtask/SystemTask.h"
#include <lvgl/src/lv_core/lv_style.h>
#include <lvgl/src/lv_core/lv_obj.h>
namespace Pinetime {
namespace Controllers {
class ImmediateAlertService;
}
namespace Applications {
namespace Screens {
class FindMyPhone : public Screen {
public:
FindMyPhone(Pinetime::Controllers::ImmediateAlertService& immediateAlertService);
~FindMyPhone() override;
void OnStartStopEvent(lv_event_t event);
private:
Pinetime::Controllers::ImmediateAlertService& immediateAlertService;
void UpdateStartStopButton(bool isRunning);
lv_obj_t* label_title;
lv_obj_t* btn_startStop;
lv_obj_t* label_startStop;
bool isFindMyPhoneRunning;
};
}
template <>
struct AppTraits<Apps::FindMyPhone> {
static constexpr Apps app = Apps::FindMyPhone;
static constexpr const char* icon = Screens::Symbols::magnifyingGlass ;
static Screens::Screen* Create(AppControllers& controllers) {
return new Screens::FindMyPhone(controllers.systemTask->nimble().immediateAlertClient());
};
};
}
}

View file

@ -39,6 +39,7 @@ namespace Pinetime {
static constexpr const char* eye = "\xEF\x81\xAE";
static constexpr const char* home = "\xEF\x80\x95";
static constexpr const char* sleep = "\xEE\xBD\x84";
static constexpr const char* magnifyingGlass = "\xEF\x80\x82"; // f002
// fontawesome_weathericons.c
// static constexpr const char* sun = "\xEF\x86\x85";