| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- /// Latest values read from the ELM327 adapter.
- class ObdState {
- const ObdState({
- this.connected = false,
- this.connecting = false,
- this.speedKmh,
- this.throttlePercent,
- this.mafGramsPerSecond,
- this.ambientCelsius,
- this.error,
- this.updatedAt = 0,
- });
- final bool connected;
- final bool connecting;
- final double? speedKmh;
- final double? throttlePercent;
- final double? mafGramsPerSecond;
- final double? ambientCelsius;
- final String? error;
- final int updatedAt;
- bool get hasVehicleData =>
- connected && (speedKmh != null || throttlePercent != null);
- bool get hasTemperature => connected && ambientCelsius != null;
- factory ObdState.fromMap(Map<dynamic, dynamic> map) {
- double? number(String key) => (map[key] as num?)?.toDouble();
- return ObdState(
- connected: map['connected'] == true,
- connecting: map['connecting'] == true,
- speedKmh: number('speedKmh'),
- throttlePercent: number('throttle'),
- mafGramsPerSecond: number('maf'),
- ambientCelsius: number('ambient'),
- error: map['error'] as String?,
- updatedAt: (map['updatedAt'] as num?)?.toInt() ?? 0,
- );
- }
- }
|