diff options
author | Scott Murray <scott.murray@konsulko.com> | 2024-01-05 18:50:51 -0500 |
---|---|---|
committer | Scott Murray <scott.murray@konsulko.com> | 2024-01-05 18:52:32 -0500 |
commit | dbb971abeaa2beff2a13e421f8cca83b3054db34 (patch) | |
tree | 049af6bf56c53534807f6cb5de9803dcb111c4e6 | |
parent | da47b0611f7495fb9f4727449721c18c9a617217 (diff) |
Fix unit handling
Fix distance unit handling with respect to the VSS signal for that,
and add temperature unit support.
Bug-AGL: SPEC-5045
Change-Id: I9b25c36c36d19da55f1b9bff7f380c55d592d5d6
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
-rw-r--r-- | lib/screen/home.dart | 15 | ||||
-rw-r--r-- | lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart | 6 | ||||
-rw-r--r-- | lib/screen/widgets/turn_signal.dart | 12 | ||||
-rw-r--r-- | lib/vehicle-signals/vehicle_status_provider.dart | 48 | ||||
-rw-r--r-- | lib/vehicle-signals/vss_path.dart | 5 | ||||
-rw-r--r-- | lib/vehicle-signals/vss_provider.dart | 18 |
6 files changed, 69 insertions, 35 deletions
diff --git a/lib/screen/home.dart b/lib/screen/home.dart index f154550..d9bfa32 100644 --- a/lib/screen/home.dart +++ b/lib/screen/home.dart @@ -67,6 +67,15 @@ class _HomeState extends ConsumerState<Home> { final String performanceMode = ref.watch(vehicleStatusProvider.select((p) => p.performanceMode));
final String selectedGear = ref.watch(vehicleStatusProvider.select((p) => p.selectedGear));
final double ambientAirTemp = ref.watch(vehicleStatusProvider.select((p) => p.ambientAirTemp));
+ final TemperatureUnit tempUnit = ref.watch(vehicleStatusProvider.select((p) => p.temperatureUnit));
+
+ String ambientAirTempString = "";
+ if (tempUnit == TemperatureUnit.celsius) {
+ ambientAirTempString += "${ambientAirTemp.toStringAsFixed(0)} ${"\u00B0"}C";
+ } else {
+ ambientAirTempString += "${((ambientAirTemp * 9 / 5) + 32).toStringAsFixed(0)} ${"\u00B0"}F";
+ }
+
final clock = ref.watch(clockProvider);
final windowHeight = MediaQuery.of(context).size.height;
final windowWidth = MediaQuery.of(context).size.width;
@@ -105,8 +114,8 @@ class _HomeState extends ConsumerState<Home> { children: [
TurnSignal(
screenHeight: screenHeight,
- isLefton: isLeftIndicator,
- isRighton: isRightIndicator,
+ isLeftOn: isLeftIndicator,
+ isRightOn: isRightIndicator,
),
Flex(
direction: Axis.horizontal,
@@ -146,7 +155,7 @@ class _HomeState extends ConsumerState<Home> { SizedBox(
width: (30 * screenHeight) / 480),
Text(
- "${ambientAirTemp} ${"\u00B0"}C",
+ ambientAirTempString,
style: TextStyle(
color: const Color.fromARGB(
255, 184, 183, 183),
diff --git a/lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart b/lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart index dfa4277..78b907e 100644 --- a/lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart +++ b/lib/screen/widgets/gauges/speed_gauge_animation_wrapper.dart @@ -16,12 +16,12 @@ class SpeedGauge extends HookConsumerWidget { @override
Widget build(BuildContext context, WidgetRef ref) {
final double speed = ref.watch(vehicleStatusProvider.select((p) => p.speed));
- final String units = ref.watch(vehicleStatusProvider.select((p) => p.vehicleDistanceUnit));
+ final DistanceUnit unit = ref.watch(vehicleStatusProvider.select((p) => p.distanceUnit));
const double minSpeed = 0;
const double maxSpeed = 240;
const Duration sweepDuration = Duration(milliseconds: 200);
- double speedScaling = (units == "mi") ? 0.621504 : 1.0;
+ double speedScaling = (unit == DistanceUnit.miles) ? 0.621504 : 1.0;
final animationController = useAnimationController(
lowerBound: minSpeed,
@@ -39,7 +39,7 @@ class SpeedGauge extends HookConsumerWidget { low: minSpeed,
high: maxSpeed,
mainValue: animationController.value,
- label: (units == "mi") ? "mph" : "Km/h",
+ label: (unit == DistanceUnit.miles) ? "mph" : "km/h",
zeroTickLabel: minSpeed.toInt().toString(),
maxTickLabel: maxSpeed.toInt().toString(),
inPrimaryColor: gaugeColor?.inPrimary,
diff --git a/lib/screen/widgets/turn_signal.dart b/lib/screen/widgets/turn_signal.dart index 446fbb8..861ffd4 100644 --- a/lib/screen/widgets/turn_signal.dart +++ b/lib/screen/widgets/turn_signal.dart @@ -6,13 +6,13 @@ import 'package:hooks_riverpod/hooks_riverpod.dart'; class TurnSignal extends HookConsumerWidget {
final double screenHeight;
- final bool isLefton;
- final bool isRighton;
+ final bool isLeftOn;
+ final bool isRightOn;
const TurnSignal({
Key? key,
required this.screenHeight,
- required this.isLefton,
- required this.isRighton,
+ required this.isLeftOn,
+ required this.isRightOn,
}) : super(key: key);
double calcPadding(double value, double height) {
// values wrt to values at 720 height
@@ -38,7 +38,7 @@ class TurnSignal extends HookConsumerWidget { children: [
Image.asset(
"images/left.png",
- color: (isLefton)
+ color: (isLeftOn)
? Color.lerp(
Colors.black,
const Color.fromARGB(255, 99, 251, 104),
@@ -48,7 +48,7 @@ class TurnSignal extends HookConsumerWidget { ),
Image.asset(
"images/right.png",
- color: (isRighton)
+ color: (isRightOn)
? Color.lerp(
Colors.black,
const Color.fromARGB(255, 99, 251, 104),
diff --git a/lib/vehicle-signals/vehicle_status_provider.dart b/lib/vehicle-signals/vehicle_status_provider.dart index 9518f59..0c53b2d 100644 --- a/lib/vehicle-signals/vehicle_status_provider.dart +++ b/lib/vehicle-signals/vehicle_status_provider.dart @@ -2,6 +2,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
+enum DistanceUnit { kilometers, miles }
+enum TemperatureUnit { celsius, fahrenheit }
+
class VehicleStatus {
VehicleStatus({
required this.speed,
@@ -14,7 +17,7 @@ class VehicleStatus { required this.isLowBeam,
required this.isHighBeam,
required this.isHazardLightOn,
- required this.travelledDistance,
+ required this.traveledDistance,
required this.isParkingOn,
required this.performanceMode,
required this.ambientAirTemp,
@@ -25,9 +28,9 @@ class VehicleStatus { required this.isTrunkLocked,
required this.isTrunkOpen,
required this.isBatteryCharging,
-
- // steering switches
- required this.vehicleDistanceUnit,
+ required this.distanceUnit,
+ required this.temperatureUnit,
+ // Steering wheel switches
required this.isSteeringCruiseEnable,
required this.isSteeringCruiseSet,
required this.isSteeringCruiseResume,
@@ -56,9 +59,11 @@ class VehicleStatus { final bool isCruiseControlActive;
final bool isCruiseControlError;
final bool isBatteryCharging;
- final double travelledDistance;
+ final double traveledDistance;
+ final DistanceUnit distanceUnit;
+ final TemperatureUnit temperatureUnit;
- final String vehicleDistanceUnit;
+ // Steering wheel switches
final bool isSteeringCruiseEnable;
final bool isSteeringCruiseSet;
final bool isSteeringCruiseResume;
@@ -86,10 +91,11 @@ class VehicleStatus { bool? isCruiseControlError,
bool? isCruiseControlActive,
bool? isBatteryCharging,
- double? travelledDistance,
+ double? traveledDistance,
double? cruiseControlSpeed,
- // Steering
- String? vehicleDistanceUnit,
+ DistanceUnit? distanceUnit,
+ TemperatureUnit? temperatureUnit,
+ // Steering wheel switches
bool? isSteeringCruiseEnable,
bool? isSteeringCruiseSet,
bool? isSteeringCruiseResume,
@@ -108,7 +114,9 @@ class VehicleStatus { isLowBeam: isLowBeam ?? this.isLowBeam,
isHighBeam: isHighBeam ?? this.isHighBeam,
isHazardLightOn: isHazardLightOn ?? this.isHazardLightOn,
- travelledDistance: travelledDistance ?? this.travelledDistance,
+ traveledDistance: traveledDistance ?? this.traveledDistance,
+ distanceUnit: distanceUnit ?? this.distanceUnit,
+ temperatureUnit: temperatureUnit ?? this.temperatureUnit,
isParkingOn: isParkingOn ?? this.isParkingOn,
performanceMode: performanceMode ?? this.performanceMode,
isTrunkLocked: isTrunkLocked ?? this.isTrunkLocked,
@@ -130,7 +138,6 @@ class VehicleStatus { isSteeringInfo: isSteeringInfo ?? this.isSteeringInfo,
isSteeringLaneWarning:
isSteeringLaneWarning ?? this.isSteeringLaneWarning,
- vehicleDistanceUnit: vehicleDistanceUnit ?? this.vehicleDistanceUnit,
);
}
}
@@ -155,7 +162,7 @@ class VehicleStatusNotifier extends StateNotifier<VehicleStatus> { isHighBeam: true,
isLowBeam: false,
isParkingOn: true,
- travelledDistance: 888,
+ traveledDistance: 888,
ambientAirTemp: 25,
cruiseControlSpeed: 60,
isCruiseControlActive: false,
@@ -164,13 +171,14 @@ class VehicleStatusNotifier extends StateNotifier<VehicleStatus> { isTrunkLocked: true,
isTrunkOpen: false,
isBatteryCharging: true,
+ distanceUnit: DistanceUnit.kilometers,
+ temperatureUnit: TemperatureUnit.celsius,
isSteeringCruiseEnable: false,
isSteeringCruiseSet: false,
isSteeringCruiseResume: false,
isSteeringCruiseCancel: false,
isSteeringInfo: false,
isSteeringLaneWarning: false,
- vehicleDistanceUnit: 'km',
);
void update({
double? speed,
@@ -192,10 +200,11 @@ class VehicleStatusNotifier extends StateNotifier<VehicleStatus> { bool? isCruiseControlActive,
bool? isCruiseControlError,
bool? isBatteryCharging,
- double? travelledDistance,
+ double? traveledDistance,
double? cruiseControlSpeed,
- //
- String? vehicleDistanceUnit,
+ DistanceUnit? distanceUnit,
+ TemperatureUnit? temperatureUnit,
+ // Steering wheel switches
bool? isSteeringCruiseEnable,
bool? isSteeringCruiseSet,
bool? isSteeringCruiseResume,
@@ -214,7 +223,7 @@ class VehicleStatusNotifier extends StateNotifier<VehicleStatus> { isLowBeam: isLowBeam,
isHighBeam: isHighBeam,
isHazardLightOn: isHazardLightOn,
- travelledDistance: travelledDistance,
+ traveledDistance: traveledDistance,
performanceMode: performanceMode,
isParkingOn: isParkingOn,
isTrunkOpen: isTrunkOpen,
@@ -225,14 +234,15 @@ class VehicleStatusNotifier extends StateNotifier<VehicleStatus> { isCruiseControlError: isCruiseControlError,
cruiseControlSpeed: cruiseControlSpeed,
isBatteryCharging: isBatteryCharging,
- //
+ distanceUnit: distanceUnit,
+ temperatureUnit: temperatureUnit,
+ // Steering wheel switches
isSteeringCruiseEnable: isSteeringCruiseEnable,
isSteeringCruiseSet: isSteeringCruiseSet,
isSteeringCruiseResume: isSteeringCruiseResume,
isSteeringCruiseCancel: isSteeringCruiseCancel,
isSteeringInfo: isSteeringInfo,
isSteeringLaneWarning: isSteeringLaneWarning,
- vehicleDistanceUnit: vehicleDistanceUnit,
);
}
}
diff --git a/lib/vehicle-signals/vss_path.dart b/lib/vehicle-signals/vss_path.dart index dae8a53..047ad18 100644 --- a/lib/vehicle-signals/vss_path.dart +++ b/lib/vehicle-signals/vss_path.dart @@ -32,7 +32,7 @@ class VSSPath { static const String vehicleHazardLightOn = "Vehicle.Body.Lights.Hazard.IsSignaling";
- static const String vehicleTravelledDistance = "Vehicle.TraveledDistance";
+ static const String vehicleTraveledDistance = "Vehicle.TraveledDistance";
static const String vehicleTrunkLocked = "Vehicle.Body.Trunk.Rear.IsLocked";
@@ -77,6 +77,9 @@ class VSSPath { static const String vehicleDistanceUnit =
"Vehicle.Cabin.Infotainment.HMI.DistanceUnit";
+ static const String vehicleTemperatureUnit =
+ "Vehicle.Cabin.Infotainment.HMI.TemperatureUnit";
+
static const String vehicleCurrLat = "Vehicle.CurrentLocation.Latitude";
static const String vehicleCurrLon = "Vehicle.CurrentLocation.Longitude";
diff --git a/lib/vehicle-signals/vss_provider.dart b/lib/vehicle-signals/vss_provider.dart index 7820a52..50a3b6b 100644 --- a/lib/vehicle-signals/vss_provider.dart +++ b/lib/vehicle-signals/vss_provider.dart @@ -35,6 +35,7 @@ class DashboardVssClient extends VssClient { VSSPath.vehicleCruiseControlActive, VSSPath.vehicleBatteryChargingStatus, VSSPath.vehicleDistanceUnit, + VSSPath.vehicleTemperatureUnit, VSSPath.steeringCruiseEnable, VSSPath.steeringCruiseSet, VSSPath.steeringCruiseResume, @@ -140,9 +141,9 @@ class DashboardVssClient extends VssClient { vehicleStatus.update(performanceMode: update.entry.value.string); } break; - case VSSPath.vehicleTravelledDistance: + case VSSPath.vehicleTraveledDistance: if (update.entry.value.hasFloat()) { - vehicleStatus.update(travelledDistance: update.entry.value.float); + vehicleStatus.update(traveledDistance: update.entry.value.float); } break; case VSSPath.vehicleTrunkLocked: @@ -182,7 +183,18 @@ class DashboardVssClient extends VssClient { break; case VSSPath.vehicleDistanceUnit: if (update.entry.value.hasString()) { - vehicleStatus.update(vehicleDistanceUnit: update.entry.value.string); + DistanceUnit unit = DistanceUnit.kilometers; + if (update.entry.value.string == "MILES") + unit = DistanceUnit.miles; + vehicleStatus.update(distanceUnit: unit); + } + break; + case VSSPath.vehicleTemperatureUnit: + if (update.entry.value.hasString()) { + TemperatureUnit unit = TemperatureUnit.celsius; + if (update.entry.value.string == "F") + unit = TemperatureUnit.fahrenheit; + vehicleStatus.update(temperatureUnit: unit); } break; |