Skip to content

Commit f33578a

Browse files
committed
Show communication failure in UI.
1 parent 58944b5 commit f33578a

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/components/ble/ImmediateAlertClient.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ bool ImmediateAlertClient::SendImmediateAlert(ImmediateAlertClient::Levels level
9494
return false;
9595
}
9696

97-
ble_gattc_write_no_rsp(connectionHandle, *alertLevelHandle, om);
98-
return true;
97+
return ble_gattc_write_no_rsp(connectionHandle, *alertLevelHandle, om) == 0;
9998
}
10099

101100
int ImmediateAlertClient::OnDiscoveryEventCallback(uint16_t conn_handle,

src/displayapp/screens/FindMyPhone.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ const FindMyPhone::LabelState FindMyPhone::alertingLabelState {
4343
.color = LV_COLOR_RED,
4444
};
4545

46+
const FindMyPhone::LabelState FindMyPhone::sendFailedLabelState {
47+
.text = "Communication fail",
48+
.color = LV_COLOR_WHITE,
49+
};
50+
4651
FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient) : immediateAlertClient {immediateAlertClient} {
4752
container = lv_cont_create(lv_scr_act(), nullptr);
4853

@@ -92,7 +97,11 @@ void FindMyPhone::OnImmediateAlertEvent(lv_obj_t* obj, lv_event_t event) {
9297
ASSERT(false);
9398
return;
9499
}
95-
immediateAlertClient.SendImmediateAlert(*lastUserInitiatedLevel);
100+
if (immediateAlertClient.SendImmediateAlert(*lastUserInitiatedLevel)) {
101+
lastSendFailed = false;
102+
} else {
103+
lastSendFailed = true;
104+
}
96105
}
97106
}
98107

@@ -106,6 +115,9 @@ const FindMyPhone::LabelState& FindMyPhone::GetLabelState() const {
106115
case Pinetime::Controllers::ImmediateAlertClient::State::Connected:
107116
break;
108117
}
118+
if (lastSendFailed) {
119+
return sendFailedLabelState;
120+
}
109121
// Conntected state handling.
110122
if (!lastUserInitiatedLevel.has_value()) {
111123
return defaultLabelState;
@@ -132,6 +144,7 @@ void FindMyPhone::Refresh() {
132144
lv_obj_add_state(btnStop, LV_STATE_DISABLED);
133145
lv_obj_add_state(btnRing, LV_STATE_DISABLED);
134146
lastUserInitiatedLevel = std::nullopt;
147+
lastSendFailed = false;
135148
}
136149
const auto& label_state = GetLabelState();
137150
lv_obj_set_style_local_text_color(lblTitle, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, label_state.color);

src/displayapp/screens/FindMyPhone.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace Pinetime {
4444
static const LabelState noServiceLabelState;
4545
static const LabelState defaultLabelState;
4646
static const LabelState alertingLabelState;
47+
static const LabelState sendFailedLabelState;
4748
const LabelState& GetLabelState() const;
4849

4950
lv_obj_t* container;
@@ -54,6 +55,7 @@ namespace Pinetime {
5455
lv_obj_t* lblRing;
5556
lv_task_t* refreshTask = nullptr;
5657

58+
bool lastSendFailed = false;
5759
std::optional<Pinetime::Controllers::ImmediateAlertClient::Levels> lastUserInitiatedLevel;
5860
};
5961
}

0 commit comments

Comments
 (0)