mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-08-11 08:20:36 +00:00
fix: Tame rapid GPS updates #41
This commit is contained in:
@@ -341,7 +341,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Meters',
|
||||
helperText: 'Valid range: 1 to 1000 meters',
|
||||
helperText: 'Valid range: 10 to 1000 meters',
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
@@ -353,7 +353,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
onPressed: () {
|
||||
final parsed = double.tryParse(controller.text.trim());
|
||||
if (parsed == null) return;
|
||||
Navigator.pop(context, parsed.clamp(1.0, 1000.0));
|
||||
Navigator.pop(context, parsed.clamp(10.0, 1000.0));
|
||||
},
|
||||
child: const Text('Save'),
|
||||
),
|
||||
@@ -382,7 +382,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Seconds',
|
||||
helperText: 'Valid range: 5 to 60 seconds',
|
||||
helperText: 'Valid range: 10 to 31 seconds',
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
@@ -394,7 +394,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
onPressed: () {
|
||||
final parsed = int.tryParse(controller.text.trim());
|
||||
if (parsed == null) return;
|
||||
Navigator.pop(context, parsed.clamp(5, 60));
|
||||
Navigator.pop(context, parsed.clamp(10, 31));
|
||||
},
|
||||
child: const Text('Save'),
|
||||
),
|
||||
|
||||
@@ -144,11 +144,11 @@ class AppConfigSnapshotService {
|
||||
}
|
||||
if (section.fastLocationMovementThresholdMeters != null) {
|
||||
locationTracking.fastLocationMovementThresholdMeters =
|
||||
section.fastLocationMovementThresholdMeters!;
|
||||
section.fastLocationMovementThresholdMeters!.clamp(10.0, 1000.0);
|
||||
}
|
||||
if (section.fastLocationActiveCadenceSeconds != null) {
|
||||
locationTracking.fastLocationActiveCadenceSeconds =
|
||||
section.fastLocationActiveCadenceSeconds!;
|
||||
section.fastLocationActiveCadenceSeconds!.clamp(10, 31);
|
||||
}
|
||||
await locationTracking.saveSettings();
|
||||
await appProvider.reloadProfileScopedSettings();
|
||||
|
||||
@@ -20,6 +20,14 @@ import 'profiles_feature_service.dart';
|
||||
/// - MeshCore mesh network integration
|
||||
/// - Real-time position updates via callbacks
|
||||
class LocationTrackingService {
|
||||
static const double _defaultFastLocationMovementThresholdMeters = 10.0;
|
||||
static const double _minFastLocationMovementThresholdMeters = 10.0;
|
||||
static const int _defaultFastLocationActiveCadenceSeconds = 10;
|
||||
static const int _minFastLocationActiveCadenceSeconds = 10;
|
||||
static const int _maxFastLocationActiveCadenceSeconds = 31;
|
||||
static const Duration _fastLocationMinimumUpdateInterval = Duration(
|
||||
seconds: 31,
|
||||
);
|
||||
// ============================================================================
|
||||
// Singleton Pattern
|
||||
// ============================================================================
|
||||
@@ -75,10 +83,12 @@ class LocationTrackingService {
|
||||
bool fastLocationUpdatesEnabled = false;
|
||||
|
||||
/// Distance threshold for fast GPS updates
|
||||
double fastLocationMovementThresholdMeters = 10.0;
|
||||
double fastLocationMovementThresholdMeters =
|
||||
_defaultFastLocationMovementThresholdMeters;
|
||||
|
||||
/// Cadence for active-use fast GPS updates
|
||||
int fastLocationActiveCadenceSeconds = 10;
|
||||
int fastLocationActiveCadenceSeconds =
|
||||
_defaultFastLocationActiveCadenceSeconds;
|
||||
|
||||
/// Target channel index for fast GPS updates; null means disabled/unset.
|
||||
int? fastLocationChannelIdx;
|
||||
@@ -522,12 +532,18 @@ class LocationTrackingService {
|
||||
}
|
||||
|
||||
Future<void> updateFastLocationMovementThreshold(double meters) async {
|
||||
fastLocationMovementThresholdMeters = meters.clamp(1.0, 1000.0);
|
||||
fastLocationMovementThresholdMeters = meters.clamp(
|
||||
_minFastLocationMovementThresholdMeters,
|
||||
1000.0,
|
||||
);
|
||||
await saveSettings();
|
||||
}
|
||||
|
||||
Future<void> updateFastLocationActiveCadenceSeconds(int seconds) async {
|
||||
fastLocationActiveCadenceSeconds = seconds.clamp(5, 60);
|
||||
fastLocationActiveCadenceSeconds = seconds.clamp(
|
||||
_minFastLocationActiveCadenceSeconds,
|
||||
_maxFastLocationActiveCadenceSeconds,
|
||||
);
|
||||
await saveSettings();
|
||||
_refreshFastLocationTimer();
|
||||
}
|
||||
@@ -583,6 +599,11 @@ class LocationTrackingService {
|
||||
final now = DateTime.now();
|
||||
final previous = _lastFastLocationSentPosition;
|
||||
final previousTime = _lastFastLocationSentAt;
|
||||
if (previousTime != null &&
|
||||
now.difference(previousTime) < _fastLocationMinimumUpdateInterval) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (previous != null && previousTime != null) {
|
||||
final distance = Geolocator.distanceBetween(
|
||||
previous.latitude,
|
||||
@@ -673,12 +694,14 @@ class LocationTrackingService {
|
||||
prefs.getBool(_scopedKey(_prefKeyFastLocationEnabled)) ?? false;
|
||||
fastLocationMovementThresholdMeters =
|
||||
(prefs.getDouble(_scopedKey(_prefKeyFastMovementThreshold)) ??
|
||||
gpsUpdateDistance)
|
||||
.clamp(1.0, 1000.0);
|
||||
_defaultFastLocationMovementThresholdMeters)
|
||||
.clamp(_minFastLocationMovementThresholdMeters, 1000.0);
|
||||
fastLocationActiveCadenceSeconds =
|
||||
(prefs.getInt(_scopedKey(_prefKeyFastActiveCadence)) ?? 10).clamp(
|
||||
5,
|
||||
60,
|
||||
(prefs.getInt(_scopedKey(_prefKeyFastActiveCadence)) ??
|
||||
_defaultFastLocationActiveCadenceSeconds)
|
||||
.clamp(
|
||||
_minFastLocationActiveCadenceSeconds,
|
||||
_maxFastLocationActiveCadenceSeconds,
|
||||
);
|
||||
fastLocationChannelIdx = prefs.getInt(_scopedKey(_prefKeyFastChannelIdx));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user