summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcooljqln <cooljqln@noreply.codeberg.org>2025-03-05 02:37:55 +0000
committercooljqln <cooljqln@noreply.codeberg.org>2025-03-05 02:37:55 +0000
commit42c2a4f2445ff56a2a0a78c4ef265e5be346d40d (patch)
tree508b9e6b4d151b4d25237cae36f55d9031c43b1f /src
parent826190edcf14980f6a31f209552ec34d7fcbb746 (diff)
parentff9c4885bfc4984668477d45d839ce3cd9ddb7a8 (diff)
downloadtangara-fw-42c2a4f2445ff56a2a0a78c4ef265e5be346d40d.tar.gz
Merge pull request 'Trim whitespace from end of bluetooth device names' (#288) from tahnok/tangara-fw:trim-bt-name-whitespace into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/288 Reviewed-by: cooljqln <cooljqln@noreply.codeberg.org>
Diffstat (limited to 'src')
-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 1fd80c51..4e17011a 100644
--- a/src/drivers/bluetooth.cpp
+++ b/src/drivers/bluetooth.cpp
@@ -366,8 +366,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);
}