diff --git a/Cargo.toml b/Cargo.toml index 9315aab..5bb3503 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,17 +1,15 @@ [package] name = "aw-lights" version = "0.1.0" -authors = ["root"] +authors = ["Austen Adler "] edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - [dependencies] rppal = "0.7" ws2818-rgb-led-spi-driver = { path = "lib-ws2818-rgb-led-spi-driver/" } -# ws2818-rgb-led-spi-driver = { path = "ws2818-rgb-led-spi-driver/" } -# ws2818-rgb-led-spi-driver = { path = "/home/pi/tt/" } -# ws2818-rgb-led-spi-driver = { path = "/home/pi/ws2818-rgb-led-spi-driver/" } +serde = {version = "1.0", features = ["derive"]} +actix-web = {version = "3", default_features = false} +rust-embed="6.0.0" [target.armv7-unknown-linux-gnueabihf] linker = "armv7-unknown-linux-gnueabihf" diff --git a/entr.sh b/entr.sh index e6206b5..ac953c2 100755 --- a/entr.sh +++ b/entr.sh @@ -2,7 +2,7 @@ CMD="$(cat <<'EOF' set -euo pipefail HEIGHT="$(($(tput lines) - 1))" clear -for i in fmt build clippy; do +for i in check fmt build clippy; do echo "+ cargo "${i}"" cargo --color=always "${i}" |& head -n "${HEIGHT}" done diff --git a/html/index.html b/html/index.html new file mode 100644 index 0000000..45b983b --- /dev/null +++ b/html/index.html @@ -0,0 +1 @@ +hi diff --git a/src/main.rs b/src/main.rs index 6a76594..1e5ea51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,7 +31,9 @@ mod errors; mod pattern; mod strip; mod ui; +mod webui; use errors::ProgramError; +use std::io; use std::sync::mpsc::channel; use std::thread; use strip::{LedStrip, Message}; @@ -56,5 +58,12 @@ fn main() -> Result<(), ProgramError> { let _console_ui_handle = thread::spawn(move || -> Result<(), ProgramError> { console_ui_loop(&tx) }); + // I do not care if the web ui crashes + let _web_ui_handle = thread::spawn(move || -> Result<(), io::Error> { + webui::start() + // TODO: Do not join -- this is just because we are running on a computer with no spi env + }) + .join()?; + strip_handle.join()? } diff --git a/src/strip.rs b/src/strip.rs index 34d6656..08c211f 100644 --- a/src/strip.rs +++ b/src/strip.rs @@ -144,7 +144,6 @@ impl LedStrip { } } - // TODO: Handle error properly if self .pattern .step() diff --git a/src/webui.rs b/src/webui.rs new file mode 100644 index 0000000..8b1d5ce --- /dev/null +++ b/src/webui.rs @@ -0,0 +1,48 @@ +use actix_web::web::Form; +use actix_web::{get, post, web, App, HttpRequest, HttpServer, Responder}; +use rust_embed::RustEmbed; +use serde::Deserialize; + +// TODO: Pre-compute binary somehow? So do not have to unwrap +#[derive(RustEmbed)] +#[folder = "html/"] +struct Asset; + +struct AppState { + app_name: String, +} + +#[derive(Deserialize, Debug)] +struct ColorForm { + color: String, +} + +#[post("/setcolor")] +async fn set_color(data: web::Data, params: Form) -> impl Responder { + format!("{:?}", params) +} + +#[get("/")] +async fn test(data: web::Data, req: HttpRequest) -> impl Responder { + // TODO: This is probably the ugliest possible way to do it. Make this better + String::from_utf8((&Asset::get("index.html").unwrap().data).to_vec()).unwrap() +} + +#[actix_web::main] +pub async fn start() -> std::io::Result<()> { + println!("Starting webui"); + HttpServer::new(|| { + App::new() + .data(AppState { + app_name: String::from("abawse"), + }) + .service(test) + .service(set_color) + // App::new() + // .route("/", web::get().to(greet)) + // .route("/{name}", web::get().to(greet)) + }) + .bind(("127.0.0.1", 8080))? + .run() + .await +}