mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-10-22 23:21:53 +02:00
Restore FindMyPhone UI after task sent.
This commit is contained in:
parent
15daf4cb84
commit
0e76bf1766
|
@ -98,16 +98,16 @@ void ImmediateAlertClient::Discover(uint16_t connectionHandle, std::function<voi
|
||||||
ble_gattc_disc_svc_by_uuid(connectionHandle, &immediateAlertClientUuid.u, OnDiscoveryEventCallback, this);
|
ble_gattc_disc_svc_by_uuid(connectionHandle, &immediateAlertClientUuid.u, OnDiscoveryEventCallback, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImmediateAlertClient::sendImmediateAlert(ImmediateAlertClient::Levels level) {
|
bool ImmediateAlertClient::sendImmediateAlert(ImmediateAlertClient::Levels level) {
|
||||||
|
|
||||||
auto* om = ble_hs_mbuf_from_flat(&level, 1);
|
auto* om = ble_hs_mbuf_from_flat(&level, 1);
|
||||||
|
|
||||||
uint16_t connectionHandle = systemTask.nimble().connHandle();
|
uint16_t connectionHandle = systemTask.nimble().connHandle();
|
||||||
|
|
||||||
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
|
if (connectionHandle == 0 || connectionHandle == BLE_HS_CONN_HANDLE_NONE) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ble_gattc_write_no_rsp(connectionHandle, alertLevelHandle, om);
|
ble_gattc_write_no_rsp(connectionHandle, alertLevelHandle, om);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace Pinetime {
|
||||||
bool OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error* error, const ble_gatt_svc* service);
|
bool OnDiscoveryEvent(uint16_t connectionHandle, const ble_gatt_error* error, const ble_gatt_svc* service);
|
||||||
int OnCharacteristicDiscoveryEvent(uint16_t conn_handle, const ble_gatt_error* error, const ble_gatt_chr* characteristic);
|
int OnCharacteristicDiscoveryEvent(uint16_t conn_handle, const ble_gatt_error* error, const ble_gatt_chr* characteristic);
|
||||||
|
|
||||||
void sendImmediateAlert(Levels level);
|
bool sendImmediateAlert(Levels level);
|
||||||
|
|
||||||
static constexpr const ble_uuid16_t* Uuid() {
|
static constexpr const ble_uuid16_t* Uuid() {
|
||||||
return &ImmediateAlertClient::immediateAlertClientUuid;
|
return &ImmediateAlertClient::immediateAlertClientUuid;
|
||||||
|
|
|
@ -7,10 +7,21 @@
|
||||||
using namespace Pinetime::Applications::Screens;
|
using namespace Pinetime::Applications::Screens;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
static constexpr char defaultLabelText[] = "Find my phone";
|
||||||
|
static constexpr char alertSentLabelText[] = "Alert sent";
|
||||||
|
static constexpr char noConnectionLabelText[] = "No connection";
|
||||||
|
static constexpr auto restoreLabelTimeoutTicks = pdMS_TO_TICKS(2 * 1000);
|
||||||
|
|
||||||
void btnImmediateAlertEventHandler(lv_obj_t* obj, lv_event_t event) {
|
void btnImmediateAlertEventHandler(lv_obj_t* obj, lv_event_t event) {
|
||||||
auto* screen = static_cast<FindMyPhone*>(obj->user_data);
|
auto* screen = static_cast<FindMyPhone*>(obj->user_data);
|
||||||
screen->OnImmediateAlertEvent(obj, event);
|
screen->OnImmediateAlertEvent(obj, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RestoreLabelTaskCallback(lv_task_t* task) {
|
||||||
|
auto* screen = static_cast<FindMyPhone*>(task->user_data);
|
||||||
|
screen->RestoreLabelText();
|
||||||
|
screen->StopRestoreLabelTask();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient) : immediateAlertClient {immediateAlertClient} {
|
FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient) : immediateAlertClient {immediateAlertClient} {
|
||||||
|
@ -26,7 +37,8 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA
|
||||||
|
|
||||||
label_title = lv_label_create(lv_scr_act(), nullptr);
|
label_title = lv_label_create(lv_scr_act(), nullptr);
|
||||||
|
|
||||||
lv_label_set_text_static(label_title, "Find my phone");
|
lv_label_set_text_static(label_title, defaultLabelText);
|
||||||
|
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
|
||||||
lv_obj_align(label_title, nullptr, LV_ALIGN_CENTER, 0, -40);
|
lv_obj_align(label_title, nullptr, LV_ALIGN_CENTER, 0, -40);
|
||||||
|
|
||||||
bt_none = lv_btn_create(container, nullptr);
|
bt_none = lv_btn_create(container, nullptr);
|
||||||
|
@ -55,8 +67,6 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA
|
||||||
label_high = lv_label_create(bt_high, nullptr);
|
label_high = lv_label_create(bt_high, nullptr);
|
||||||
lv_label_set_text_static(label_high, "High");
|
lv_label_set_text_static(label_high, "High");
|
||||||
lv_obj_set_style_local_bg_color(bt_high, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
|
lv_obj_set_style_local_bg_color(bt_high, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
|
||||||
|
|
||||||
UpdateImmediateAlerts();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FindMyPhone::~FindMyPhone() {
|
FindMyPhone::~FindMyPhone() {
|
||||||
|
@ -88,7 +98,29 @@ void FindMyPhone::UpdateImmediateAlerts() {
|
||||||
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
|
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
immediateAlertClient.sendImmediateAlert(last_level);
|
if (immediateAlertClient.sendImmediateAlert(last_level)) {
|
||||||
|
lv_label_set_text_static(label_title, alertSentLabelText);
|
||||||
|
} else {
|
||||||
|
lv_label_set_text_static(label_title, noConnectionLabelText);
|
||||||
|
}
|
||||||
|
ScheduleRestoreLabelTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FindMyPhone::ScheduleRestoreLabelTask() {
|
||||||
|
if (taskRestoreLabelText) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
taskRestoreLabelText = lv_task_create(RestoreLabelTaskCallback, restoreLabelTimeoutTicks, LV_TASK_PRIO_MID, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FindMyPhone::StopRestoreLabelTask() {
|
||||||
|
if (taskRestoreLabelText) {
|
||||||
|
lv_task_del(taskRestoreLabelText);
|
||||||
|
taskRestoreLabelText = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FindMyPhone::RestoreLabelText() {
|
||||||
|
lv_label_set_text_static(label_title, defaultLabelText);
|
||||||
|
lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,10 @@ namespace Pinetime {
|
||||||
|
|
||||||
void OnImmediateAlertEvent(lv_obj_t* obj, lv_event_t event);
|
void OnImmediateAlertEvent(lv_obj_t* obj, lv_event_t event);
|
||||||
|
|
||||||
|
void ScheduleRestoreLabelTask();
|
||||||
|
void StopRestoreLabelTask();
|
||||||
|
void RestoreLabelText();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient;
|
Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient;
|
||||||
|
|
||||||
|
@ -39,7 +43,7 @@ namespace Pinetime {
|
||||||
lv_obj_t* label_none;
|
lv_obj_t* label_none;
|
||||||
lv_obj_t* label_high;
|
lv_obj_t* label_high;
|
||||||
lv_obj_t* label_mild;
|
lv_obj_t* label_mild;
|
||||||
|
lv_task_t* taskRestoreLabelText = nullptr;
|
||||||
|
|
||||||
Pinetime::Controllers::ImmediateAlertClient::Levels last_level;
|
Pinetime::Controllers::ImmediateAlertClient::Levels last_level;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue