mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-02-18 00:17:40 +01:00
implement rssi
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user