Files
StarPilot/openpilot/starpilot/galaxy/web/js/bluetooth-devices.js
T
firestar5683 fab3ec9aeb Galaxy UI
Add Galaxy web assets and client settings interfaces with their bundled vendor notices.

Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>

Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 19:56:17 -05:00

22 lines
872 B
JavaScript

export function hasBluetoothName(device) {
if (typeof device?.name !== "string") return false
const name = device.name.trim()
const address = name.replace(/^[[(]|[\])]$/g, "").replace(/^dev_/i, "").replace(/[:.\s_-]/g, "")
return name.length > 0 && !/^[0-9a-f]{12}$/i.test(address)
}
// Keep discovery rows in their first-seen position while updating live state.
export class BluetoothDeviceList {
constructor() { this.reset() }
reset() { this.order = [] }
update(devices) {
const current = new Map()
for (const device of devices) {
if (!hasBluetoothName(device)) continue
current.set(device.address, { ...device, name: device.name.trim() })
if (!this.order.includes(device.address)) this.order.push(device.address)
}
return this.order.filter((address) => current.has(address)).map((address) => current.get(address))
}
}