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

View File

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