diff --git a/Cargo.toml b/Cargo.toml index 7b07c9b..8628279 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,3 @@ actix-web-static-files = "3.0" [build-dependencies] actix-web-static-files = "3.0" - -[target.armv7-unknown-linux-gnueabihf] -linker = "armv7-unknown-linux-gnueabihf" diff --git a/src/color.rs b/src/color.rs index b41c857..5cf32e7 100644 --- a/src/color.rs +++ b/src/color.rs @@ -1,8 +1,9 @@ use serde::Deserialize; +use serde::Serialize; use std::num::ParseIntError; use std::str::FromStr; -#[derive(Copy, Clone, Debug, PartialEq, Deserialize)] +#[derive(Copy, Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct Rgb(pub u8, pub u8, pub u8); impl Rgb { pub const fn to_tuple(self) -> (u8, u8, u8) { diff --git a/src/main.rs b/src/main.rs index 5bd4dd5..b6e94a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,8 @@ clippy::multiple_crate_versions, // Intentional code clippy::map_err_ignore, + // "as f32" used frequently in this project + clippy::cast_precision_loss, // This is fine clippy::implicit_return, // Missing docs is fine diff --git a/src/pattern.rs b/src/pattern.rs index d70ea52..2ed6fca 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -1,5 +1,5 @@ use crate::color::Rgb; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use std::collections::vec_deque; pub mod collide; @@ -15,7 +15,7 @@ pub use moving_rainbow::MovingRainbow; pub use orb::Orb; pub use solid::Solid; -#[derive(Deserialize, Debug)] +#[derive(Serialize, Deserialize, Debug)] pub enum Parameters { Collide(Rgb, Rgb, Rgb), Fade((Rgb,)), diff --git a/src/pattern/moving_rainbow.rs b/src/pattern/moving_rainbow.rs index f9b584b..b37e5e9 100644 --- a/src/pattern/moving_rainbow.rs +++ b/src/pattern/moving_rainbow.rs @@ -39,15 +39,16 @@ impl Pattern for MovingRainbow { // The length of the buffer // Always a factor of RAINBOW.len() * width - let length_factor = u16::try_from(RAINBOW.len()).or(Err(()))?.saturating_mul(u16::from(self.width)); + let length_factor = u16::try_from(RAINBOW.len()) + .or(Err(()))? + .saturating_mul(u16::from(self.width)); let buf_length = num_lights .checked_sub(1) .ok_or(())? .div_euclid(length_factor) .checked_add(1) .ok_or(())? - .saturating_mul(length_factor) - ; + .saturating_mul(length_factor); self.lights_buf = RAINBOW .iter() diff --git a/src/strip.rs b/src/strip.rs index f7a5b91..9972730 100644 --- a/src/strip.rs +++ b/src/strip.rs @@ -151,9 +151,9 @@ impl LedStrip { if pat.init(self.config.num_lights).is_ok() { self.pattern = Box::new(pat); } else { - let _ = message_tx.send(errors::Message::String( - String::from("Could not construct clear pattern") - )); + let _ = message_tx.send(errors::Message::String(String::from( + "Could not construct clear pattern", + ))); } } } @@ -168,7 +168,9 @@ impl LedStrip { } if exit { - let _ = message_tx.send(errors::Message::String(String::from("Exiting as requested"))); + let _ = message_tx.send(errors::Message::String(String::from( + "Exiting as requested", + ))); process::exit(0); } diff --git a/src/webui.rs b/src/webui.rs index 471410e..740bddd 100644 --- a/src/webui.rs +++ b/src/webui.rs @@ -1,7 +1,8 @@ use crate::errors; use crate::pattern; use crate::strip; -use actix_web::error::JsonPayloadError; + +use actix_web::error::{JsonPayloadError, UrlencodedError}; use actix_web::web::JsonConfig; use actix_web::{post, web, App, HttpServer, Responder, Result}; use actix_web_static_files::ResourceFiles; @@ -17,22 +18,16 @@ struct AppState { } #[post("/setcolor")] -async fn set_color( +async fn set_color_json( data: web::Data, params: web::Json, ) -> Result { println!("Got params: {:?}", params); data.strip_tx .lock() - .map_err(|_| io::Error::new( - io::ErrorKind::Other, - "Failed to get a lock", - ))? + .map_err(|_| io::Error::new(io::ErrorKind::Other, "Failed to get a lock"))? .send(strip::Message::ChangePattern(params.0.to_pattern())) - .map_err(|_| io::Error::new( - io::ErrorKind::Other, - "Failed to send to channel", - ))?; + .map_err(|_| io::Error::new(io::ErrorKind::Other, "Failed to send to channel"))?; Ok(format!("{:?}", params)) } @@ -57,7 +52,13 @@ pub async fn start( err.into() }), ) - .service(set_color), + .app_data(web::FormConfig::default().error_handler( + |err: UrlencodedError, _req| { + println!("{:?}", err); + err.into() + }, + )) + .service(set_color_json), ) .service(ResourceFiles::new("/", generated)) }) diff --git a/web/src/Form.svelte b/web/src/Form.svelte index 64628bb..0775169 100644 --- a/web/src/Form.svelte +++ b/web/src/Form.svelte @@ -51,28 +51,17 @@ return x.value; } }); - //console.log(selectedPattern); - console.log("Form data: "); - console.log(ret); return ret; } function handleSubmit() { - // Default options are marked with * const response = fetch(url, { - method: 'POST', // *GET, POST, PUT, DELETE, etc. - // mode: 'no-cors', // no-cors, *cors, same-origin - // cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached - // credentials: 'same-origin', // include, *same-origin, omit + method: 'POST', headers: { 'Content-Type': 'application/json' - // 'Content-Type': 'application/x-www-form-urlencoded', }, - // redirect: 'follow', // manual, *follow, error - // referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url - body: JSON.stringify(getFormData()) // body data type must match "Content-Type" header + body: JSON.stringify(getFormData()) }).then(r => console.log(response)); - // return response.json(); // parses JSON response into native JavaScript objects }