Misc cleanup
This commit is contained in:
parent
4bc1ef4ba2
commit
a00867ad03
@ -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"
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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,)),
|
||||
|
@ -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()
|
||||
|
10
src/strip.rs
10
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);
|
||||
}
|
||||
|
||||
|
23
src/webui.rs
23
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<AppState>,
|
||||
params: web::Json<pattern::Parameters>,
|
||||
) -> Result<impl Responder> {
|
||||
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))
|
||||
})
|
||||
|
@ -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
|
||||
}
|
||||
</script>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user