aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2023-12-08 10:28:48 +0900
committerScott Murray <scott.murray@konsulko.com>2023-12-08 10:54:30 +0900
commit71d46d03850653c0229c678de197c6f94fceb477 (patch)
treeb91915e70c9092d304d3172b93eb61ffb0c287c5
parentdca5f5bc58fc3b25972bedc82827b71300d66adc (diff)
More signaling fixes
Changes: - Fixed parsing of engine speed from databroker response to use uint32 again to match VSS type. - Shifted engine speed definitions in Vehicle class next to vehicle speed since that seems a bit saner than having it down at the bottom with the temperature values. - Removed duplicate temperature state from temperature control widget, and pushed the use of the providers from the HVAC widget. The existing scheme was somewhat broken with respect to having the values managed with RiverPod, e.g. new values from external updates would not show up until switching away and back to the HVAC tab. - Moved HVAC "SYNC" button state into the Vehicle state class to manage it with RiverPod, and allow use from both the HVAC and temperature widgets so that the expected behavior can actually be implemented. - Fixed brace usage in a couple of debugPrint statements. Bug-AGL: SPEC-4999 Change-Id: I07ea49d20fedca47e6f9e54f45ad34296e0a873c Signed-off-by: Scott Murray <scott.murray@konsulko.com>
-rw-r--r--lib/core/constants/vss_path.dart6
-rw-r--r--lib/data/data_providers/vehicle_notifier.dart10
-rw-r--r--lib/data/models/vehicle.dart52
-rw-r--r--lib/presentation/screens/hvac/hvac_content.dart41
-rw-r--r--lib/presentation/screens/hvac/widgets/fan_speed_controls.dart3
-rw-r--r--lib/presentation/screens/hvac/widgets/temperature_control.dart70
6 files changed, 97 insertions, 85 deletions
diff --git a/lib/core/constants/vss_path.dart b/lib/core/constants/vss_path.dart
index 2147b75..99f3d60 100644
--- a/lib/core/constants/vss_path.dart
+++ b/lib/core/constants/vss_path.dart
@@ -1,5 +1,7 @@
class VSSPath {
static const String vehicleSpeed = 'Vehicle.Speed';
+ static const String vehicleEngineSpeed =
+ 'Vehicle.Powertrain.CombustionEngine.Speed';
static const String vehicleInsideTemperature =
'Vehicle.Cabin.HVAC.AmbientAirTemperature';
static const String vehicleOutsideTemperature =
@@ -13,8 +15,6 @@ class VSSPath {
'Vehicle.Cabin.Door.Row2.DriverSide.IsChildLockActive';
static const String vehicleIsChildLockActiveRight =
'Vehicle.Cabin.Door.Row2.PassengerSide.IsChildLockActive';
- static const String vehicleEngineSpeed =
- 'Vehicle.Powertrain.CombustionEngine.Speed';
static const String vehicleFrontLeftTire =
'Vehicle.Chassis.Axle.Row1.Wheel.Left.Tire.Pressure';
static const String vehicleFrontRightTire =
@@ -41,6 +41,7 @@ class VSSPath {
List<String> getSignalsList() {
return const [
vehicleSpeed,
+ vehicleEngineSpeed,
vehicleInsideTemperature,
vehicleOutsideTemperature,
vehicleRange,
@@ -48,7 +49,6 @@ class VSSPath {
vehicleMediaVolume,
vehicleIsChildLockActiveLeft,
vehicleIsChildLockActiveRight,
- vehicleEngineSpeed,
vehicleFrontLeftTire,
vehicleFrontRightTire,
vehicleRearLeftTire,
diff --git a/lib/data/data_providers/vehicle_notifier.dart b/lib/data/data_providers/vehicle_notifier.dart
index 1b2a31a..3a385a3 100644
--- a/lib/data/data_providers/vehicle_notifier.dart
+++ b/lib/data/data_providers/vehicle_notifier.dart
@@ -352,7 +352,7 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
isChildLockActiveRight: !state.isChildLockActiveRight);
break;
default:
- debugPrint("ERROR: Unexpected side value $side}");
+ debugPrint("ERROR: Unexpected side value ${side}");
break;
}
} catch (e) {
@@ -391,7 +391,7 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
state = state.copyWith(passengerTemperature: value);
break;
default:
- debugPrint("ERROR: Unexpected side value $side}");
+ debugPrint("ERROR: Unexpected side value ${side}");
break;
}
} catch (e) {
@@ -399,6 +399,10 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
}
}
+ void setTemperatureSynced(bool newValue) {
+ state = state.copyWith(temperatureSynced: newValue);
+ }
+
void updateFanSpeed(int newValue) {
// Convert local 0-3 setting to the 0-100 the VSS signal expects
var targetFanSpeed = 0;
@@ -465,7 +469,7 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
isRecirculationActive: !state.isRecirculationActive);
break;
default:
- debugPrint("ERROR: Unexpected mode value $mode}");
+ debugPrint("ERROR: Unexpected mode value ${mode}");
break;
}
} catch (e) {
diff --git a/lib/data/models/vehicle.dart b/lib/data/models/vehicle.dart
index 67ef693..2dea928 100644
--- a/lib/data/models/vehicle.dart
+++ b/lib/data/models/vehicle.dart
@@ -5,6 +5,7 @@ import '../../export.dart';
@immutable
class Vehicle {
final double speed;
+ final double engineSpeed;
final double insideTemperature;
final double outsideTemperature;
final int range;
@@ -12,7 +13,6 @@ class Vehicle {
final int mediaVolume;
final bool isChildLockActiveLeft;
final bool isChildLockActiveRight;
- final double engineSpeed;
final int frontLeftTire;
final int frontRightTire;
final int rearLeftTire;
@@ -24,9 +24,11 @@ class Vehicle {
final int fanSpeed;
final int driverTemperature;
final int passengerTemperature;
+ final bool temperatureSynced;
const Vehicle(
this.speed,
+ this.engineSpeed,
this.insideTemperature,
this.outsideTemperature,
this.range,
@@ -34,7 +36,6 @@ class Vehicle {
this.mediaVolume,
this.isChildLockActiveLeft,
this.isChildLockActiveRight,
- this.engineSpeed,
this.frontLeftTire,
this.frontRightTire,
this.rearLeftTire,
@@ -43,13 +44,15 @@ class Vehicle {
this.isFrontDefrosterActive,
this.isRearDefrosterActive,
this.isRecirculationActive,
- this.fanSpeed,
- this.driverTemperature,
- this.passengerTemperature,
+ this.fanSpeed,
+ this.driverTemperature,
+ this.passengerTemperature,
+ this.temperatureSynced,
);
const Vehicle.initial()
: speed = 0,
+ engineSpeed = 0,
insideTemperature = 0,
outsideTemperature = 0,
range = 0,
@@ -57,7 +60,6 @@ class Vehicle {
mediaVolume = 50,
isChildLockActiveLeft = false,
isChildLockActiveRight = true,
- engineSpeed = 0,
frontLeftTire = 33,
frontRightTire = 31,
rearLeftTire = 31,
@@ -68,10 +70,12 @@ class Vehicle {
isRecirculationActive = false,
fanSpeed = 0,
driverTemperature = 26,
- passengerTemperature = 26;
+ passengerTemperature = 26,
+ temperatureSynced = true;
const Vehicle.initialForDebug()
: speed = 60,
+ engineSpeed = 6500,
insideTemperature = 25,
outsideTemperature = 32.0,
range = 21,
@@ -79,7 +83,6 @@ class Vehicle {
mediaVolume = 50,
isChildLockActiveLeft = false,
isChildLockActiveRight = true,
- engineSpeed = 6500,
frontLeftTire = 33,
frontRightTire = 31,
rearLeftTire = 31,
@@ -90,10 +93,12 @@ class Vehicle {
isRecirculationActive = false,
fanSpeed = 0,
driverTemperature = 26,
- passengerTemperature = 26;
+ passengerTemperature = 26,
+ temperatureSynced = true;
Vehicle copyWith(
{double? speed,
+ double? engineSpeed,
double? insideTemperature,
double? outsideTemperature,
int? range,
@@ -101,7 +106,6 @@ class Vehicle {
int? mediaVolume,
bool? isChildLockActiveLeft,
bool? isChildLockActiveRight,
- double? engineSpeed,
int? frontLeftTire,
int? frontRightTire,
int? rearLeftTire,
@@ -110,12 +114,14 @@ class Vehicle {
bool? isFrontDefrosterActive,
bool? isRearDefrosterActive,
bool? isRecirculationActive,
- int? fanSpeed,
- int? driverTemperature,
- int? passengerTemperature,
+ int? fanSpeed,
+ int? driverTemperature,
+ int? passengerTemperature,
+ bool? temperatureSynced,
}) {
return Vehicle(
speed ?? this.speed,
+ engineSpeed ?? this.engineSpeed,
insideTemperature ?? this.insideTemperature,
outsideTemperature ?? this.outsideTemperature,
range ?? this.range,
@@ -123,7 +129,6 @@ class Vehicle {
mediaVolume ?? this.mediaVolume,
isChildLockActiveLeft ?? this.isChildLockActiveLeft,
isChildLockActiveRight ?? this.isChildLockActiveRight,
- engineSpeed ?? this.engineSpeed,
frontLeftTire ?? this.frontLeftTire,
frontRightTire ?? this.frontRightTire,
rearLeftTire ?? this.rearLeftTire,
@@ -132,15 +137,17 @@ class Vehicle {
isFrontDefrosterActive ?? this.isFrontDefrosterActive,
isRearDefrosterActive ?? this.isRearDefrosterActive,
isRecirculationActive ?? this.isRecirculationActive,
- fanSpeed ?? this.fanSpeed,
- driverTemperature ?? this.driverTemperature,
- passengerTemperature ?? this.passengerTemperature,
+ fanSpeed ?? this.fanSpeed,
+ driverTemperature ?? this.driverTemperature,
+ passengerTemperature ?? this.passengerTemperature,
+ temperatureSynced ?? this.temperatureSynced,
);
}
Map<String, dynamic> toMap() {
return {
'speed': speed,
+ 'engineSpeed': engineSpeed,
'insideTemperature': insideTemperature,
'outsideTemperature': outsideTemperature,
'range': range,
@@ -148,7 +155,6 @@ class Vehicle {
'mediaVolume': mediaVolume,
'isChildLockActiveLeft': isChildLockActiveLeft,
'isChildLockActiveRight': isChildLockActiveRight,
- 'engineSpeed': engineSpeed,
'frontLeftTire': frontLeftTire,
'frontRightTire': frontRightTire,
'rearLeftTire': rearLeftTire,
@@ -160,12 +166,14 @@ class Vehicle {
'fanSpeed': fanSpeed,
'driverTemperature': driverTemperature,
'passengerTemperature': passengerTemperature,
+ 'temperatureSynced': temperatureSynced,
};
}
factory Vehicle.fromMap(Map<String, dynamic> map) {
return Vehicle(
map['speed']?.toDouble() ?? 0.0,
+ map['engineSpeed']?.toDouble() ?? 0.0,
map['insideTemperature']?.toDouble() ?? 0.0,
map['outsideTemperature']?.toDouble() ?? 0.0,
map['range']?.toInt() ?? 0,
@@ -173,7 +181,6 @@ class Vehicle {
map['mediaVolume']?.toInt() ?? 0,
map['isChildLockActiveLeft'] ?? false,
map['isChildLockActiveRight'] ?? false,
- map['engineSpeed']?.toInt() ?? 0,
map['frontLeftTire']?.toInt() ?? 0,
map['frontRightTire']?.toInt() ?? 0,
map['rearLeftTire']?.toInt() ?? 0,
@@ -185,6 +192,7 @@ class Vehicle {
map['fanSpeed'] ?? 0,
map['driverTemperature'] ?? 0,
map['passengerTemperature'] ?? 0,
+ map['temperatureSynced'] ?? false,
);
}
@@ -222,7 +230,8 @@ class Vehicle {
other.isRecirculationActive == isRecirculationActive &&
other.fanSpeed == fanSpeed &&
other.driverTemperature == driverTemperature &&
- other.passengerTemperature == passengerTemperature;
+ other.passengerTemperature == passengerTemperature &&
+ other.temperatureSynced == temperatureSynced;
}
@override
@@ -246,7 +255,8 @@ class Vehicle {
isRecirculationActive.hashCode ^
fanSpeed.hashCode ^
driverTemperature.hashCode ^
- passengerTemperature.hashCode;
+ passengerTemperature.hashCode ^
+ temperatureSynced.hashCode;
}
// }
// / class VehicleNotifier extends StateNotifier<Vehicle> {
diff --git a/lib/presentation/screens/hvac/hvac_content.dart b/lib/presentation/screens/hvac/hvac_content.dart
index 73fd439..e541efd 100644
--- a/lib/presentation/screens/hvac/hvac_content.dart
+++ b/lib/presentation/screens/hvac/hvac_content.dart
@@ -13,15 +13,8 @@ class HVACState extends ConsumerState<HVAC> {
bool isFanFocusLeftBottomSelected = true;
bool isFanFocusRightBottomSelected = false;
- late bool isACSelected;
- bool isSYNCSelected = true;
- late bool isFrontDefrostSelected;
bool isAutoSelected = true;
- late bool isRecirculationSelected;
- late bool isRearDefrostSelected;
- int temperatureLeft = 26;
- int temperatureRight = 26;
@override
void initState() {
super.initState();
@@ -52,14 +45,12 @@ class HVACState extends ConsumerState<HVAC> {
@override
Widget build(BuildContext context) {
- final vehicle = ref.watch(vehicleProvider.select((vehicle) => vehicle));
- isACSelected = vehicle.isAirConditioningActive;
- isFrontDefrostSelected = vehicle.isFrontDefrosterActive;
- isRearDefrostSelected = vehicle.isRearDefrosterActive;
- isRecirculationSelected = vehicle.isRecirculationActive;
+ bool isACSelected = ref.watch(vehicleProvider.select((vehicle) => vehicle.isAirConditioningActive));
+ bool isFrontDefrostSelected = ref.watch(vehicleProvider.select((vehicle) => vehicle.isFrontDefrosterActive));
+ bool isRearDefrostSelected = ref.watch(vehicleProvider.select((vehicle) => vehicle.isRearDefrosterActive));
+ bool isRecirculationSelected = ref.watch(vehicleProvider.select((vehicle) => vehicle.isRecirculationActive));
+ bool isSYNCSelected = ref.watch(vehicleProvider.select((vehicle) => vehicle.temperatureSynced));
Size size = MediaQuery.sizeOf(context);
- temperatureLeft = vehicle.driverTemperature;
- temperatureRight = vehicle.passengerTemperature;
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -155,14 +146,8 @@ class HVACState extends ConsumerState<HVAC> {
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
- TemperatureControl(
- temperature: temperatureLeft,
- side: Side.left,
- ),
- TemperatureControl(
- temperature: temperatureRight,
- side: Side.right,
- )
+ TemperatureControl(side: Side.left),
+ TemperatureControl(side: Side.right)
],
),
const SizedBox(
@@ -190,9 +175,15 @@ class HVACState extends ConsumerState<HVAC> {
)),
ClimateControls(
onPressed: () {
- setState(() {
- isSYNCSelected = !isSYNCSelected;
- });
+ if (!isSYNCSelected) {
+ int temperature = ref.read(vehicleProvider.select((vehicle) => vehicle.driverTemperature));
+ ref
+ .read(vehicleProvider.notifier)
+ .setTemperature(side: Side.right, value: temperature);
+ }
+ ref
+ .read(vehicleProvider.notifier)
+ .setTemperatureSynced(!isSYNCSelected);
},
isSelected: isSYNCSelected,
child: Text(
diff --git a/lib/presentation/screens/hvac/widgets/fan_speed_controls.dart b/lib/presentation/screens/hvac/widgets/fan_speed_controls.dart
index ac813ca..e9a9719 100644
--- a/lib/presentation/screens/hvac/widgets/fan_speed_controls.dart
+++ b/lib/presentation/screens/hvac/widgets/fan_speed_controls.dart
@@ -69,8 +69,7 @@ class FanSpeedControlsState extends ConsumerState<FanSpeedControls>
double iconSize = 80;
- final vehicle = ref.watch(vehicleProvider.select((vehicle) => vehicle));
- selectedFanSpeed = vehicle.fanSpeed;
+ int selectedFanSpeed = ref.watch(vehicleProvider.select((vehicle) => vehicle.fanSpeed));
controlProgress = selectedFanSpeed * 0.3;
return Stack(
diff --git a/lib/presentation/screens/hvac/widgets/temperature_control.dart b/lib/presentation/screens/hvac/widgets/temperature_control.dart
index 77d6dbc..31875ca 100644
--- a/lib/presentation/screens/hvac/widgets/temperature_control.dart
+++ b/lib/presentation/screens/hvac/widgets/temperature_control.dart
@@ -6,8 +6,7 @@ enum Side { left, right }
class TemperatureControl extends ConsumerStatefulWidget {
const TemperatureControl(
- {super.key, required this.temperature, required this.side});
- final int temperature;
+ {super.key, required this.side});
final Side side;
@override
@@ -16,48 +15,57 @@ class TemperatureControl extends ConsumerStatefulWidget {
class TemperatureControlState extends ConsumerState<TemperatureControl> {
late Timer tempButtonTimer;
- int temperature = 0;
bool isUpButtonHighlighted = false;
bool isDownButtonHighlighted = false;
- @override
- void initState() {
- super.initState();
- setState(() {
- temperature = widget.temperature;
- });
- }
-
onPressed({required String type, required Side side}) {
- setState(() {
- if (type == "add") {
- temperature = temperature + 1;
- } else if (type == "subtract") {
- temperature = temperature - 1;
- }
- // limit the temperature to 60-100F
- if (temperature <= 15) {
- temperature = 15;
- } else if (temperature >= 38) {
- temperature = 38;
- }
- if (widget.side == Side.left) {
+ int temperature = 0;
+ if (side == Side.left) {
+ temperature = ref.read(vehicleProvider.select((vehicle) => vehicle.driverTemperature));
+ } else {
+ temperature = ref.read(vehicleProvider.select((vehicle) => vehicle.passengerTemperature));
+ }
+ if (type == "add") {
+ temperature = temperature + 1;
+ } else if (type == "subtract") {
+ temperature = temperature - 1;
+ }
+ // limit the temperature to 60-100F
+ if (temperature <= 15) {
+ temperature = 15;
+ } else if (temperature >= 38) {
+ temperature = 38;
+ }
+ bool isSynced = ref.read(vehicleProvider.select((vehicle) => vehicle.temperatureSynced));
+ if (widget.side == Side.left) {
+ ref
+ .read(vehicleProvider.notifier)
+ .setTemperature(side: Side.left, value: temperature);
+ if (isSynced) {
ref
.read(vehicleProvider.notifier)
- .setTemperature(side: Side.left, value: temperature);
- } else {
+ .setTemperature(side: Side.right, value: temperature);
+ }
+ } else {
+ if (isSynced) {
ref
.read(vehicleProvider.notifier)
- .setTemperature(side: Side.right, value: temperature);
+ .setTemperatureSynced(false);
}
- });
+ ref
+ .read(vehicleProvider.notifier)
+ .setTemperature(side: Side.right, value: temperature);
+ }
}
@override
Widget build(BuildContext context) {
- //final temperature = ref.watch(vehicleProvider.select((vehicle) => vehicle));
- // final outsideTemperature = ref
- // .watch(vehicleProvider.select((vehicle) => vehicle.outsideTemperature));
+ int temperature = 0;
+ if (widget.side == Side.left) {
+ temperature = ref.watch(vehicleProvider.select((vehicle) => vehicle.driverTemperature));
+ } else {
+ temperature = ref.watch(vehicleProvider.select((vehicle) => vehicle.passengerTemperature));
+ }
final tempUnit =
ref.watch(unitStateProvider.select((unit) => unit.temperatureUnit));