aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/core/constants/vss_path.dart4
-rw-r--r--lib/data/data_providers/audio_notifier.dart5
-rw-r--r--lib/data/data_providers/vehicle_notifier.dart71
-rw-r--r--lib/presentation/common_widget/volume_bar.dart32
-rw-r--r--lib/presentation/screens/media_player/widgets/media_volume_bar.dart30
5 files changed, 74 insertions, 68 deletions
diff --git a/lib/core/constants/vss_path.dart b/lib/core/constants/vss_path.dart
index 236287f..2147b75 100644
--- a/lib/core/constants/vss_path.dart
+++ b/lib/core/constants/vss_path.dart
@@ -10,9 +10,9 @@ class VSSPath {
static const String vehicleMediaVolume =
'Vehicle.Cabin.Infotainment.Media.Volume';
static const String vehicleIsChildLockActiveLeft =
- 'Vehicle.Cabin.Door.Row1.DriverSide.IsChildLockActive';
+ 'Vehicle.Cabin.Door.Row2.DriverSide.IsChildLockActive';
static const String vehicleIsChildLockActiveRight =
- 'Vehicle.Cabin.Door.Row1.PassengerSide.IsChildLockActive';
+ 'Vehicle.Cabin.Door.Row2.PassengerSide.IsChildLockActive';
static const String vehicleEngineSpeed =
'Vehicle.Powertrain.CombustionEngine.Speed';
static const String vehicleFrontLeftTire =
diff --git a/lib/data/data_providers/audio_notifier.dart b/lib/data/data_providers/audio_notifier.dart
index 8981036..1f8c1a9 100644
--- a/lib/data/data_providers/audio_notifier.dart
+++ b/lib/data/data_providers/audio_notifier.dart
@@ -7,10 +7,6 @@ class AudioNotifier extends StateNotifier<Audio> {
state = state.copyWith(treble: 5.0, bass: 5.0, rearFront: 5.0);
}
- void setVolume(double newVal) {
- state = state.copyWith(volume: newVal);
- }
-
void setTreble(double newVal) {
state = state.copyWith(treble: newVal);
}
@@ -23,3 +19,4 @@ class AudioNotifier extends StateNotifier<Audio> {
state = state.copyWith(rearFront: newVal);
}
}
+
diff --git a/lib/data/data_providers/vehicle_notifier.dart b/lib/data/data_providers/vehicle_notifier.dart
index f94d5ab..8538ac1 100644
--- a/lib/data/data_providers/vehicle_notifier.dart
+++ b/lib/data/data_providers/vehicle_notifier.dart
@@ -19,8 +19,13 @@ class KuksaConfig {
static int defaultPort = 55555;
static String defaultCaCertPath = '/etc/kuksa-val/CA.pem';
- KuksaConfig({required this.hostname, required this.port, required this.authorization,
- required this.use_tls, required this.ca_certificate, required this.tls_server_name});
+ KuksaConfig(
+ {required this.hostname,
+ required this.port,
+ required this.authorization,
+ required this.use_tls,
+ required this.ca_certificate,
+ required this.tls_server_name});
}
class VehicleNotifier extends StateNotifier<Vehicle> {
@@ -61,13 +66,11 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
state = state.copyWith(fuelLevel: update.entry.value.uint32);
}
break;
- // case VSSPath.vehicleMediaVolume:
- // if (update.entry.value.hasInt32()) {
- // ref
- // .read(vehicleMediaVolume.notifier)
- // .update((state) => state = update.entry.value.uint32);
- // }
- // break;
+ case VSSPath.vehicleMediaVolume:
+ if (update.entry.value.hasUint32()) {
+ state = state.copyWith(mediaVolume: update.entry.value.uint32);
+ }
+ break;
case VSSPath.vehicleIsChildLockActiveLeft:
if (update.entry.value.hasBool_12()) {
state =
@@ -106,7 +109,6 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
}
break;
- ///
case VSSPath.vehicleIsAirConditioningActive:
if (update.entry.value.hasBool_12()) {
state = state.copyWith(
@@ -177,8 +179,7 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
if (yamlMap.containsKey('use-tls')) {
var value = yamlMap['use-tls'];
- if (value is bool)
- use_tls = value;
+ if (value is bool) use_tls = value;
}
if (use_tls) {
@@ -194,7 +195,6 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
if (yamlMap.containsKey('authorization')) {
token = yamlMap['authorization'];
}
-
} catch (e) {
//debugPrint('ERROR: Could not read from file: $configFile');
debugPrint(e.toString());
@@ -217,8 +217,7 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
if (yamlMap.containsKey('use-tls')) {
var value = yamlMap['use-tls'];
- if (value is bool)
- use_tls = value;
+ if (value is bool) use_tls = value;
}
//debugPrint("Use TLS = $use_tls");
@@ -228,7 +227,7 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
}
try {
ca_cert = File(ca_path).readAsBytesSync();
- } on Exception catch(_) {
+ } on Exception catch (_) {
print("ERROR: Could not read CA certificate file $ca_path");
ca_cert = [];
}
@@ -248,7 +247,7 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
String tokenFile = token;
try {
token = await File(tokenFile).readAsString();
- } on Exception catch(_) {
+ } on Exception catch (_) {
print("ERROR: Could not read authorization token file $token");
token = "";
}
@@ -260,13 +259,12 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
//debugPrint(e.toString());
}
return KuksaConfig(
- hostname: hostname,
- port: port,
- authorization: token,
- use_tls: use_tls,
- ca_certificate: ca_cert,
- tls_server_name: tls_server_name
- );
+ hostname: hostname,
+ port: port,
+ authorization: token,
+ use_tls: use_tls,
+ ca_certificate: ca_cert,
+ tls_server_name: tls_server_name);
}
void startListen() async {
@@ -275,20 +273,19 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
if (config.use_tls && config.ca_certificate.isNotEmpty) {
print("Using TLS");
if (config.tls_server_name.isNotEmpty)
- creds = ChannelCredentials.secure(certificates: config.ca_certificate,
- authority: config.tls_server_name);
+ creds = ChannelCredentials.secure(
+ certificates: config.ca_certificate,
+ authority: config.tls_server_name);
else
creds = ChannelCredentials.secure(certificates: config.ca_certificate);
} else {
creds = ChannelCredentials.insecure();
}
- channel = ClientChannel(
- config.hostname,
- port: config.port,
- options: ChannelOptions(credentials: creds)
- );
+ channel = ClientChannel(config.hostname,
+ port: config.port, options: ChannelOptions(credentials: creds));
debugPrint('Start Listen on port: ${config.port}');
stub = VALClient(channel);
+ authorization = config.authorization;
List<String> fewSignals = VSSPath().getSignalsList();
var request = SubscribeRequest();
for (int i = 0; i < fewSignals.length; i++) {
@@ -318,7 +315,7 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
}
}
- void setChildLock({required String side}) {
+ void setChildLock({required String side}) async {
var helper = ValClientHelper(stub: stub, authorization: authorization);
try {
switch (side) {
@@ -349,6 +346,16 @@ class VehicleNotifier extends StateNotifier<Vehicle> {
}
}
+ void setVolume(double newVal) {
+ state = state.copyWith(mediaVolume: newVal.toInt());
+ var helper = ValClientHelper(stub: stub, authorization: authorization);
+ helper.setUint32(
+ VSSPath.vehicleMediaVolume,
+ newVal.toInt(),
+ false,
+ );
+ }
+
void setTemperature({required Side side, required int value}) {
var helper = ValClientHelper(stub: stub, authorization: authorization);
try {
diff --git a/lib/presentation/common_widget/volume_bar.dart b/lib/presentation/common_widget/volume_bar.dart
index a029698..f494332 100644
--- a/lib/presentation/common_widget/volume_bar.dart
+++ b/lib/presentation/common_widget/volume_bar.dart
@@ -14,32 +14,32 @@ class VolumeBarState extends ConsumerState<VolumeBar> {
@override
void initState() {
super.initState();
- // "ref" can be used in all life-cycles of a StatefulWidget.
- //ref.read(counterProvider);
}
void increaseVolume() {
+ val += 10;
+ if (val > 100) {
+ val = 100;
+ }
setState(() {
- if (val < 20) {
- val++;
- ref.read(audioStateProvider.notifier).setVolume(val);
- }
+ ref.read(vehicleProvider.notifier).setVolume(val);
});
}
void decreaseVolume() {
+ val -= 10;
+ if (val < 0) {
+ val = 0;
+ }
setState(() {
- if (val > 0) {
- val--;
- ref.read(audioStateProvider.notifier).setVolume(val);
- }
+ ref.read(vehicleProvider.notifier).setVolume(val);
});
}
void setVolume(double newWalue) {
setState(() {
val = newWalue;
- ref.read(audioStateProvider.notifier).setVolume(val);
+ ref.read(vehicleProvider.notifier).setVolume(val);
});
}
@@ -48,8 +48,8 @@ class VolumeBarState extends ConsumerState<VolumeBar> {
@override
Widget build(BuildContext context) {
final volumeValue =
- ref.watch(audioStateProvider.select((audio) => audio.volume));
- val = volumeValue;
+ ref.watch(vehicleProvider.select((vehicle) => vehicle.mediaVolume));
+ val = volumeValue.toDouble();
return Column(
// mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.center,
@@ -114,9 +114,9 @@ class VolumeBarState extends ConsumerState<VolumeBar> {
),
child: Slider(
min: 0,
- max: 20,
- value: volumeValue,
- divisions: 20,
+ max: 100,
+ value: volumeValue.toDouble(),
+ divisions: 10,
onChanged: (newValue) {
setVolume(newValue);
},
diff --git a/lib/presentation/screens/media_player/widgets/media_volume_bar.dart b/lib/presentation/screens/media_player/widgets/media_volume_bar.dart
index 2b063b4..ed962a7 100644
--- a/lib/presentation/screens/media_player/widgets/media_volume_bar.dart
+++ b/lib/presentation/screens/media_player/widgets/media_volume_bar.dart
@@ -14,28 +14,30 @@ class CustomVolumeSlider extends ConsumerStatefulWidget {
class CustomVolumeSliderState extends ConsumerState<CustomVolumeSlider> {
void _increase() {
+ _currentVal += 10;
+ if (_currentVal > 100) {
+ _currentVal = 100;
+ }
setState(() {
- if (_currentVal < 20) {
- _currentVal++;
- ref.read(audioStateProvider.notifier).setVolume(_currentVal);
- }
+ ref.read(vehicleProvider.notifier).setVolume(_currentVal);
});
}
void _dercrease() {
+ _currentVal -= 10;
+ if (_currentVal < 0) {
+ _currentVal = 0;
+ }
setState(() {
- if (_currentVal > 0) {
- _currentVal--;
- ref.read(audioStateProvider.notifier).setVolume(_currentVal);
- }
+ ref.read(vehicleProvider.notifier).setVolume(_currentVal);
});
}
- double _currentVal = 5;
+ double _currentVal = 50;
@override
Widget build(BuildContext context) {
final volumeValue =
- ref.watch(audioStateProvider.select((audio) => audio.volume));
+ ref.watch(vehicleProvider.select((audio) => audio.mediaVolume));
return Column(
//crossAxisAlignment: CrossAxisAlignment.center,
@@ -99,12 +101,12 @@ class CustomVolumeSliderState extends ConsumerState<CustomVolumeSlider> {
//trackHeight: 5,
),
child: Slider(
- divisions: 20,
+ divisions: 10,
min: 0,
- max: 20,
- value: volumeValue,
+ max: 100,
+ value: volumeValue.toDouble(),
onChanged: (newValue) {
- ref.read(audioStateProvider.notifier).setVolume(newValue);
+ ref.read(vehicleProvider.notifier).setVolume(newValue);
_currentVal = newValue;
},
),