a0d93d7f6d
- Update gps_data_manager.dart: import ProcessedGpsData from models/, use GpsConfig constants, replace all print() with Logger calls - Update gps_service.dart: use GpsConfig.VALID_HEADING_MIN/MAX for heading validation - Update main.dart: import from config/, models/, replace all customDebugPrint() and print() with Logger, use TimingConfig/OverlayConfig constants, convert overlay IPC to OverlayMessage typed class - Delete customDebugPrint() function definition - Delete lib/speed_units.dart and lib/color_themes.dart (moved to config/) - Zero analyzer errors, zero bare print() calls remaining
48 lines
1.5 KiB
Dart
48 lines
1.5 KiB
Dart
import 'dart:async';
|
|
import 'package:geolocator/geolocator.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
import 'config/gps_constants.dart';
|
|
|
|
class GpsService {
|
|
static double? _lastValidHeading;
|
|
|
|
static Stream<Position> get positionStream {
|
|
return Geolocator.getPositionStream(
|
|
locationSettings: const LocationSettings(
|
|
accuracy: LocationAccuracy.bestForNavigation,
|
|
distanceFilter: 0,
|
|
),
|
|
);
|
|
}
|
|
|
|
static Future<bool> requestPermissions() async {
|
|
final permission = await Permission.locationWhenInUse.request();
|
|
return permission.isGranted;
|
|
}
|
|
|
|
static Future<bool> isLocationServiceEnabled() async {
|
|
return await Geolocator.isLocationServiceEnabled();
|
|
}
|
|
|
|
static double getCachedHeading(double heading) {
|
|
if (heading >= GpsConfig.VALID_HEADING_MIN && heading <= GpsConfig.VALID_HEADING_MAX) {
|
|
_lastValidHeading = heading;
|
|
return heading;
|
|
}
|
|
return _lastValidHeading ?? 0.0;
|
|
}
|
|
|
|
static String getCompassDirection(double heading) {
|
|
final cachedHeading = getCachedHeading(heading);
|
|
|
|
const directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
|
|
final index = ((cachedHeading + 22.5) / 45).floor() % 8;
|
|
return directions[index];
|
|
}
|
|
|
|
static String formatHeading(double heading) {
|
|
final cachedHeading = getCachedHeading(heading);
|
|
return '${cachedHeading.round()} ${getCompassDirection(heading)}'; // don't add that degree symbol, this is cooler
|
|
}
|
|
}
|