diff --git a/Cargo.lock b/Cargo.lock index e837b9d..3f3e152 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -194,6 +194,45 @@ dependencies = [ "generic-array", ] +[[package]] +name = "clap" +version = "3.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190814073e85d238f31ff738fcb0bf6910cedeb73376c87cd69291028966fd83" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "once_cell", + "strsim", + "termcolor", + "textwrap", +] + +[[package]] +name = "clap_derive" +version = "3.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "759bf187376e1afa7b85b959e6a664a3e7a95203415dba952ad19139e798f902" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "cookie" version = "0.16.0" @@ -632,6 +671,7 @@ dependencies = [ name = "ir-remote" version = "0.1.0" dependencies = [ + "clap", "env_logger", "futures", "log", @@ -862,6 +902,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "os_str_bytes" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21326818e99cfe6ce1e524c2a805c189a99b5ae555a35d19f9a284b427d86afa" + [[package]] name = "parking_lot" version = "0.12.1" @@ -950,6 +996,30 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.40" @@ -1317,6 +1387,12 @@ dependencies = [ "loom", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "strum" version = "0.24.1" @@ -1379,6 +1455,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" + [[package]] name = "thread_local" version = "1.1.4" diff --git a/Cargo.toml b/Cargo.toml index 439bc76..1d8d4ac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ futures = "0.3" strum_macros = "0.24" strum = { version = "0.24", features = ["derive"] } mime = "0.3" +clap = {version = "3", features = ["derive"]} [build-dependencies] ructe = {version = "0.14", features = ["mime03"]} diff --git a/src/ir_types.rs b/src/ir_types.rs index 2a05d5d..05c35b3 100644 --- a/src/ir_types.rs +++ b/src/ir_types.rs @@ -37,10 +37,10 @@ impl DeviceType { Function::ChannelDown => 0x10, Function::Button0 => 0x11, Function::ChannelUp => 0x12, - Function::Last => 0x13, + Function::PreviousChannel => 0x13, Function::Menu => 0x1a, Function::Info => 0x1f, - Function::AddSubtract => 0x25, + // Function::AddSubtract => 0x25, Function::Exit => 0x2d, Function::EManual => 0x3f, Function::Tools => 0x4b, @@ -54,6 +54,20 @@ impl DeviceType { Function::ChannelList => 0x6b, Function::SmartHub => 0x79, Function::Button3D => 0x9f, + + Function::Dash => 0x23, + Function::ButtonA => 0x6c, + Function::ButtonB => 0x14, + Function::ButtonC => 0x15, + Function::ButtonD => 0x16, + Function::PictureSize => 0x3e, + Function::CloseCaptioning => 0x25, + Function::Stop => 0x46, + Function::Rewind => 0x45, + Function::Play => 0x47, + Function::Pause => 0x4a, + Function::FastForward => 0x48, + Function::Search => 0x73, }, } } @@ -78,10 +92,10 @@ pub enum Function { ChannelDown, Button0, ChannelUp, - Last, + PreviousChannel, Menu, Info, - AddSubtract, + // AddSubtract, Exit, EManual, Tools, @@ -95,6 +109,20 @@ pub enum Function { ChannelList, SmartHub, Button3D, + + Dash, + ButtonA, + ButtonB, + ButtonC, + ButtonD, + PictureSize, + CloseCaptioning, + Stop, + Rewind, + Play, + Pause, + FastForward, + Search, } impl Function { @@ -117,10 +145,10 @@ impl Function { Self::ChannelDown => "Channel Down", Self::Button0 => "Button 0", Self::ChannelUp => "Channel Up", - Self::Last => "Last", + Self::PreviousChannel => "Previous Channel", Self::Menu => "Menu", Self::Info => "Info", - Self::AddSubtract => "Add Subtract", + // Self::AddSubtract => "Add Subtract", Self::Exit => "Exit", Self::EManual => "E-Manual", Self::Tools => "Tools", @@ -134,6 +162,19 @@ impl Function { Self::ChannelList => "Channel List", Self::SmartHub => "Smart Hub", Self::Button3D => "Button 3D", + Self::Dash => "-", + Self::ButtonA => "A", + Self::ButtonB => "B", + Self::ButtonC => "C", + Self::ButtonD => "D", + Self::PictureSize => "Picture Size", + Self::CloseCaptioning => "Close Captioning", + Self::Stop => "Stop", + Self::Rewind => "Rewind", + Self::Play => "Play", + Self::Pause => "Pause", + Self::FastForward => "Fast Forward", + Self::Search => "Search", } } } diff --git a/src/main.rs b/src/main.rs index 9bcdbdc..9e98f48 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,11 +2,12 @@ mod ir_types; mod serial_agent; mod webui; +use clap::Parser; use env_logger::Env; use futures::future::join_all; use ir_types::DeviceType; use ir_types::Function; -use log::{error, info}; +use log::{error, info, warn}; use std::sync::Arc; use std::time::Duration; use tokio::sync::mpsc::channel; @@ -16,30 +17,40 @@ use tokio::time; type AppResult = Result>; -// struct Options { -// // device: DeviceType, -// } +#[derive(Parser, Debug)] +struct Options { + // device: DeviceType, + #[clap(short, long, help = "Disables serial communication")] + no_serial: bool, +} #[tokio::main] async fn main() -> AppResult<()> { env_logger::Builder::from_env(Env::default().default_filter_or("info")).init(); - info!("Starting ir remote"); - // let options = Arc::new(Options { - // // device: DeviceType::Samsung, - // }); + let options = Arc::new(Options::parse()); + + info!("Starting ir remote"); let (outbound_serial_tx, outbound_serial_rx) = channel(100); let (inbound_serial_tx, inbound_serial_rx) = channel(100); - info!("Starting serial port agent"); - let agent_handle: JoinHandle> = tokio::task::spawn(async move { - serial_agent::serialport_agent(inbound_serial_tx, outbound_serial_rx).await - }); + let agent_handle: Option>> = if options.no_serial { + warn!("Not starting serial port agent (--no-serial was given)"); + + None + } else { + info!("Starting serial port agent"); + + Some(tokio::task::spawn(async move { + serial_agent::serialport_agent(inbound_serial_tx, outbound_serial_rx).await + })) + }; // TODO: Consume inbound_serial_rx, otherwise it will fill up and eventually be dropped // let (agent_shutdown_tx, agent_handle): (Sender<()>, JoinHandle>) = { + // let (shutdown_tx, shutdown_rx) = channel(1); // ( // shutdown_tx, @@ -57,7 +68,8 @@ async fn main() -> AppResult<()> { .await?; tokio::select!( - // r = agent_handle => { + // TODO: Handle the case where agent_handle is enabled or disabled + // r = agent_handle.unwrap(), if agent_handle.is_some() => { // error!("Agent handle ended: {r:?}"); // } r = webui_handle => { diff --git a/src/webui/template_responder.rs b/src/webui/template_responder.rs index b32c31b..b794d04 100644 --- a/src/webui/template_responder.rs +++ b/src/webui/template_responder.rs @@ -1,8 +1,8 @@ use super::templates::statics::StaticFile; +use log::info; use rocket::http::Header; use rocket::{http::ContentType, response, response::Responder, Request, Response}; use std::io::Cursor; -use log::info; pub struct TemplateResponder(pub Vec); diff --git a/static/remote2.svg b/static/remote2.svg index aeae532..a44407f 100644 --- a/static/remote2.svg +++ b/static/remote2.svg @@ -1,6 +1,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/index.rs.html b/templates/index.rs.html index 1dc61fb..2581600 100644 --- a/templates/index.rs.html +++ b/templates/index.rs.html @@ -6,7 +6,7 @@ - Unknown Title + IR Remote @@ -16,9 +16,9 @@ - - + + - + @@ -1033,7 +1033,7 @@ kl+J8KhFCNZFmyirVvZisdfPLEpgomBYkopyNgQ+rv8A/9k= - + @@ -1059,15 +1059,15 @@ kl+J8KhFCNZFmyirVvZisdfPLEpgomBYkopyNgQ+rv8A/9k= - + - - + + - - - - + + + +