Misc cleanup
This commit is contained in:
parent
4bc1ef4ba2
commit
a00867ad03
@ -17,6 +17,3 @@ actix-web-static-files = "3.0"
|
|||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
actix-web-static-files = "3.0"
|
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::Deserialize;
|
||||||
|
use serde::Serialize;
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
use std::str::FromStr;
|
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);
|
pub struct Rgb(pub u8, pub u8, pub u8);
|
||||||
impl Rgb {
|
impl Rgb {
|
||||||
pub const fn to_tuple(self) -> (u8, u8, u8) {
|
pub const fn to_tuple(self) -> (u8, u8, u8) {
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
clippy::multiple_crate_versions,
|
clippy::multiple_crate_versions,
|
||||||
// Intentional code
|
// Intentional code
|
||||||
clippy::map_err_ignore,
|
clippy::map_err_ignore,
|
||||||
|
// "as f32" used frequently in this project
|
||||||
|
clippy::cast_precision_loss,
|
||||||
// This is fine
|
// This is fine
|
||||||
clippy::implicit_return,
|
clippy::implicit_return,
|
||||||
// Missing docs is fine
|
// Missing docs is fine
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use crate::color::Rgb;
|
use crate::color::Rgb;
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::vec_deque;
|
use std::collections::vec_deque;
|
||||||
|
|
||||||
pub mod collide;
|
pub mod collide;
|
||||||
@ -15,7 +15,7 @@ pub use moving_rainbow::MovingRainbow;
|
|||||||
pub use orb::Orb;
|
pub use orb::Orb;
|
||||||
pub use solid::Solid;
|
pub use solid::Solid;
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub enum Parameters {
|
pub enum Parameters {
|
||||||
Collide(Rgb, Rgb, Rgb),
|
Collide(Rgb, Rgb, Rgb),
|
||||||
Fade((Rgb,)),
|
Fade((Rgb,)),
|
||||||
|
@ -39,15 +39,16 @@ impl Pattern for MovingRainbow {
|
|||||||
|
|
||||||
// The length of the buffer
|
// The length of the buffer
|
||||||
// Always a factor of RAINBOW.len() * width
|
// 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
|
let buf_length = num_lights
|
||||||
.checked_sub(1)
|
.checked_sub(1)
|
||||||
.ok_or(())?
|
.ok_or(())?
|
||||||
.div_euclid(length_factor)
|
.div_euclid(length_factor)
|
||||||
.checked_add(1)
|
.checked_add(1)
|
||||||
.ok_or(())?
|
.ok_or(())?
|
||||||
.saturating_mul(length_factor)
|
.saturating_mul(length_factor);
|
||||||
;
|
|
||||||
|
|
||||||
self.lights_buf = RAINBOW
|
self.lights_buf = RAINBOW
|
||||||
.iter()
|
.iter()
|
||||||
|
10
src/strip.rs
10
src/strip.rs
@ -151,9 +151,9 @@ impl LedStrip {
|
|||||||
if pat.init(self.config.num_lights).is_ok() {
|
if pat.init(self.config.num_lights).is_ok() {
|
||||||
self.pattern = Box::new(pat);
|
self.pattern = Box::new(pat);
|
||||||
} else {
|
} else {
|
||||||
let _ = message_tx.send(errors::Message::String(
|
let _ = message_tx.send(errors::Message::String(String::from(
|
||||||
String::from("Could not construct clear pattern")
|
"Could not construct clear pattern",
|
||||||
));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,7 +168,9 @@ impl LedStrip {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if exit {
|
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);
|
process::exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
23
src/webui.rs
23
src/webui.rs
@ -1,7 +1,8 @@
|
|||||||
use crate::errors;
|
use crate::errors;
|
||||||
use crate::pattern;
|
use crate::pattern;
|
||||||
use crate::strip;
|
use crate::strip;
|
||||||
use actix_web::error::JsonPayloadError;
|
|
||||||
|
use actix_web::error::{JsonPayloadError, UrlencodedError};
|
||||||
use actix_web::web::JsonConfig;
|
use actix_web::web::JsonConfig;
|
||||||
use actix_web::{post, web, App, HttpServer, Responder, Result};
|
use actix_web::{post, web, App, HttpServer, Responder, Result};
|
||||||
use actix_web_static_files::ResourceFiles;
|
use actix_web_static_files::ResourceFiles;
|
||||||
@ -17,22 +18,16 @@ struct AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[post("/setcolor")]
|
#[post("/setcolor")]
|
||||||
async fn set_color(
|
async fn set_color_json(
|
||||||
data: web::Data<AppState>,
|
data: web::Data<AppState>,
|
||||||
params: web::Json<pattern::Parameters>,
|
params: web::Json<pattern::Parameters>,
|
||||||
) -> Result<impl Responder> {
|
) -> Result<impl Responder> {
|
||||||
println!("Got params: {:?}", params);
|
println!("Got params: {:?}", params);
|
||||||
data.strip_tx
|
data.strip_tx
|
||||||
.lock()
|
.lock()
|
||||||
.map_err(|_| io::Error::new(
|
.map_err(|_| io::Error::new(io::ErrorKind::Other, "Failed to get a lock"))?
|
||||||
io::ErrorKind::Other,
|
|
||||||
"Failed to get a lock",
|
|
||||||
))?
|
|
||||||
.send(strip::Message::ChangePattern(params.0.to_pattern()))
|
.send(strip::Message::ChangePattern(params.0.to_pattern()))
|
||||||
.map_err(|_| io::Error::new(
|
.map_err(|_| io::Error::new(io::ErrorKind::Other, "Failed to send to channel"))?;
|
||||||
io::ErrorKind::Other,
|
|
||||||
"Failed to send to channel",
|
|
||||||
))?;
|
|
||||||
Ok(format!("{:?}", params))
|
Ok(format!("{:?}", params))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +52,13 @@ pub async fn start(
|
|||||||
err.into()
|
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))
|
.service(ResourceFiles::new("/", generated))
|
||||||
})
|
})
|
||||||
|
@ -51,28 +51,17 @@
|
|||||||
return x.value;
|
return x.value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//console.log(selectedPattern);
|
|
||||||
console.log("Form data: ");
|
|
||||||
console.log(ret);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSubmit() {
|
function handleSubmit() {
|
||||||
// Default options are marked with *
|
|
||||||
const response = fetch(url, {
|
const response = fetch(url, {
|
||||||
method: 'POST', // *GET, POST, PUT, DELETE, etc.
|
method: 'POST',
|
||||||
// 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
|
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
// 'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
},
|
},
|
||||||
// redirect: 'follow', // manual, *follow, error
|
body: JSON.stringify(getFormData())
|
||||||
// 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
|
|
||||||
}).then(r => console.log(response));
|
}).then(r => console.log(response));
|
||||||
// return response.json(); // parses JSON response into native JavaScript objects
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user