commit a06ca800f0892cb0f38d9d5abccc319f1f173eff
parent ded1091eb1c07f8cb8409c483e8ba345d7fc1741
Author: Daniel Barlow <dan@telent.net>
Date: Sat, 22 Nov 2025 23:28:28 +0000
WIP: ecu.poll reads tables and calls a callback for each value
currently the only value is rpm
Diffstat:
1 file changed, 29 insertions(+), 3 deletions(-)
diff --git a/src/ecu.rs b/src/ecu.rs
@@ -12,10 +12,10 @@ use embassy_time::{
use log::{info};
-// implement iterator
-// https://doc.rust-lang.org/std/iter/index.html#implementing-iterator
-pub enum Command { Nop }
+pub enum Measure {
+ Rpm(i32)
+}
pub struct Ecu<'a> {
tx_peripheral : esp_hal::peripherals::GPIO21<'a>,
@@ -137,6 +137,32 @@ impl Ecu<'_> {
&r[5..]
}
+ pub async fn poll(&mut self, callback: impl AsyncFn(Measure)) {
+ let mut buf = [0u8; 80];
+ let table = self.fetch_table(0x11, &mut buf).await;
+ match table {
+ [rpm_h, rpm_l,
+ _tps_v,
+ _tps_100,
+ _ect_v,
+ _ect_deg,
+ _iat_v,
+ _iat_deg,
+ _map_v,
+ _map_kpa,
+ _, _,
+ _supply_v,
+ _speed,
+ _fuel_h, _fuel_l,
+ ..
+ ] => {
+ let rpm : i32 = (rpm_h << 8 + rpm_l).into();
+ callback(Measure::Rpm(rpm)).await;
+ },
+ _ => ()
+ }
+ }
+
pub async fn do_stuff(&mut self) {
let mut buf = [0u8; 80];