summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWesley Ellis <tahnok@gmail.com>2025-02-27 20:57:19 -0500
committerWesley Ellis <tahnok@gmail.com>2025-02-28 11:36:39 -0500
commitff9c4885bfc4984668477d45d839ce3cd9ddb7a8 (patch)
treec977932f3e28f2eba58db24bbacb7b159c271459
parentd147c92053c2ed577bf44aca0e92bfcd20b75fab (diff)
downloadtangara-fw-ff9c4885bfc4984668477d45d839ce3cd9ddb7a8.tar.gz
Trim whitespace from end of bluetooth device names
I have a speaker at home with a name of "Pebble V3\r\n" that renders poorly without this change.
-rw-r--r--src/drivers/bluetooth.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/drivers/bluetooth.cpp b/src/drivers/bluetooth.cpp
index 64e45e23..3697b33d 100644
--- a/src/drivers/bluetooth.cpp
+++ b/src/drivers/bluetooth.cpp
@@ -364,8 +364,21 @@ auto Scanner::HandleDeviceDiscovery(const esp_bt_gap_cb_param_t& param)
return;
}
- device.name = std::pmr::string{reinterpret_cast<char*>(name),
- static_cast<size_t>(length)};
+ // Create string from the device name
+ std::pmr::string deviceName{reinterpret_cast<char*>(name),
+ static_cast<size_t>(length)};
+
+ // Trim trailing whitespace (spaces, tabs, \r, \n)
+ const std::string::size_type lastChar = deviceName.find_last_not_of(" \n\r\t");
+ if (lastChar != std::string::npos) {
+ deviceName.erase(lastChar + 1);
+ }
+
+ if (deviceName.empty()) {
+ return;
+ }
+
+ device.name = deviceName;
events::DeviceDiscovered ev{.device = device};
tinyfsm::FsmList<bluetooth::BluetoothState>::dispatch(ev);
}