Skip to content

Commit

Permalink
More work on docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmunns committed Feb 3, 2025
1 parent 4ed81bb commit 53d5435
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
50 changes: 50 additions & 0 deletions book/src/tutorial/104-sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,53 @@ $ cargo run --release
Current state: '{"b":0,"g":0,"r":0}'
Updated state: '{"b":255,"g":255,"r":255}'
```

### With Shared types

In order to share types, we'll need to have a crate that can be included by both the firmware device,
as well as our host application.

The ICD for the simulators supported by poststation are available [on GitHub](https://github.com/OneVariable/poststation-util/tree/main/crates/poststation-sim-icd),
and published as `poststation-sim-icd`. We can go ahead and add that to our example project:

```sh
$ cargo add poststation-sim-icd
Updating crates.io index
Adding poststation-sim-icd v0.1.0 to dependencies
...
```

This gives us access to the types we need.

Now we can access the same endpoints as above, but without having to deal with JSON types:

```rust
// Import endpoint names and types from the ICD crate
use poststation_sim_icd::simulator::{GetStatusLed, Rgb8, SetStatusLed};

let response = client.proxy_endpoint::<GetStatusLed>(serial, 10, &()).await;
let Ok(color) = response else {
println!("First Request failed!");
return;
};
println!("initial status: {color:?}");
let new = Rgb8 { r: !color.r, g: !color.g, b: !color.b };

// Now set a new color
let response = client.proxy_endpoint::<SetStatusLed>(serial, 11, &new).await;
let Ok(()) = response else {
println!("Second Request failed!");
return;
};

// And verify the result
let response = client.proxy_endpoint::<GetStatusLed>(serial, 12, &()).await;
let Ok(new_color) = response else {
println!("Third Request failed!");
return;
};

println!("New status: {new_color:?}");
assert_eq!(new, new_color);
println!("Success!");
```
2 changes: 2 additions & 0 deletions book/src/tutorial/200-rp2040.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Using an RP2040

Coming soon! Check out the `templates` and `examples` folder of <https://github.com/OneVariable/poststation-util>!
2 changes: 1 addition & 1 deletion tools/poststation-sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "poststation-sdk"
# This version of the SDK tested with poststation v0.14.0
# This version of the SDK tested with poststation v0.15.0
version = "0.4.1"
edition = "2021"
authors = ["James Munns <[email protected]>"]
Expand Down

0 comments on commit 53d5435

Please sign in to comment.