Start work on webui
This commit is contained in:
parent
0b03474308
commit
09ac4e37fd
10
Cargo.toml
10
Cargo.toml
@ -1,17 +1,15 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "aw-lights"
|
name = "aw-lights"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["root"]
|
authors = ["Austen Adler <agadler@austenadler.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rppal = "0.7"
|
rppal = "0.7"
|
||||||
ws2818-rgb-led-spi-driver = { path = "lib-ws2818-rgb-led-spi-driver/" }
|
ws2818-rgb-led-spi-driver = { path = "lib-ws2818-rgb-led-spi-driver/" }
|
||||||
# ws2818-rgb-led-spi-driver = { path = "ws2818-rgb-led-spi-driver/" }
|
serde = {version = "1.0", features = ["derive"]}
|
||||||
# ws2818-rgb-led-spi-driver = { path = "/home/pi/tt/" }
|
actix-web = {version = "3", default_features = false}
|
||||||
# ws2818-rgb-led-spi-driver = { path = "/home/pi/ws2818-rgb-led-spi-driver/" }
|
rust-embed="6.0.0"
|
||||||
|
|
||||||
[target.armv7-unknown-linux-gnueabihf]
|
[target.armv7-unknown-linux-gnueabihf]
|
||||||
linker = "armv7-unknown-linux-gnueabihf"
|
linker = "armv7-unknown-linux-gnueabihf"
|
||||||
|
2
entr.sh
2
entr.sh
@ -2,7 +2,7 @@ CMD="$(cat <<'EOF'
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
HEIGHT="$(($(tput lines) - 1))"
|
HEIGHT="$(($(tput lines) - 1))"
|
||||||
clear
|
clear
|
||||||
for i in fmt build clippy; do
|
for i in check fmt build clippy; do
|
||||||
echo "+ cargo "${i}""
|
echo "+ cargo "${i}""
|
||||||
cargo --color=always "${i}" |& head -n "${HEIGHT}"
|
cargo --color=always "${i}" |& head -n "${HEIGHT}"
|
||||||
done
|
done
|
||||||
|
1
html/index.html
Normal file
1
html/index.html
Normal file
@ -0,0 +1 @@
|
|||||||
|
hi
|
@ -31,7 +31,9 @@ mod errors;
|
|||||||
mod pattern;
|
mod pattern;
|
||||||
mod strip;
|
mod strip;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
mod webui;
|
||||||
use errors::ProgramError;
|
use errors::ProgramError;
|
||||||
|
use std::io;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use strip::{LedStrip, Message};
|
use strip::{LedStrip, Message};
|
||||||
@ -56,5 +58,12 @@ fn main() -> Result<(), ProgramError> {
|
|||||||
let _console_ui_handle =
|
let _console_ui_handle =
|
||||||
thread::spawn(move || -> Result<(), ProgramError> { console_ui_loop(&tx) });
|
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()?
|
strip_handle.join()?
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,6 @@ impl LedStrip {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Handle error properly
|
|
||||||
if self
|
if self
|
||||||
.pattern
|
.pattern
|
||||||
.step()
|
.step()
|
||||||
|
48
src/webui.rs
Normal file
48
src/webui.rs
Normal file
@ -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<AppState>, params: Form<ColorForm>) -> impl Responder {
|
||||||
|
format!("{:?}", params)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
async fn test(data: web::Data<AppState>, 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user