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>
custom
cooljqln 2 months ago
commit 42c2a4f244
  1. 17
      src/drivers/bluetooth.cpp

@ -366,8 +366,21 @@ auto Scanner::HandleDeviceDiscovery(const esp_bt_gap_cb_param_t& param)
return; return;
} }
device.name = std::pmr::string{reinterpret_cast<char*>(name), // Create string from the device name
static_cast<size_t>(length)}; 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}; events::DeviceDiscovered ev{.device = device};
tinyfsm::FsmList<bluetooth::BluetoothState>::dispatch(ev); tinyfsm::FsmList<bluetooth::BluetoothState>::dispatch(ev);
} }

Loading…
Cancel
Save