diff --git a/cli/src/main.rs b/cli/src/main.rs index d4dd45f..2558707 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,5 +1,6 @@ use clap::{Arg, App}; -use gvm_lights::{GvmClient, ControlMessage, LightCmd}; +use gvm_lights::{GvmClient, ControlMessage}; +use gvm_lights::codec::LightCmd; use std::str::FromStr; #[async_std::main] @@ -59,6 +60,6 @@ async fn main() -> Result<(), Box> { let client = GvmClient::new("192.168.4.2").await?; let sent_bytes = client.send_to(&"192.168.4.1", &cmd).await?; - println!("{}", sent_bytes); + println!("{:?}", sent_bytes); Ok(()) } diff --git a/gvm_lights/src/codec.rs b/gvm_lights/src/codec.rs index fbc1536..2a95797 100644 --- a/gvm_lights/src/codec.rs +++ b/gvm_lights/src/codec.rs @@ -15,7 +15,7 @@ pub enum ControlMessage { pub fn encode(msg: &ControlMessage) -> Result, Box> { let dev_id = b"00"; - let dev_type = b"30"; + let dev_type = b"20"; let (cmd, param) = match msg { ControlMessage::Light(param) => { @@ -24,27 +24,27 @@ pub fn encode(msg: &ControlMessage) -> Result, Box (b"00", b"00".to_vec()), } }, - ControlMessage::SetBrightness(*br) => { - let br = if br > 100 { 100 } - else { br }; + ControlMessage::SetBrightness(br) => { + let br = if *br > 100 { 100 } + else { *br }; (b"02", hex::encode_upper([br]).into_bytes()) }, ControlMessage::SetTemperature(t) => { - let t = if t < 3200 { 3200 } + let t = if *t < 3200 { 3200 } else { - if t > 5600 { 5600 } - else { t } + if *t > 5600 { 5600 } + else { *t } }; (b"03", hex::encode_upper([(t / 100) as u8]).into_bytes()) }, ControlMessage::SetHue(hue) => { - let hue = if hue > 360 { 360 } - else { hue }; + let hue = if *hue > 360 { 360 } + else { *hue }; (b"04", hex::encode_upper([(hue / 5) as u8]).into_bytes()) }, ControlMessage::SetSaturation(sat) => { - let sat = if sat > 100 { 100 } - else { sat }; + let sat = if *sat > 100 { 100 } + else { *sat }; (b"05", hex::encode_upper([sat]).into_bytes()) }, }; diff --git a/proxy/Cargo.lock b/proxy/Cargo.lock index ce424e4..dfa5ed6 100644 --- a/proxy/Cargo.lock +++ b/proxy/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" version = "0.7.15" @@ -35,21 +37,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "bit-set" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e1e6fb1c9e3d6fcdec57216a74eaa03e41f52a22f13a16438251d8e88b89da" -dependencies = [ - "bit-vec", -] - -[[package]] -name = "bit-vec" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" - [[package]] name = "bitflags" version = "1.2.1" @@ -64,19 +51,19 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "bluster" -version = "0.1.2" -source = "git+https://github.com/dfrankland/bluster#1931b0474ca481eb31e343cab85956c05749688b" +version = "0.1.3" +source = "git+https://github.com/dfrankland/bluster?rev=ffba9e258561d5d2e70a81f805c694456ca11dd1#ffba9e258561d5d2e70a81f805c694456ca11dd1" dependencies = [ "dbus", "dbus-crossroads", "dbus-tokio", + "dbus-tree", "futures", - "libusb", "log", "objc", "objc-foundation", "objc_id", - "tokio", + "tokio 1.13.1", "uuid", ] @@ -113,34 +100,44 @@ dependencies = [ [[package]] name = "dbus" -version = "0.8.4" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cd9e78c210146a1860f897db03412fd5091fd73100778e43ee255cca252cf32" +checksum = "1bb21987b9fb1613058ba3843121dd18b163b254d8a6e797e144cbac14d96d1b" dependencies = [ - "futures", + "futures-channel", + "futures-util", "libc", "libdbus-sys", + "winapi 0.3.9", ] [[package]] name = "dbus-crossroads" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f560f694d441fe319e71bb2042dc13b12cdbca093a7660bd4d4a69e019542189" +checksum = "0a816e8ae3382c7b1bccfa6f2778346ee5b13f80e0eccf80cf8f2912af73995a" dependencies = [ "dbus", ] [[package]] name = "dbus-tokio" -version = "0.5.2" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baaf99ea9b8296ba0db293cad28c51d788e690c47ebe9974b864354b258a636a" +checksum = "007688d459bc677131c063a3a77fb899526e17b7980f390b69644bdbc41fad13" dependencies = [ "dbus", "libc", - "mio", - "tokio", + "tokio 1.13.1", +] + +[[package]] +name = "dbus-tree" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f456e698ae8e54575e19ddb1f9b7bce2298568524f215496b248eb9498b4f508" +dependencies = [ + "dbus", ] [[package]] @@ -324,34 +321,13 @@ checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" [[package]] name = "libdbus-sys" -version = "0.2.1" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc12a3bc971424edbbf7edaf6e5740483444db63aa8e23d3751ff12a30f306f0" +checksum = "06085512b750d640299b79be4bad3d2fa90a9c00b1fd9e1b46364f66f0485c72" dependencies = [ "pkg-config", ] -[[package]] -name = "libusb" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f990ddd929cbe53de4ecd6cf26e1f4e0c5b9796e4c629d9046570b03738aa53" -dependencies = [ - "bit-set", - "libc", - "libusb-sys", -] - -[[package]] -name = "libusb-sys" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c53b6582563d64ad3e692f54ef95239c3ea8069e82c9eb70ca948869a7ad767" -dependencies = [ - "libc", - "pkg-config", -] - [[package]] name = "log" version = "0.4.11" @@ -395,6 +371,19 @@ dependencies = [ "winapi 0.2.8", ] +[[package]] +name = "mio" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7" +dependencies = [ + "libc", + "log", + "miow 0.3.6", + "ntapi", + "winapi 0.3.9", +] + [[package]] name = "mio-named-pipes" version = "0.1.7" @@ -402,7 +391,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0840c1c50fd55e521b247f949c241c9997709f23bd7f023b9762cd561e935656" dependencies = [ "log", - "mio", + "mio 0.6.23", "miow 0.3.6", "winapi 0.3.9", ] @@ -415,7 +404,7 @@ checksum = "afcb699eb26d4332647cc848492bbc15eafb26f08d0304550d5aa1f612e066f0" dependencies = [ "iovec", "libc", - "mio", + "mio 0.6.23", ] [[package]] @@ -451,6 +440,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "ntapi" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "num-integer" version = "0.1.44" @@ -599,7 +597,7 @@ dependencies = [ "bluster", "futures", "pretty_env_logger", - "tokio", + "tokio 0.2.24", "uuid", ] @@ -715,18 +713,32 @@ dependencies = [ "lazy_static", "libc", "memchr", - "mio", + "mio 0.6.23", "mio-named-pipes", "mio-uds", "num_cpus", "pin-project-lite 0.1.11", "signal-hook-registry", "slab", - "tokio-macros", + "tokio-macros 0.2.6", "tracing", "winapi 0.3.9", ] +[[package]] +name = "tokio" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52963f91310c08d91cb7bff5786dfc8b79642ab839e188187e92105dbfb9d2c8" +dependencies = [ + "autocfg", + "libc", + "mio 0.7.7", + "pin-project-lite 0.2.0", + "tokio-macros 1.1.0", + "winapi 0.3.9", +] + [[package]] name = "tokio-macros" version = "0.2.6" @@ -738,6 +750,17 @@ dependencies = [ "syn", ] +[[package]] +name = "tokio-macros" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caf7b11a536f46a809a8a9f0bb4237020f70ecbf115b842360afb127ea2fda57" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing" version = "0.1.22" diff --git a/proxy/Cargo.toml b/proxy/Cargo.toml index 6d5ceb8..7ecdbb2 100644 --- a/proxy/Cargo.toml +++ b/proxy/Cargo.toml @@ -9,6 +9,6 @@ edition = "2018" [dependencies] tokio = { version = "0.2.23", features = ["full", "tracing"] } futures = "0.3" -bluster = { git = "https://github.com/dfrankland/bluster" } +bluster = { git = "https://github.com/dfrankland/bluster", rev = "ffba9e258561d5d2e70a81f805c694456ca11dd1" } uuid = "0.8.1" pretty_env_logger = "0.2"