Skip to content

Commit fc976da

Browse files
committed
Restore FindMyPhone UI after task sent.
1 parent 91c03b9 commit fc976da

4 files changed

Lines changed: 45 additions & 9 deletions

File tree

src/components/ble/ImmediateAlertClient.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,16 @@ void ImmediateAlertClient::Discover(uint16_t connectionHandle, std::function<voi
9898
ble_gattc_disc_svc_by_uuid(connectionHandle, &immediateAlertClientUuid.u, OnDiscoveryEventCallback, this);
9999
}
100100

101-
void ImmediateAlertClient::sendImmediateAlert(ImmediateAlertClient::Levels level) {
101+
bool ImmediateAlertClient::sendImmediateAlert(ImmediateAlertClient::Levels level) {
102102

103103
auto* om = ble_hs_mbuf_from_flat(&level, 1);
104104

105105
uint16_t connectionHandle = systemTask.nimble().connHandle();
106106

107107
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
108-
return;
108+
return false;
109109
}
110110

111111
ble_gattc_write_no_rsp(connectionHandle, alertLevelHandle, om);
112-
112+
return true;
113113
}

src/components/ble/ImmediateAlertClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Pinetime {
2525
bool OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error* error, const ble_gatt_svc* service);
2626
int OnCharacteristicDiscoveryEvent(uint16_t conn_handle, const ble_gatt_error* error, const ble_gatt_chr* characteristic);
2727

28-
void sendImmediateAlert(Levels level);
28+
bool sendImmediateAlert(Levels level);
2929

3030
static constexpr const ble_uuid16_t* Uuid() {
3131
return &ImmediateAlertClient::immediateAlertClientUuid;

src/displayapp/screens/FindMyPhone.cpp

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@
77
using namespace Pinetime::Applications::Screens;
88

99
namespace {
10+
static constexpr char defaultLabelText[] = "Find my phone";
11+
static constexpr char alertSentLabelText[] = "Alert sent";
12+
static constexpr char noConnectionLabelText[] = "No connection";
13+
static constexpr auto restoreLabelTimeoutTicks = pdMS_TO_TICKS(2 * 1000);
14+
1015
void btnImmediateAlertEventHandler(lv_obj_t* obj, lv_event_t event) {
1116
auto* screen = static_cast<FindMyPhone*>(obj->user_data);
1217
screen->OnImmediateAlertEvent(obj, event);
1318
}
19+
20+
void RestoreLabelTaskCallback(lv_task_t* task) {
21+
auto* screen = static_cast<FindMyPhone*>(task->user_data);
22+
screen->RestoreLabelText();
23+
screen->StopRestoreLabelTask();
24+
}
1425
}
1526

1627
FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient) : immediateAlertClient {immediateAlertClient} {
@@ -26,7 +37,8 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA
2637

2738
label_title = lv_label_create(lv_scr_act(), nullptr);
2839

29-
lv_label_set_text_static(label_title, "Find my phone");
40+
lv_label_set_text_static(label_title, defaultLabelText);
41+
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
3042
lv_obj_align(label_title, nullptr, LV_ALIGN_CENTER, 0, -40);
3143

3244
bt_none = lv_btn_create(container, nullptr);
@@ -55,8 +67,6 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA
5567
label_high = lv_label_create(bt_high, nullptr);
5668
lv_label_set_text_static(label_high, "High");
5769
lv_obj_set_style_local_bg_color(bt_high, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
58-
59-
UpdateImmediateAlerts();
6070
}
6171

6272
FindMyPhone::~FindMyPhone() {
@@ -88,7 +98,29 @@ void FindMyPhone::UpdateImmediateAlerts() {
8898
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
8999
break;
90100
}
91-
immediateAlertClient.sendImmediateAlert(last_level);
101+
if (immediateAlertClient.sendImmediateAlert(last_level)) {
102+
lv_label_set_text_static(label_title, alertSentLabelText);
103+
} else {
104+
lv_label_set_text_static(label_title, noConnectionLabelText);
105+
}
106+
ScheduleRestoreLabelTask();
107+
}
92108

109+
void FindMyPhone::ScheduleRestoreLabelTask() {
110+
if (taskRestoreLabelText) {
111+
return;
112+
}
113+
taskRestoreLabelText = lv_task_create(RestoreLabelTaskCallback, restoreLabelTimeoutTicks, LV_TASK_PRIO_MID, this);
93114
}
94115

116+
void FindMyPhone::StopRestoreLabelTask() {
117+
if (taskRestoreLabelText) {
118+
lv_task_del(taskRestoreLabelText);
119+
taskRestoreLabelText = nullptr;
120+
}
121+
}
122+
123+
void FindMyPhone::RestoreLabelText() {
124+
lv_label_set_text_static(label_title, defaultLabelText);
125+
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
126+
}

src/displayapp/screens/FindMyPhone.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ namespace Pinetime {
2626

2727
void OnImmediateAlertEvent(lv_obj_t* obj, lv_event_t event);
2828

29+
void ScheduleRestoreLabelTask();
30+
void StopRestoreLabelTask();
31+
void RestoreLabelText();
32+
2933
private:
3034
Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient;
3135

@@ -39,7 +43,7 @@ namespace Pinetime {
3943
lv_obj_t* label_none;
4044
lv_obj_t* label_high;
4145
lv_obj_t* label_mild;
42-
46+
lv_task_t* taskRestoreLabelText = nullptr;
4347

4448
Pinetime::Controllers::ImmediateAlertClient::Levels last_level;
4549
};

0 commit comments

Comments
 (0)