aboutsummaryrefslogtreecommitdiffstats
path: root/lib/vehicle-signals/vss_providers.dart
diff options
context:
space:
mode:
authorScott Murray <scott.murray@konsulko.com>2022-12-28 15:05:26 -0500
committerScott Murray <scott.murray@konsulko.com>2022-12-29 06:35:38 +0000
commit4fbd3fdb9e01c197d972b78961f0d033534a5cc7 (patch)
treedef7bfc0d0f11746006439b33019b61dfc16e1b8 /lib/vehicle-signals/vss_providers.dart
parente21709c9601209e26d09dea0a45e37f0636bb605 (diff)
Add volume control to bottom panel
Changes: - Import a reworked version of the KUKSA.val client code from the Flutter dashboard app, with the aggregated signal Riverpod provider replaced with per-signal providers for the signal the homescreen needs and a couple of temperature ones it might use. Using separate providers is more in-line with recommended Riverpod best practices. - Various tweaks to enable using Riverpod. - Split the bottom panel out into its own widget, and add a stack in it to layer the default logo panel with the volume control slider, which has been added as a new widget definition to provide the hook to drive timer based lowering behavior like the Qt homescreen does. - The KUKSA.val connection widget has been added to the bottom panel rather than overriding the top-level widget as in the dashboard and HVAC apps. This seems preferable with respect to still providing some functionality in the event KUKSA.val is unavailable. - Remove the old demo dashboard and HVAC pages that are now unused, along with the image assets they needed, to allow cleaning up pubspec.yaml and ease maintenance. Bug-AGL: SPEC-4659 Signed-off-by: Scott Murray <scott.murray@konsulko.com> Change-Id: I5d9180a3461948a58321564e71134c4961ce0ef7
Diffstat (limited to 'lib/vehicle-signals/vss_providers.dart')
-rw-r--r--lib/vehicle-signals/vss_providers.dart130
1 files changed, 130 insertions, 0 deletions
diff --git a/lib/vehicle-signals/vss_providers.dart b/lib/vehicle-signals/vss_providers.dart
new file mode 100644
index 0000000..630a273
--- /dev/null
+++ b/lib/vehicle-signals/vss_providers.dart
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: Apache-2.0
+//import 'dart:ffi';
+import 'dart:io';
+import 'package:meta/meta.dart';
+import 'package:flutter_riverpod/flutter_riverpod.dart';
+
+@immutable
+class VISServerSocket {
+ const VISServerSocket({required this.socket});
+
+ final WebSocket? socket;
+
+ VISServerSocket copyWith({WebSocket? socket}) {
+ return VISServerSocket(socket: socket ?? this.socket);
+ }
+}
+
+class VISServerSocketNotifier extends StateNotifier<VISServerSocket> {
+ VISServerSocketNotifier() : super(_initialValue);
+
+ static final VISServerSocket _initialValue = VISServerSocket(socket: null);
+
+ void update(WebSocket socket) {
+ state = state.copyWith(socket: socket);
+ }
+}
+
+final VISServerSocketProvider =
+ StateNotifierProvider<VISServerSocketNotifier, VISServerSocket>((ref) {
+ return VISServerSocketNotifier();
+});
+
+// Media Volume
+
+@immutable
+class VehicleSignalMediaVolume {
+ const VehicleSignalMediaVolume({required this.volume});
+
+ final int volume;
+
+ VehicleSignalMediaVolume copyWith({int? volume}) {
+ return VehicleSignalMediaVolume(volume: volume ?? this.volume);
+ }
+}
+
+class VehicleSignalMediaVolumeNotifier
+ extends StateNotifier<VehicleSignalMediaVolume> {
+ VehicleSignalMediaVolumeNotifier() : super(_initialValue);
+
+ static final VehicleSignalMediaVolume _initialValue =
+ VehicleSignalMediaVolume(volume: 50);
+
+ void update({int? volume}) {
+ int? n = volume;
+ if (n != null) {
+ n = n.toUnsigned(8);
+ if (n > 100) n = 100;
+ }
+ state = state.copyWith(volume: n);
+ }
+}
+
+//final vehicleSignalMediaVolumeProvider = StateNotifierProvider<
+// VehicleSignalMediaVolumeNotifier, VehicleSignalMediaVolume>((ref) {
+// return VehicleSignalMediaVolumeNotifier();
+//});
+
+final vehicleSignalMediaVolumeProvider = StateNotifierProvider<
+ VehicleSignalMediaVolumeNotifier,
+ VehicleSignalMediaVolume>((ref) => VehicleSignalMediaVolumeNotifier());
+
+// Inside Temperature
+
+@immutable
+class VehicleSignalInsideTemp {
+ const VehicleSignalInsideTemp({required this.temp});
+
+ final double temp;
+
+ VehicleSignalInsideTemp copyWith({double? temp}) {
+ return VehicleSignalInsideTemp(temp: temp ?? this.temp);
+ }
+}
+
+class VehicleSignalInsideTempNotifier
+ extends StateNotifier<VehicleSignalInsideTemp> {
+ VehicleSignalInsideTempNotifier() : super(_initialValue);
+
+ static final VehicleSignalInsideTemp _initialValue =
+ VehicleSignalInsideTemp(temp: 25);
+
+ void update({double? temp}) {
+ state = state.copyWith(temp: temp);
+ }
+}
+
+final vehicleSignalInsideTempProvider = StateNotifierProvider<
+ VehicleSignalInsideTempNotifier, VehicleSignalInsideTemp>(
+ (ref) => VehicleSignalInsideTempNotifier(),
+);
+
+// Outside Temperature
+
+@immutable
+class VehicleSignalOutsideTemp {
+ const VehicleSignalOutsideTemp({required this.temp});
+
+ final double temp;
+
+ VehicleSignalOutsideTemp copyWith({double? temp}) {
+ return VehicleSignalOutsideTemp(temp: temp ?? this.temp);
+ }
+}
+
+class VehicleSignalOutsideTempNotifier
+ extends StateNotifier<VehicleSignalOutsideTemp> {
+ VehicleSignalOutsideTempNotifier() : super(_initialValue);
+
+ static final VehicleSignalOutsideTemp _initialValue =
+ VehicleSignalOutsideTemp(temp: 32);
+
+ void update({double? temp}) {
+ state = state.copyWith(temp: temp);
+ }
+}
+
+final vehicleSignalOutsideTempProvider = StateNotifierProvider<
+ VehicleSignalOutsideTempNotifier, VehicleSignalOutsideTemp>(
+ (ref) => VehicleSignalOutsideTempNotifier(),
+);