From 10115923d6eac4e4e128b1dc26eaecffa386b594 Mon Sep 17 00:00:00 2001 From: Vyacheslav Chigrin Date: Sun, 8 Dec 2024 03:09:44 +0300 Subject: [PATCH] Show communication failure in UI. --- src/components/ble/ImmediateAlertClient.cpp | 3 +-- src/displayapp/screens/FindMyPhone.cpp | 15 ++++++++++++++- src/displayapp/screens/FindMyPhone.h | 2 ++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components/ble/ImmediateAlertClient.cpp b/src/components/ble/ImmediateAlertClient.cpp index ad3ac189fc..4b50f6c537 100644 --- a/src/components/ble/ImmediateAlertClient.cpp +++ b/src/components/ble/ImmediateAlertClient.cpp @@ -94,8 +94,7 @@ bool ImmediateAlertClient::SendImmediateAlert(ImmediateAlertClient::Levels level return false; } - ble_gattc_write_no_rsp(connectionHandle, *alertLevelHandle, om); - return true; + return ble_gattc_write_no_rsp(connectionHandle, *alertLevelHandle, om) == 0; } int ImmediateAlertClient::OnDiscoveryEventCallback(uint16_t conn_handle, diff --git a/src/displayapp/screens/FindMyPhone.cpp b/src/displayapp/screens/FindMyPhone.cpp index 45dc9570f3..d6fca72669 100644 --- a/src/displayapp/screens/FindMyPhone.cpp +++ b/src/displayapp/screens/FindMyPhone.cpp @@ -43,6 +43,11 @@ const FindMyPhone::LabelState FindMyPhone::alertingLabelState { .color = LV_COLOR_RED, }; +const FindMyPhone::LabelState FindMyPhone::sendFailedLabelState { + .text = "Communication fail", + .color = LV_COLOR_WHITE, +}; + FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient) : immediateAlertClient {immediateAlertClient} { container = lv_cont_create(lv_scr_act(), nullptr); @@ -92,7 +97,11 @@ void FindMyPhone::OnImmediateAlertEvent(lv_obj_t* obj, lv_event_t event) { ASSERT(false); return; } - immediateAlertClient.SendImmediateAlert(*lastUserInitiatedLevel); + if (immediateAlertClient.SendImmediateAlert(*lastUserInitiatedLevel)) { + lastSendFailed = false; + } else { + lastSendFailed = true; + } } } @@ -106,6 +115,9 @@ const FindMyPhone::LabelState& FindMyPhone::GetLabelState() const { case Pinetime::Controllers::ImmediateAlertClient::State::Connected: break; } + if (lastSendFailed) { + return sendFailedLabelState; + } // Conntected state handling. if (!lastUserInitiatedLevel.has_value()) { return defaultLabelState; @@ -132,6 +144,7 @@ void FindMyPhone::Refresh() { lv_obj_add_state(btnStop, LV_STATE_DISABLED); lv_obj_add_state(btnRing, LV_STATE_DISABLED); lastUserInitiatedLevel = std::nullopt; + lastSendFailed = false; } const auto& label_state = GetLabelState(); lv_obj_set_style_local_text_color(lblTitle, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, label_state.color); diff --git a/src/displayapp/screens/FindMyPhone.h b/src/displayapp/screens/FindMyPhone.h index 92c3b92897..b0561be1de 100644 --- a/src/displayapp/screens/FindMyPhone.h +++ b/src/displayapp/screens/FindMyPhone.h @@ -44,6 +44,7 @@ namespace Pinetime { static const LabelState noServiceLabelState; static const LabelState defaultLabelState; static const LabelState alertingLabelState; + static const LabelState sendFailedLabelState; const LabelState& GetLabelState() const; lv_obj_t* container; @@ -54,6 +55,7 @@ namespace Pinetime { lv_obj_t* lblRing; lv_task_t* refreshTask = nullptr; + bool lastSendFailed = false; std::optional lastUserInitiatedLevel; }; }