Skip to content

Commit 31392a3

Browse files
committed
Restore FindMyPhone UI after task sent.
1 parent c0d5dca commit 31392a3

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

src/components/ble/ImmediateAlertClient.cpp

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

102-
void ImmediateAlertClient::sendImmediateAlert(ImmediateAlertClient::Levels level) {
102+
bool ImmediateAlertClient::sendImmediateAlert(ImmediateAlertClient::Levels level) {
103103

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

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

108108
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
109-
return;
109+
return false;
110110
}
111111

112112
ble_gattc_write_no_rsp(connectionHandle, alertLevelHandle, om);
113-
113+
return true;
114114
}

src/components/ble/ImmediateAlertClient.h

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

29-
void sendImmediateAlert(Levels level);
29+
bool sendImmediateAlert(Levels level);
3030

3131
static constexpr const ble_uuid16_t* Uuid() {
3232
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)
@@ -27,7 +38,8 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA
2738

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

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

3345
bt_none = lv_btn_create(container, nullptr);
@@ -56,8 +68,6 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA
5668
label_high = lv_label_create(bt_high, nullptr);
5769
lv_label_set_text_static(label_high, "High");
5870
lv_obj_set_style_local_bg_color(bt_high, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED );
59-
60-
UpdateImmediateAlerts();
6171
}
6272

6373
FindMyPhone::~FindMyPhone() {
@@ -89,7 +99,29 @@ void FindMyPhone::UpdateImmediateAlerts() {
8999
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
90100
break;
91101
}
92-
immediateAlertClient.sendImmediateAlert(last_level);
102+
if (immediateAlertClient.sendImmediateAlert(last_level)) {
103+
lv_label_set_text_static(label_title, alertSentLabelText);
104+
} else {
105+
lv_label_set_text_static(label_title, noConnectionLabelText);
106+
}
107+
ScheduleRestoreLabelTask();
108+
}
93109

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

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

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)