Merge pull request #137 from michidk/rssi

Displaying the RSSI of connected devices
This commit is contained in:
jonasbark
2025-10-26 20:54:05 +01:00
committed by GitHub
2 changed files with 29 additions and 1 deletions

View File

@@ -53,6 +53,16 @@ class Connection {
}
};
UniversalBle.onScanResult = (result) {
// Update RSSI for already connected devices
final existingDevice = devices.firstOrNullWhere(
(e) => e is BluetoothDevice && e.device.deviceId == result.deviceId,
);
if (existingDevice != null && existingDevice is BluetoothDevice) {
existingDevice.rssi = result.rssi;
_connectionStreams.add(existingDevice); // Notify UI of update
return;
}
if (_lastScanResult.none((e) => e.deviceId == result.deviceId)) {
_lastScanResult.add(result);

View File

@@ -22,10 +22,13 @@ abstract class BluetoothDevice extends BaseDevice {
final BleDevice scanResult;
BluetoothDevice(this.scanResult, {required super.availableButtons, super.isBeta = false})
: super(scanResult.name ?? 'Unknown Device');
: super(scanResult.name ?? 'Unknown Device') {
rssi = scanResult.rssi;
}
int? batteryLevel;
String? firmwareVersion;
int? rssi;
static List<String> servicesToScan = [
ZwiftConstants.ZWIFT_CUSTOM_SERVICE_UUID,
@@ -157,6 +160,21 @@ abstract class BluetoothDevice extends BaseDevice {
style: TextStyle(fontWeight: FontWeight.bold),
),
if (isBeta) BetaPill(),
if (rssi != null) ...[
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Icon(
switch (rssi!) {
>= -50 => Icons.signal_cellular_4_bar,
>= -60 => Icons.signal_cellular_alt_2_bar,
>= -70 => Icons.signal_cellular_alt_1_bar,
_ => Icons.signal_cellular_alt,
},
size: 18,
),
),
Text('$rssi dBm'),
],
if (batteryLevel != null) ...[
Icon(switch (batteryLevel!) {
>= 80 => Icons.battery_full,