play over network
This commit is contained in:
parent
43fedd11bf
commit
860e49de9d
9 changed files with 123 additions and 8 deletions
33
common/Cargo.lock
generated
33
common/Cargo.lock
generated
|
@ -11,10 +11,17 @@ dependencies = [
|
||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "common"
|
name = "common"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"heapless",
|
||||||
"serde",
|
"serde",
|
||||||
"sha3",
|
"sha3",
|
||||||
]
|
]
|
||||||
|
@ -58,6 +65,26 @@ dependencies = [
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hash32"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heapless"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
|
||||||
|
dependencies = [
|
||||||
|
"hash32",
|
||||||
|
"serde",
|
||||||
|
"stable_deref_trait",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "keccak"
|
name = "keccak"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
|
@ -121,6 +148,12 @@ dependencies = [
|
||||||
"keccak",
|
"keccak",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "stable_deref_trait"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.90"
|
version = "2.0.90"
|
||||||
|
|
|
@ -6,3 +6,4 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
sha3 = {version="0.10.0", default-features=false}
|
sha3 = {version="0.10.0", default-features=false}
|
||||||
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
|
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
|
||||||
|
heapless = { version = "0.8.0", features = ["serde"] }
|
||||||
|
|
|
@ -9,6 +9,7 @@ pub enum Request {
|
||||||
SetRecentBadge(Name),
|
SetRecentBadge(Name),
|
||||||
SetBadge(Name, u64),
|
SetBadge(Name, u64),
|
||||||
SetVolume(u8),
|
SetVolume(u8),
|
||||||
|
Play(heapless::String<32>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
|
#[derive(Clone, Copy, Serialize, Deserialize, Debug)]
|
||||||
|
|
2
outside/Cargo.lock
generated
2
outside/Cargo.lock
generated
|
@ -264,6 +264,7 @@ dependencies = [
|
||||||
name = "common"
|
name = "common"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"heapless 0.8.0",
|
||||||
"serde",
|
"serde",
|
||||||
"sha3",
|
"sha3",
|
||||||
]
|
]
|
||||||
|
@ -1303,6 +1304,7 @@ checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"defmt",
|
"defmt",
|
||||||
"hash32 0.3.1",
|
"hash32 0.3.1",
|
||||||
|
"serde",
|
||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ pub enum MusicCommand {
|
||||||
Introduce(Name, bool),
|
Introduce(Name, bool),
|
||||||
/// 0-30
|
/// 0-30
|
||||||
SetVolume(u8),
|
SetVolume(u8),
|
||||||
Play(&'static str),
|
Play(heapless::String<32>),
|
||||||
Button(),
|
Button(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,9 @@ pub async fn server_task(stack: embassy_net::Stack<'static>) {
|
||||||
Ok(Request::SetVolume(vol)) => {
|
Ok(Request::SetVolume(vol)) => {
|
||||||
COMMANDS.send(crate::music::MusicCommand::SetVolume(vol)).await;
|
COMMANDS.send(crate::music::MusicCommand::SetVolume(vol)).await;
|
||||||
}
|
}
|
||||||
|
Ok(Request::Play(song)) => {
|
||||||
|
COMMANDS.send(crate::music::MusicCommand::Play(song))
|
||||||
|
}
|
||||||
Err(e) => { info!("parse error: {e}") }
|
Err(e) => { info!("parse error: {e}") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
26
server/Cargo.lock
generated
26
server/Cargo.lock
generated
|
@ -162,6 +162,7 @@ checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15"
|
||||||
name = "common"
|
name = "common"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"heapless 0.8.0",
|
||||||
"serde",
|
"serde",
|
||||||
"sha3",
|
"sha3",
|
||||||
]
|
]
|
||||||
|
@ -366,6 +367,15 @@ dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hash32"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "47d60b12902ba28e2730cd37e95b8c9223af2808df9e902d4df49588d1470606"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "heapless"
|
name = "heapless"
|
||||||
version = "0.7.17"
|
version = "0.7.17"
|
||||||
|
@ -373,13 +383,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f"
|
checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atomic-polyfill",
|
"atomic-polyfill",
|
||||||
"hash32",
|
"hash32 0.2.1",
|
||||||
"rustc_version",
|
"rustc_version",
|
||||||
"serde",
|
"serde",
|
||||||
"spin",
|
"spin",
|
||||||
"stable_deref_trait",
|
"stable_deref_trait",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heapless"
|
||||||
|
version = "0.8.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad"
|
||||||
|
dependencies = [
|
||||||
|
"hash32 0.3.1",
|
||||||
|
"serde",
|
||||||
|
"stable_deref_trait",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "http"
|
name = "http"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
|
@ -660,7 +681,7 @@ dependencies = [
|
||||||
"cobs",
|
"cobs",
|
||||||
"embedded-io 0.4.0",
|
"embedded-io 0.4.0",
|
||||||
"embedded-io 0.6.1",
|
"embedded-io 0.6.1",
|
||||||
"heapless",
|
"heapless 0.7.17",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -797,6 +818,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"axum",
|
"axum",
|
||||||
"common",
|
"common",
|
||||||
|
"heapless 0.8.0",
|
||||||
"ping-rs",
|
"ping-rs",
|
||||||
"postcard",
|
"postcard",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -7,6 +7,7 @@ edition = "2021"
|
||||||
anyhow = "1.0.94"
|
anyhow = "1.0.94"
|
||||||
axum = "0.7.9"
|
axum = "0.7.9"
|
||||||
common = {path = "../common"}
|
common = {path = "../common"}
|
||||||
|
heapless = { version = "0.8.0", features = ["serde"] }
|
||||||
ping-rs = "0.1.2"
|
ping-rs = "0.1.2"
|
||||||
postcard = {version = "1.0.0", features = ["alloc"]}
|
postcard = {version = "1.0.0", features = ["alloc"]}
|
||||||
serde = "*"
|
serde = "*"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
use std::{collections::HashMap, net::Ipv4Addr, sync::Arc, time::Duration};
|
use std::{collections::HashMap, net::Ipv4Addr, str::FromStr, sync::Arc, time::Duration};
|
||||||
|
|
||||||
use axum::{extract::State, http::StatusCode, response::Html, routing::{get, post}, serve, Form, Router};
|
use axum::{extract::State, http::StatusCode, response::Html, routing::{get, post}, serve, Form, Router};
|
||||||
use common::{Name, Request};
|
use common::{Name, Request};
|
||||||
|
@ -73,11 +73,12 @@ async fn main() -> Result<()>{
|
||||||
|
|
||||||
let app: Router = Router::new()
|
let app: Router = Router::new()
|
||||||
.route("/names", get(names))
|
.route("/names", get(names))
|
||||||
|
.route("/soundboard", get(soundboard))
|
||||||
.route("/", get(root))
|
.route("/", get(root))
|
||||||
.route("/admin", get(control))
|
.route("/admin", get(control))
|
||||||
.route("/phil", get(phil))
|
.route("/phil", get(phil))
|
||||||
.route("/recent", get(recent_badge))
|
.route("/recent", get(recent_badge))
|
||||||
.route("/setLast", post(set_last))
|
.route("/play", post(play))
|
||||||
.route("/openDoor", post(open_door))
|
.route("/openDoor", post(open_door))
|
||||||
.route("/open", get(open_door))
|
.route("/open", get(open_door))
|
||||||
.route("/setVolume", post(set_volume))
|
.route("/setVolume", post(set_volume))
|
||||||
|
@ -123,9 +124,9 @@ async fn main() -> Result<()>{
|
||||||
let door = Ipv4Addr::new(192,168,0,10).into();
|
let door = Ipv4Addr::new(192,168,0,10).into();
|
||||||
let router = Ipv4Addr::new(192,168,0,50).into();
|
let router = Ipv4Addr::new(192,168,0,50).into();
|
||||||
let (fish,door,router) = join!(
|
let (fish,door,router) = join!(
|
||||||
send_ping_async(&fish, Duration::from_millis(1500), Arc::new(&[255,127]), None),
|
send_ping_async(&fish, Duration::from_millis(3500), Arc::new(&[255,127]), None),
|
||||||
send_ping_async(&door, Duration::from_millis(1500), Arc::new(&[255,127]), None),
|
send_ping_async(&door, Duration::from_millis(3500), Arc::new(&[255,127]), None),
|
||||||
send_ping_async(&router, Duration::from_millis(1500), Arc::new(&[255,127]), None)
|
send_ping_async(&router, Duration::from_millis(3500), Arc::new(&[255,127]), None)
|
||||||
);
|
);
|
||||||
|
|
||||||
let status = NetStatus {
|
let status = NetStatus {
|
||||||
|
@ -204,6 +205,36 @@ async fn root() -> Html<String> {
|
||||||
"#);
|
"#);
|
||||||
Html::from(page)
|
Html::from(page)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn soundboard() -> Html<String> {
|
||||||
|
let mut page = format!(r#"
|
||||||
|
<h1>soundboard</h1>
|
||||||
|
"#);
|
||||||
|
|
||||||
|
for (name, sound) in [
|
||||||
|
("I'm John the Fish!", "b1"),
|
||||||
|
] {
|
||||||
|
page.push_str(&format!(r#"
|
||||||
|
<form target="output" style="display:inline; margin-right:10px; " action="setLast" method="post" id="myForm">
|
||||||
|
<button style="font-size:40px;" type="submit" name="name" value="{sound}" target="output">{name}</button>
|
||||||
|
</form>
|
||||||
|
"#));
|
||||||
|
}
|
||||||
|
|
||||||
|
page.push_str(&format!(r#"
|
||||||
|
<form target="output" style="margin-top:10px;" action="setLast" method="post" id="myForm">
|
||||||
|
<input style="font-size:40px;" name="name" placeholder="other" "type="text"></input>
|
||||||
|
<button style="font-size:40px;" type="submit" target="output">other</button>
|
||||||
|
</form>
|
||||||
|
<form target="output" action="setVolume" method="post" id="myForm">
|
||||||
|
<input type="range" min="0" max="30" value="0" name="volume" class="slider" id="volume">
|
||||||
|
<button style="font-size:30px;" type="submit" target="output">set volume</button>
|
||||||
|
</form>
|
||||||
|
<iframe name="output"></iframe>
|
||||||
|
"#));
|
||||||
|
Html::from(page)
|
||||||
|
}
|
||||||
|
|
||||||
async fn names(state: State<AppState>) -> Html<String> {
|
async fn names(state: State<AppState>) -> Html<String> {
|
||||||
let last_badge_view = last_badge_view(&state).await;
|
let last_badge_view = last_badge_view(&state).await;
|
||||||
|
|
||||||
|
@ -332,6 +363,27 @@ async fn set_volume(
|
||||||
Html::from(format!("<p>volume is now {}</p></br><a href=\"/\">back</a>", input.volume))
|
Html::from(format!("<p>volume is now {}</p></br><a href=\"/\">back</a>", input.volume))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize)]
|
||||||
|
struct SongForm {
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn play(
|
||||||
|
state: State<AppState>,
|
||||||
|
Form(input): Form<SongForm>) -> Html<String> {
|
||||||
|
|
||||||
|
info!("playing {}", input.name);
|
||||||
|
let _fish = state.fish.acquire().await.unwrap();
|
||||||
|
let mut conn = TcpStream::connect(FISH).await.unwrap();
|
||||||
|
let name = heapless::String::from_str(&input.name).unwrap();
|
||||||
|
let req = Request::Play(name);
|
||||||
|
conn.write_all(&to_allocvec(&req).unwrap()).await.unwrap();
|
||||||
|
conn.flush().await.unwrap();
|
||||||
|
|
||||||
|
|
||||||
|
Html::from(format!("<p>playing {}</p>", input.name))
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
struct NameForm {
|
struct NameForm {
|
||||||
name: String,
|
name: String,
|
||||||
|
|
Loading…
Reference in a new issue