Procedural commit, I don't know what's been done
This commit is contained in:
@@ -10,7 +10,6 @@ class GpsService {
|
|||||||
locationSettings: const LocationSettings(
|
locationSettings: const LocationSettings(
|
||||||
accuracy: LocationAccuracy.bestForNavigation,
|
accuracy: LocationAccuracy.bestForNavigation,
|
||||||
distanceFilter: 0,
|
distanceFilter: 0,
|
||||||
timeLimit: Duration(seconds: 2), // Short timeout for ongoing updates after initial fix
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -44,4 +43,4 @@ class GpsService {
|
|||||||
final cachedHeading = getCachedHeading(heading);
|
final cachedHeading = getCachedHeading(heading);
|
||||||
return '${cachedHeading.round()} ${getCompassDirection(heading)}'; // don't add that degree symbol, this is cooler
|
return '${cachedHeading.round()} ${getCompassDirection(heading)}'; // don't add that degree symbol, this is cooler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ class GpsDataManager {
|
|||||||
isHeadingValid: false,
|
isHeadingValid: false,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
static const Duration _staleDataThreshold = Duration(seconds: 4);
|
||||||
|
Timer? _staleDataTimer;
|
||||||
|
|
||||||
// Public stream for UI components to subscribe to
|
// Public stream for UI components to subscribe to
|
||||||
Stream<ProcessedGpsData> get dataStream => _dataController.stream;
|
Stream<ProcessedGpsData> get dataStream => _dataController.stream;
|
||||||
|
|
||||||
@@ -154,30 +157,36 @@ class GpsDataManager {
|
|||||||
|
|
||||||
void _onPositionUpdate(Position position) {
|
void _onPositionUpdate(Position position) {
|
||||||
print('[GpsDataManager] 📡 Raw GPS update: speed=${position.speed.toStringAsFixed(2)} m/s, heading=${position.heading.toStringAsFixed(1)}°');
|
print('[GpsDataManager] 📡 Raw GPS update: speed=${position.speed.toStringAsFixed(2)} m/s, heading=${position.heading.toStringAsFixed(1)}°');
|
||||||
|
|
||||||
// For now, simple pass-through processing
|
_scheduleStaleDataTimer();
|
||||||
// TODO: Add intelligent caching logic here later
|
|
||||||
|
final rawSpeed = position.speed;
|
||||||
final speed = position.speed;
|
final bool speedValid = rawSpeed.isFinite && rawSpeed >= 0;
|
||||||
final heading = position.heading;
|
final double speed = speedValid ? rawSpeed : 0.0;
|
||||||
|
|
||||||
|
final rawHeading = position.heading;
|
||||||
|
final bool headingValid = rawHeading.isFinite && rawHeading >= 0 && rawHeading < 360;
|
||||||
|
final double heading = headingValid ? rawHeading : _currentData.heading;
|
||||||
|
|
||||||
// Basic display logic - TEMPORARILY show all speeds for indoor testing
|
// Basic display logic - TEMPORARILY show all speeds for indoor testing
|
||||||
// TODO: Re-enable low-speed logic later: (speed < 1.0 && (heading < 0.0 || heading >= 360.0)) ? '--' : ...
|
// TODO: Re-enable low-speed logic later: (speed < 1.0 && (heading < 0.0 || heading >= 360.0)) ? '--' : ...
|
||||||
final displaySpeed = speed.toStringAsFixed(1);
|
final displaySpeed = speed.toStringAsFixed(1);
|
||||||
|
|
||||||
final displayHeading = GpsService.formatHeading(heading);
|
final displayHeading = headingValid
|
||||||
|
? GpsService.formatHeading(heading)
|
||||||
|
: _currentData.displayHeading;
|
||||||
|
|
||||||
print('[GpsDataManager] 🔄 Processed: displaySpeed="$displaySpeed", displayHeading="$displayHeading"');
|
print('[GpsDataManager] 🔄 Processed: displaySpeed="$displaySpeed", displayHeading="$displayHeading"');
|
||||||
|
|
||||||
final processedData = ProcessedGpsData(
|
final processedData = ProcessedGpsData(
|
||||||
speed: speed,
|
speed: speed,
|
||||||
heading: heading,
|
heading: heading,
|
||||||
displaySpeed: displaySpeed,
|
displaySpeed: displaySpeed,
|
||||||
displayHeading: displayHeading,
|
displayHeading: displayHeading,
|
||||||
isSpeedValid: speed >= 0,
|
isSpeedValid: speedValid,
|
||||||
isHeadingValid: heading >= 0 && heading < 360,
|
isHeadingValid: headingValid,
|
||||||
);
|
);
|
||||||
|
|
||||||
_updateData(processedData);
|
_updateData(processedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,6 +203,34 @@ class GpsDataManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _scheduleStaleDataTimer() {
|
||||||
|
_staleDataTimer?.cancel();
|
||||||
|
_staleDataTimer = Timer(_staleDataThreshold, _handleStaleDataTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handleStaleDataTimeout() {
|
||||||
|
// Avoid overriding explicit GPS error states or repeated stale notifications
|
||||||
|
final displayText = _currentData.displaySpeed;
|
||||||
|
if (displayText == '--' || displayText.startsWith('GPS') || displayText == 'NO PERM') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final headingStillValid = _currentData.isHeadingValid && _currentData.heading >= 0 && _currentData.heading < 360;
|
||||||
|
final displayHeading = headingStillValid ? _currentData.displayHeading : '--';
|
||||||
|
|
||||||
|
print('[GpsDataManager] ⏱️ No GPS updates within ${_staleDataThreshold.inSeconds}s - marking data as stale');
|
||||||
|
|
||||||
|
final staleData = _currentData.copyWith(
|
||||||
|
displaySpeed: '--',
|
||||||
|
displayHeading: displayHeading,
|
||||||
|
isSpeedValid: false,
|
||||||
|
isHeadingValid: headingStillValid,
|
||||||
|
);
|
||||||
|
|
||||||
|
_staleDataTimer = null;
|
||||||
|
_updateData(staleData);
|
||||||
|
}
|
||||||
|
|
||||||
void _updateData(ProcessedGpsData newData) {
|
void _updateData(ProcessedGpsData newData) {
|
||||||
print('[GpsDataManager] 📤 Broadcasting data: ${newData.displaySpeed} ${newData.displayHeading}');
|
print('[GpsDataManager] 📤 Broadcasting data: ${newData.displaySpeed} ${newData.displayHeading}');
|
||||||
_currentData = newData;
|
_currentData = newData;
|
||||||
@@ -217,8 +254,10 @@ class GpsDataManager {
|
|||||||
_gpsSubscription = null;
|
_gpsSubscription = null;
|
||||||
}
|
}
|
||||||
print('[GpsDataManager] 🛑 Closing data controller...');
|
print('[GpsDataManager] 🛑 Closing data controller...');
|
||||||
|
_staleDataTimer?.cancel();
|
||||||
|
_staleDataTimer = null;
|
||||||
_dataController.close();
|
_dataController.close();
|
||||||
_isInitialized = false;
|
_isInitialized = false;
|
||||||
print('[GpsDataManager] 🛑 GPS manager disposed');
|
print('[GpsDataManager] 🛑 GPS manager disposed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user