mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 16:30:28 +00:00
feat: GPS module toggle in device settings
This commit is contained in:
@@ -2202,6 +2202,30 @@ class ConnectionProvider with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Request fresh device info (triggers SelfInfo response)
|
/// Request fresh device info (triggers SelfInfo response)
|
||||||
|
/// Read custom variables from device (GPS mode, sensor settings, etc.)
|
||||||
|
Future<Map<String, String>> getCustomVars() async {
|
||||||
|
if (!_activeService.isConnected) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return await _activeService.getCustomVars();
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('⚠️ [Provider] getCustomVars failed: $e');
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set a custom variable on the device
|
||||||
|
Future<void> setCustomVar(String key, String value) async {
|
||||||
|
if (!_activeService.isConnected) return;
|
||||||
|
try {
|
||||||
|
await _activeService.setCustomVar(key, value);
|
||||||
|
} catch (e) {
|
||||||
|
_error = 'Failed to set $key: $e';
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> refreshDeviceInfo() async {
|
Future<void> refreshDeviceInfo() async {
|
||||||
if (_isSpectrumScanActive) return;
|
if (_isSpectrumScanActive) return;
|
||||||
if (!_activeService.isConnected) {
|
if (!_activeService.isConnected) {
|
||||||
|
|||||||
@@ -182,6 +182,8 @@ class _DeviceConfigScreenState extends State<DeviceConfigScreen> {
|
|||||||
|
|
||||||
bool _telemetryEnabled = false;
|
bool _telemetryEnabled = false;
|
||||||
bool _repeatEnabled = false;
|
bool _repeatEnabled = false;
|
||||||
|
bool? _gpsEnabled; // null = not supported by hardware
|
||||||
|
bool _gpsLoading = false;
|
||||||
bool _autoAddDiscoveredContactsEnabled = true;
|
bool _autoAddDiscoveredContactsEnabled = true;
|
||||||
bool _autoAddUsersEnabled = true;
|
bool _autoAddUsersEnabled = true;
|
||||||
bool _autoAddRepeatersEnabled = true;
|
bool _autoAddRepeatersEnabled = true;
|
||||||
@@ -294,6 +296,7 @@ class _DeviceConfigScreenState extends State<DeviceConfigScreen> {
|
|||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
_connectionProvider.getBatteryAndStorage();
|
_connectionProvider.getBatteryAndStorage();
|
||||||
unawaited(_connectionProvider.getAutoaddConfig());
|
unawaited(_connectionProvider.getAutoaddConfig());
|
||||||
|
unawaited(_loadGpsMode());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -701,6 +704,37 @@ class _DeviceConfigScreenState extends State<DeviceConfigScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _loadGpsMode() async {
|
||||||
|
try {
|
||||||
|
final vars = await _connectionProvider.getCustomVars();
|
||||||
|
if (!mounted) return;
|
||||||
|
final gpsValue = vars['gps'];
|
||||||
|
setState(() {
|
||||||
|
_gpsEnabled = gpsValue != null ? gpsValue == '1' : null;
|
||||||
|
});
|
||||||
|
} catch (_) {
|
||||||
|
// Device may not support custom vars (old firmware / no GPS hardware)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _setGpsMode(bool enabled) async {
|
||||||
|
setState(() => _gpsLoading = true);
|
||||||
|
try {
|
||||||
|
await _connectionProvider.setCustomVar('gps', enabled ? '1' : '0');
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_gpsEnabled = enabled;
|
||||||
|
_gpsLoading = false;
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() => _gpsLoading = false);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('Failed to set GPS mode: $e')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _useCurrentLocation() async {
|
Future<void> _useCurrentLocation() async {
|
||||||
try {
|
try {
|
||||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||||
@@ -1331,6 +1365,32 @@ class _DeviceConfigScreenState extends State<DeviceConfigScreen> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (_gpsEnabled != null) ...[
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
_SettingHighlightCard(
|
||||||
|
icon: _gpsEnabled!
|
||||||
|
? Icons.gps_fixed
|
||||||
|
: Icons.gps_off,
|
||||||
|
title: 'GPS Module',
|
||||||
|
description:
|
||||||
|
'Enable or disable the onboard GPS hardware.',
|
||||||
|
accentColor: _gpsEnabled!
|
||||||
|
? colorScheme.primary
|
||||||
|
: colorScheme.onSurfaceVariant,
|
||||||
|
trailing: _gpsLoading
|
||||||
|
? const SizedBox(
|
||||||
|
width: 24,
|
||||||
|
height: 24,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Switch(
|
||||||
|
value: _gpsEnabled!,
|
||||||
|
onChanged: _setGpsMode,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
const SizedBox(height: 18),
|
const SizedBox(height: 18),
|
||||||
TextField(
|
TextField(
|
||||||
controller: _nameController,
|
controller: _nameController,
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ dependencies:
|
|||||||
meshcore_client:
|
meshcore_client:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/dz0ny/meshcore_client.git
|
url: https://github.com/dz0ny/meshcore_client.git
|
||||||
ref: "9b3d63c34ed0243becb76e306ee35be24760847d"
|
ref: "77c1f81f24b4839cf70439a478ff077c026c120e"
|
||||||
|
|
||||||
# Codec2 ultra-low-bitrate speech codec (FFI plugin)
|
# Codec2 ultra-low-bitrate speech codec (FFI plugin)
|
||||||
codec2_flutter:
|
codec2_flutter:
|
||||||
|
|||||||
Reference in New Issue
Block a user