mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-10-22 15:11:51 +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);
|
||||
}
|
||||
|
||||
void ImmediateAlertClient::sendImmediateAlert(ImmediateAlertClient::Levels level) {
|
||||
bool ImmediateAlertClient::sendImmediateAlert(ImmediateAlertClient::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;
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
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() {
|
||||
return &ImmediateAlertClient::immediateAlertClientUuid;
|
||||
|
|
|
@ -7,10 +7,21 @@
|
|||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
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) {
|
||||
auto* screen = static_cast<FindMyPhone*>(obj->user_data);
|
||||
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} {
|
||||
|
@ -26,7 +37,8 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA
|
|||
|
||||
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);
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
UpdateImmediateAlerts();
|
||||
}
|
||||
|
||||
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);
|
||||
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 ScheduleRestoreLabelTask();
|
||||
void StopRestoreLabelTask();
|
||||
void RestoreLabelText();
|
||||
|
||||
private:
|
||||
Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient;
|
||||
|
||||
|
@ -39,7 +43,7 @@ namespace Pinetime {
|
|||
lv_obj_t* label_none;
|
||||
lv_obj_t* label_high;
|
||||
lv_obj_t* label_mild;
|
||||
|
||||
lv_task_t* taskRestoreLabelText = nullptr;
|
||||
|
||||
Pinetime::Controllers::ImmediateAlertClient::Levels last_level;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue