diff --git a/example/lib/widgets/sensor_view.dart b/example/lib/widgets/sensor_view.dart index 001ad0e..b38a372 100644 --- a/example/lib/widgets/sensor_view.dart +++ b/example/lib/widgets/sensor_view.dart @@ -34,9 +34,18 @@ class SensorView extends StatelessWidget { List renderedValues = []; if (snapshot.hasData) { final sensorValue = snapshot.data!; - renderedValues = sensorValue.values - .map((v) => v.toStringAsFixed(2).padLeft(7, ' ')) - .toList(); + renderedValues = sensorValue.valueStrings; + + if (sensorValue is SensorDoubleValue) { + renderedValues = sensorValue.values + .map((v) => v.toStringAsFixed(2).padLeft(7, ' ')) + .toList(); + } else if (sensorValue is SensorIntValue) { + renderedValues = sensorValue.values + .map((v) => v.toString().padLeft(7, ' ')) + .toList(); + } + } else { renderedValues = List.generate( sensor.axisCount, (_) => "#.##".padLeft(7, ' ')); diff --git a/lib/src/models/capabilities/sensor.dart b/lib/src/models/capabilities/sensor.dart index 27cc719..552e773 100644 --- a/lib/src/models/capabilities/sensor.dart +++ b/lib/src/models/capabilities/sensor.dart @@ -19,13 +19,51 @@ abstract class Sensor { } class SensorValue { - final List values; + final List _valuesStrings; final int timestamp; - int get dimensions => values.length; + int get dimensions => _valuesStrings.length; + + List get valueStrings => _valuesStrings; const SensorValue({ - required this.values, + required List valueStrings, required this.timestamp, - }); + }) : _valuesStrings = valueStrings; +} + +class SensorDoubleValue extends SensorValue { + final List values; + + const SensorDoubleValue({ + required this.values, + required int timestamp, + }) : super( + valueStrings: const [], + timestamp: timestamp, + ); + + @override + int get dimensions => values.length; + + @override + List get valueStrings => values.map((e) => e.toString()).toList(); +} + +class SensorIntValue extends SensorValue { + final List values; + + const SensorIntValue({ + required this.values, + required int timestamp, + }) : super( + valueStrings: const [], + timestamp: timestamp, + ); + + @override + int get dimensions => values.length; + + @override + List get valueStrings => values.map((e) => e.toString()).toList(); } diff --git a/lib/src/models/devices/cosinuss_one.dart b/lib/src/models/devices/cosinuss_one.dart index 4294dc9..88bc787 100644 --- a/lib/src/models/devices/cosinuss_one.dart +++ b/lib/src/models/devices/cosinuss_one.dart @@ -175,7 +175,7 @@ class _CosinussOneSensor extends Sensor { int accZ = bytes[18]; streamController.add( - SensorValue( + SensorDoubleValue( values: [accX.toDouble(), accY.toDouble(), accZ.toDouble()], timestamp: DateTime.now().millisecondsSinceEpoch - startTime, ), @@ -228,7 +228,7 @@ class _CosinussOneSensor extends Sensor { 32; // ambient light sensor (e.g., if sensor is not placed correctly) streamController.add( - SensorValue( + SensorDoubleValue( values: [ ppgRed.toDouble(), ppgGreen.toDouble(), @@ -268,7 +268,7 @@ class _CosinussOneSensor extends Sensor { } streamController.add( - SensorValue( + SensorDoubleValue( values: [temperature], timestamp: DateTime.now().millisecondsSinceEpoch - startTime, ), @@ -300,7 +300,7 @@ class _CosinussOneSensor extends Sensor { } streamController.add( - SensorValue( + SensorDoubleValue( values: [bpm.toDouble()], timestamp: DateTime.now().millisecondsSinceEpoch - startTime, ), diff --git a/lib/src/models/devices/open_earable_v1.dart b/lib/src/models/devices/open_earable_v1.dart index 50b95ff..5ee8c21 100644 --- a/lib/src/models/devices/open_earable_v1.dart +++ b/lib/src/models/devices/open_earable_v1.dart @@ -414,7 +414,7 @@ class _OpenEarableSensor extends Sensor { _dataSubscription = _sensorManager.subscribeToSensorData(0).listen((data) { int timestamp = data["timestamp"]; - SensorValue sensorValue = SensorValue( + SensorValue sensorValue = SensorDoubleValue( values: [ kalmanX.filtered(data[sensorName]["X"]), kalmanY.filtered(data[sensorName]["Y"]), @@ -436,7 +436,7 @@ class _OpenEarableSensor extends Sensor { _dataSubscription = _sensorManager.subscribeToSensorData(1).listen((data) { int timestamp = data["timestamp"]; - SensorValue sensorValue = SensorValue( + SensorValue sensorValue = SensorDoubleValue( values: [data[sensorName][componentName]], timestamp: timestamp, );