mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
feat: Show self telemetry in device info sheet
Tapping signal/battery in header now also shows device's own telemetry (temperature, humidity, pressure, GPS) when available. Triggers a self telemetry request on sheet open. Data comes from the device contact's telemetry field.
This commit is contained in:
@@ -2363,6 +2363,24 @@ class ConnectionProvider with ChangeNotifier {
|
|||||||
/// - Total storage in KB (if available)
|
/// - Total storage in KB (if available)
|
||||||
///
|
///
|
||||||
/// Results arrive via onBatteryAndStorage callback and update deviceInfo.
|
/// Results arrive via onBatteryAndStorage callback and update deviceInfo.
|
||||||
|
/// Request the companion device's own telemetry (GPS, temp, sensors).
|
||||||
|
/// The response arrives via onTelemetryReceived with the device's own key.
|
||||||
|
Future<void> requestSelfTelemetry() async {
|
||||||
|
if (!_activeService.isConnected) return;
|
||||||
|
try {
|
||||||
|
// Request own telemetry by sending telemetry req with zero-length key
|
||||||
|
final deviceKey = _deviceInfo.publicKey;
|
||||||
|
if (deviceKey != null) {
|
||||||
|
await _activeService.requestTelemetry(
|
||||||
|
Uint8List.fromList(deviceKey),
|
||||||
|
zeroHop: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('⚠️ [Provider] requestSelfTelemetry failed: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> getBatteryAndStorage() async {
|
Future<void> getBatteryAndStorage() async {
|
||||||
if (!_activeService.isConnected) {
|
if (!_activeService.isConnected) {
|
||||||
_error = 'Not connected to device';
|
_error = 'Not connected to device';
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||||||
import 'package:vibration/vibration.dart';
|
import 'package:vibration/vibration.dart';
|
||||||
import '../providers/connection_provider.dart';
|
import '../providers/connection_provider.dart';
|
||||||
import '../providers/app_provider.dart';
|
import '../providers/app_provider.dart';
|
||||||
|
import '../models/contact.dart';
|
||||||
import '../models/device_info.dart' show ConnectionMode, DeviceInfo;
|
import '../models/device_info.dart' show ConnectionMode, DeviceInfo;
|
||||||
import '../providers/messages_provider.dart';
|
import '../providers/messages_provider.dart';
|
||||||
import '../providers/contacts_provider.dart';
|
import '../providers/contacts_provider.dart';
|
||||||
@@ -435,6 +436,19 @@ class _HomeScreenState extends State<HomeScreen>
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showDeviceInfoSheet(BuildContext context, DeviceInfo deviceInfo) {
|
void _showDeviceInfoSheet(BuildContext context, DeviceInfo deviceInfo) {
|
||||||
|
// Request self telemetry so it's fresh
|
||||||
|
context.read<ConnectionProvider>().requestSelfTelemetry();
|
||||||
|
|
||||||
|
// Find the device's own contact to show self telemetry
|
||||||
|
final selfKey = deviceInfo.publicKey;
|
||||||
|
Contact? selfContact;
|
||||||
|
if (selfKey != null) {
|
||||||
|
selfContact = context.read<ContactsProvider>().findContactByKey(
|
||||||
|
Uint8List.fromList(selfKey),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final telemetry = selfContact?.telemetry;
|
||||||
|
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
shape: const RoundedRectangleBorder(
|
shape: const RoundedRectangleBorder(
|
||||||
@@ -513,6 +527,42 @@ class _HomeScreenState extends State<HomeScreen>
|
|||||||
'TX Power',
|
'TX Power',
|
||||||
'${deviceInfo.txPower} dBm',
|
'${deviceInfo.txPower} dBm',
|
||||||
),
|
),
|
||||||
|
if (telemetry != null) ...[
|
||||||
|
const Divider(height: 24),
|
||||||
|
Text(
|
||||||
|
'Self Telemetry',
|
||||||
|
style: Theme.of(context).textTheme.titleSmall,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
if (telemetry.temperature != null)
|
||||||
|
_deviceInfoRow(
|
||||||
|
context,
|
||||||
|
Icons.thermostat,
|
||||||
|
'Temperature',
|
||||||
|
'${telemetry.temperature!.toStringAsFixed(1)}°C',
|
||||||
|
),
|
||||||
|
if (telemetry.humidity != null)
|
||||||
|
_deviceInfoRow(
|
||||||
|
context,
|
||||||
|
Icons.water_drop,
|
||||||
|
'Humidity',
|
||||||
|
'${telemetry.humidity!.toStringAsFixed(1)}%',
|
||||||
|
),
|
||||||
|
if (telemetry.pressure != null)
|
||||||
|
_deviceInfoRow(
|
||||||
|
context,
|
||||||
|
Icons.compress,
|
||||||
|
'Pressure',
|
||||||
|
'${telemetry.pressure!.toStringAsFixed(1)} hPa',
|
||||||
|
),
|
||||||
|
if (telemetry.gpsLocation != null)
|
||||||
|
_deviceInfoRow(
|
||||||
|
context,
|
||||||
|
Icons.gps_fixed,
|
||||||
|
'GPS',
|
||||||
|
'${telemetry.gpsLocation!.latitude.toStringAsFixed(5)}, ${telemetry.gpsLocation!.longitude.toStringAsFixed(5)}',
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user