Included LED RPC.

This commit is contained in:
2025-08-06 12:48:00 +02:00
parent 7fed5112a1
commit 4512191795
2 changed files with 10 additions and 36 deletions

View File

@@ -5,8 +5,7 @@ use postcard_rpc::{
};
use std::convert::Infallible;
use bioz_icd_rs::{
AccelRange, BadPositionError, PingEndpoint, GetUniqueIdEndpoint, Rgb8, SetAllLedEndpoint,
SetSingleLedEndpoint, SingleLed, StartAccel, StartAccelerationEndpoint,
AccelRange, PingEndpoint, GetUniqueIdEndpoint, SetGreenLedEndpoint, StartAccel, StartAccelerationEndpoint,
StopAccelerationEndpoint,
};
@@ -73,31 +72,11 @@ impl WorkbookClient {
Ok(id)
}
pub async fn set_rgb_single(
pub async fn set_green_led(
&self,
position: u32,
r: u8,
g: u8,
b: u8,
) -> Result<(), WorkbookError<BadPositionError>> {
self.client
.send_resp::<SetSingleLedEndpoint>(&SingleLed {
position,
rgb: Rgb8 { r, g, b },
})
.await?
.flatten()
}
pub async fn set_all_rgb_single(
&self,
r: u8,
g: u8,
b: u8,
frequency: f32,
) -> Result<(), WorkbookError<Infallible>> {
self.client
.send_resp::<SetAllLedEndpoint>(&[Rgb8 { r, g, b }; 24])
.await?;
self.client.send_resp::<SetGreenLedEndpoint>(&frequency).await?;
Ok(())
}

View File

@@ -49,19 +49,14 @@ async fn main() {
let ping = client.ping(idx).await.unwrap();
println!("Got: {ping}.");
}
["rgb", pos, r, g, b] => {
let (Ok(pos), Ok(r), Ok(g), Ok(b)) = (pos.parse(), r.parse(), g.parse(), b.parse())
else {
panic!();
["led", freq] => {
let Ok(freq) = freq.parse() else {
println!("Bad freq: {freq} Hz");
continue;
};
client.set_rgb_single(pos, r, g, b).await.unwrap();
}
["rgball", r, g, b] => {
let (Ok(r), Ok(g), Ok(b)) = (r.parse(), g.parse(), b.parse()) else {
panic!();
};
client.set_all_rgb_single(r, g, b).await.unwrap();
client.set_green_led(freq).await.unwrap();
}
["accel", "listen", ms, range, dur] => {
let Ok(ms) = ms.parse::<u32>() else {
println!("Bad ms: {ms}");