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> {
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 =
}
break;
- ///
case VSSPath.vehicleIsAirConditioningActive:
if (update.entry.value.hasBool_12()) {
state = state.copyWith(
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) {
if (yamlMap.containsKey('authorization')) {
token = yamlMap['authorization'];
}
-
} catch (e) {
//debugPrint('ERROR: Could not read from file: $configFile');
debugPrint(e.toString());
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");
}
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 = [];
}
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 = "";
}
//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 {
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++) {
}
}
- void setChildLock({required String side}) {
+ void setChildLock({required String side}) async {
var helper = ValClientHelper(stub: stub, authorization: authorization);
try {
switch (side) {
}
}
+ 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 {
@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);
});
}
@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,
),
child: Slider(
min: 0,
- max: 20,
- value: volumeValue,
- divisions: 20,
+ max: 100,
+ value: volumeValue.toDouble(),
+ divisions: 10,
onChanged: (newValue) {
setVolume(newValue);
},
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,
//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;
},
),