commit 4f79126db1502c7dfc72404a4a0b690497cec005
parent 0ad9e90b9ffd23d0101bd09e6cfe1f6429d37379
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 16 Nov 2025 23:23:22 +0000
add EngineSpeedService to show we can
Diffstat:
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/src/wibble.rs b/src/wibble.rs
@@ -16,6 +16,7 @@ const L2CAP_CHANNELS_MAX: usize = 2; // Signal + att
#[gatt_server]
struct Server {
battery_service: BatteryService,
+ engine_speed_service: EngineSpeedService,
}
/// Battery service
@@ -30,6 +31,16 @@ struct BatteryService {
status: bool,
}
+#[gatt_service(uuid = "e000adbf-3508-435b-9638-eaff1d5e7c7e")]
+struct EngineSpeedService {
+ /// Battery Level
+ // #[descriptor(uuid = descriptors::VALID_RANGE, read, value = [0, 100])]
+ // #[descriptor(uuid = descriptors::MEASUREMENT_DESCRIPTION, name = "hello", read, value = "Battery Level")]
+ #[characteristic(uuid = characteristic::ROTATIONAL_SPEED, read, notify, value = 1200)]
+ rpm: i32,
+}
+
+
pub async fn run_ble(peripheral : esp_hal::peripherals::BT<'_>) {
let radio_init = esp_radio::init().expect("Failed to initialize Wi-Fi/BLE controller");
let connector = BleConnector::new(&radio_init, peripheral, Default::default()).expect("connector");
@@ -177,9 +188,16 @@ async fn custom_task<C: Controller, P: PacketPool>(
) {
let mut tick: u8 = 0;
let level = server.battery_service.level;
+ let rpm = server.engine_speed_service.rpm;
loop {
tick = tick.wrapping_add(1);
info!("[custom_task] notifying connection of tick {}", tick);
+
+ // if the characteristic does not support notifications,
+ // this would return an error. Use `set` instead, in that case.
+ // See inline comments in trouble-host/src/attribute.rs around
+ // line 631
+
if level.notify(conn, &tick).await.is_err() {
info!("[custom_task] error notifying connection");
break;
@@ -191,6 +209,9 @@ async fn custom_task<C: Controller, P: PacketPool>(
info!("[custom_task] error getting RSSI");
break;
};
+ let new_rpm = 1200 + 20 * i32::from(tick);
+ rpm.notify(conn, &new_rpm).await.expect("failed to notify");
+
Timer::after_secs(2).await;
}
}