Implement readRSSI on Android and Darwin (#203)
This commit is contained in:
@@ -113,6 +113,12 @@ class MockUniversalBle extends UniversalBlePlatform {
|
||||
return 512;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> readRssi(String deviceId) async {
|
||||
await Future.delayed(const Duration(milliseconds: 500));
|
||||
return -50; // Mock RSSI value in dBm
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> setNotifiable(String deviceId, String service,
|
||||
String characteristic, BleInputProperty bleInputProperty) async {}
|
||||
|
||||
@@ -1097,6 +1097,30 @@ class _PeripheralDetailPageState extends State<PeripheralDetailPage> {
|
||||
),
|
||||
),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
onPressed: isConnected
|
||||
? () async {
|
||||
try {
|
||||
int rssi = await bleDevice.readRssi();
|
||||
_addLog('RSSI', '$rssi dBm');
|
||||
} catch (e) {
|
||||
_addLog('ReadRssiError (${e.runtimeType})', e);
|
||||
}
|
||||
}
|
||||
: null,
|
||||
icon: const Icon(Icons.signal_cellular_alt),
|
||||
label: const Text('Get RSSI'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: colorScheme.onSurface,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (BleCapabilities.supportsRequestMtuApi)
|
||||
ElevatedButton.icon(
|
||||
onPressed: isConnected
|
||||
|
||||
Reference in New Issue
Block a user