Skip to content

Commit

Permalink
Show communication failure in UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchigrin committed Dec 8, 2024
1 parent 127f7f2 commit 2006948
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/components/ble/ImmediateAlertClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 14 additions & 1 deletion src/displayapp/screens/FindMyPhone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
}
}

Expand All @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/displayapp/screens/FindMyPhone.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,6 +55,7 @@ namespace Pinetime {
lv_obj_t* lblRing;
lv_task_t* refreshTask = nullptr;

bool lastSendFailed = false;
std::optional<Pinetime::Controllers::ImmediateAlertClient::Levels> lastUserInitiatedLevel;
};
}
Expand Down

0 comments on commit 2006948

Please sign in to comment.