mirror of
https://github.com/hubaldv/bioz-host-rs.git
synced 2025-12-06 05:11:17 +00:00
Included LED RPC.
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
|
||||
17
src/main.rs
17
src/main.rs
@@ -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}");
|
||||
|
||||
Reference in New Issue
Block a user