From 2a79d71b3959f4ba0646d7d3bac7ab93fb01f554 Mon Sep 17 00:00:00 2001 From: Jackson Date: Sun, 28 Jun 2020 16:58:56 -0600 Subject: [PATCH] Run clippy again --- Cargo.lock | 147 ++++++- Cargo.toml | 7 +- Makefile.toml | 20 + resources/systemd_files/desktopper.service | 12 + .../systemd_files/desktopper_display.service | 13 + resources/systemd_files/task_api.service | 12 + resources/target_deploy.sh | 7 + src/bin/api_server.rs | 6 +- src/bin/desktopper.rs | 388 ++++++++++++++++++ src/tasks.rs | 8 +- 10 files changed, 596 insertions(+), 24 deletions(-) create mode 100644 Makefile.toml create mode 100644 resources/systemd_files/desktopper.service create mode 100644 resources/systemd_files/desktopper_display.service create mode 100644 resources/systemd_files/task_api.service create mode 100644 resources/target_deploy.sh create mode 100644 src/bin/desktopper.rs diff --git a/Cargo.lock b/Cargo.lock index 216633e..e04887b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,19 @@ dependencies = [ "memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "anyhow" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "arc-swap" version = "0.4.6" @@ -126,6 +139,20 @@ dependencies = [ "time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "clap" +version = "2.33.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -158,6 +185,29 @@ dependencies = [ "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "desktopper" +version = "0.1.0" +dependencies = [ + "anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)", + "gpio-cdev 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "gpio_lcd 0.1.0 (git+https://github.com/jrmo14/gpio_lcd)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.56 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pretty_env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "reqwest 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", + "signal-hook 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "warp 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "digest" version = "0.8.1" @@ -342,6 +392,25 @@ dependencies = [ "wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "gpio-cdev" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "gpio_lcd" +version = "0.1.0" +source = "git+https://github.com/jrmo14/gpio_lcd#155aa96be60c02a87849c0daae0d1113339c3f0c" +dependencies = [ + "gpio-cdev 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "h2" version = "0.2.5" @@ -699,6 +768,30 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "nix" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "nix" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.70 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num-integer" version = "0.1.42" @@ -1319,6 +1412,11 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "syn" version = "1.0.23" @@ -1350,6 +1448,14 @@ dependencies = [ "winapi-util 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "thread_local" version = "1.0.1" @@ -1553,6 +1659,11 @@ dependencies = [ "smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "unicode-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unicode-xid" version = "0.2.0" @@ -1592,6 +1703,11 @@ name = "vcpkg" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "version_check" version = "0.1.5" @@ -1603,22 +1719,9 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "wall_disp" -version = "0.1.0" -dependencies = [ - "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.56 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "pretty_env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "reqwest 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.53 (registry+https://github.com/rust-lang/crates.io-index)", - "signal-hook 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", - "uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "warp 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] +name = "void" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "want" @@ -1786,6 +1889,8 @@ dependencies = [ [metadata] "checksum aho-corasick 0.7.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8716408b8bc624ed7f65d223ddb9ac2d044c0547b6fa4b0d554f3a9540496ada" +"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum anyhow 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f" "checksum arc-swap 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b585a98a234c46fc563103e9278c9391fde1f4e6850334da895d27edb9580f62" "checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" "checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" @@ -1804,6 +1909,7 @@ dependencies = [ "checksum cc 1.0.54 (registry+https://github.com/rust-lang/crates.io-index)" = "7bbb73db36c1246e9034e307d0fba23f9a2e251faa47ade70c1bd252220c8311" "checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" "checksum chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "80094f509cf8b5ae86a4966a39b3ff66cd7e2a3e594accec3743ff3fabeab5b2" +"checksum clap 2.33.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bdfa80d47f954d53a35a64987ca1422f495b8d6483c0fe9f7117b36c2a792129" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum core-foundation 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" "checksum core-foundation-sys 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" @@ -1831,6 +1937,8 @@ dependencies = [ "checksum futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" +"checksum gpio-cdev 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1919e3c3b51096c4e63948ab480f233ea475665753d00c65b13e7269acc42ab" +"checksum gpio_lcd 0.1.0 (git+https://github.com/jrmo14/gpio_lcd)" = "" "checksum h2 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "79b7246d7e4b979c03fa093da39cfb3617a96bbeee6310af63991668d7e843ff" "checksum headers 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ed18eb2459bf1a09ad2d6b1547840c3e5e62882fa09b9a6a20b1de8e3228848f" "checksum headers-core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" @@ -1868,6 +1976,8 @@ dependencies = [ "checksum multipart 0.16.1 (registry+https://github.com/rust-lang/crates.io-index)" = "136eed74cadb9edd2651ffba732b19a450316b680e4f48d6c79e905799e19d01" "checksum native-tls 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2b0d88c06fe90d5ee94048ba40409ef1d9315d86f6f38c2efdaad4fb50c58b2d" "checksum net2 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)" = "2ba7c918ac76704fb42afcbbb43891e72731f3dcca3bef2a19786297baf14af7" +"checksum nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce" +"checksum nix 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50e4785f2c3b7589a0d0c1dd60285e1188adac4006e8abd6dd578e1567027363" "checksum num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba" "checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096" "checksum num_cpus 1.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" @@ -1940,9 +2050,11 @@ dependencies = [ "checksum smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b0758c52e15a8b5e3691eae6cc559f08eee9406e548a4477ba4e67770a82b6" "checksum smallvec 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" "checksum socket2 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "03088793f677dce356f3ccc2edb1b314ad191ab702a5de3faf49304f7e104918" +"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum syn 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)" = "95b5f192649e48a5302a13f2feb224df883b98933222369e4b3b0fe2a5447269" "checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" "checksum termcolor 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f" +"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" "checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" "checksum time 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" "checksum tokio 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)" = "d099fa27b9702bed751524694adbe393e18b36b204da91eb1cbbbbb4a5ee2d58" @@ -1963,14 +2075,17 @@ dependencies = [ "checksum unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5479532badd04e128284890390c1e876ef7a993d0570b3597ae43dfa1d59afa4" +"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum url 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829d4a8476c35c9bf0bbce5a3b23f4106f79728039b726d292bb93bc106787cb" "checksum urlencoding 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3df3561629a8bb4c57e5a2e4c43348d9e29c7c29d9b1c4c1f47166deca8f37ed" "checksum utf-8 0.7.5 (registry+https://github.com/rust-lang/crates.io-index)" = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" "checksum uuid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9fde2f6a4bea1d6e007c4ad38c6839fa71cbb63b6dbf5b595aa38dc9b1093c11" "checksum vcpkg 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3fc439f2794e98976c88a2a2dafce96b930fe8010b0a256b3c2199a773933168" +"checksum vec_map 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce" +"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum want 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" "checksum warp 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0e95175b7a927258ecbb816bdada3cc469cb68593e7940b96a60f4af366a9970" "checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" diff --git a/Cargo.toml b/Cargo.toml index 75937cc..bec5435 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "wall_disp" +name = "desktopper" version = "0.1.0" authors = ["Jackson "] edition = "2018" @@ -19,6 +19,11 @@ log = "^0.4" pretty_env_logger = "^0.4" signal-hook = {version = "0.1.15", features = ["tokio-support"]} openssl-sys = "*" +gpio_lcd = {git = "https://github.com/jrmo14/gpio_lcd"} +clap = "2.33.1" +gpio-cdev = "0.3.0" +nix = "0.17.0" +anyhow = "1.0.31" [features] vendored = ["openssl-sys/vendored"] diff --git a/Makefile.toml b/Makefile.toml new file mode 100644 index 0000000..65a749b --- /dev/null +++ b/Makefile.toml @@ -0,0 +1,20 @@ +# TODO Change to release +[tasks.build_pi] +description = "Build the project for the raspberry pi" +command = "cargo" +args = ["build", "--target=armv7-unknown-linux-gnueabihf", "--features=vendored"] + +[tasks.deploy] +description = "Deploys the project to the raspberry pi" +dependencies = ["build_pi"] +script = [ + "echo Creating Zip File", + "zip -r desktopper.zip resources/ target/armv7-unknown-linux-gnueabihf/debug/desktopper target/armv7-unknown-linux-gnueabihf/debug/api_server", + "echo Copying zip file", + "scp desktopper.zip pi@desktopper:~/", + "echo Installing on target", + "ssh pi@desktopper \"unzip desktopper.zip -d desktopper;cd desktopper/resources; chmod +x target_deploy.sh; sudo ./target_deploy.sh; cd ~; rm -rf desktopper*\"", + "echo Cleaning up", + "rm -f desktopper.zip" +] + diff --git a/resources/systemd_files/desktopper.service b/resources/systemd_files/desktopper.service new file mode 100644 index 0000000..58e245b --- /dev/null +++ b/resources/systemd_files/desktopper.service @@ -0,0 +1,12 @@ +[Unit] +Description=Desktop Task monitor/display + +[Service] +# The dummy program will exit +Type=oneshot +ExecStart=/bin/true +# Keep this around after the dummy exits +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/resources/systemd_files/desktopper_display.service b/resources/systemd_files/desktopper_display.service new file mode 100644 index 0000000..d4f1bfc --- /dev/null +++ b/resources/systemd_files/desktopper_display.service @@ -0,0 +1,13 @@ +[Unit] +Description=Display and interaction controller for Desktopper +PartOf=desktopper.service +After=desktopper.service +After=task_api.service + +[Service] +ExecStart=/usr/local/bin/desktopper --rs 14 --enable 15 --data_pins 6 13 19 26 255 255 255 255 -f --cycle_button 17 --mode_button 27 --fn_button_0 22 --fn_button_1 23 --fn_button_2 24 +Restart=on-failure + +[Install] +WantedBy=desktopper.service + diff --git a/resources/systemd_files/task_api.service b/resources/systemd_files/task_api.service new file mode 100644 index 0000000..ea7278a --- /dev/null +++ b/resources/systemd_files/task_api.service @@ -0,0 +1,12 @@ +[Unit] +Description=Webserver hosting task api +PartOf=desktopper.service +After=desktopper.service + +[Service] +# Start the component +ExecStart=/usr/local/bin/api_server +Restart=on-failure + +[Install] +WantedBy=desktopper.service \ No newline at end of file diff --git a/resources/target_deploy.sh b/resources/target_deploy.sh new file mode 100644 index 0000000..a807cd4 --- /dev/null +++ b/resources/target_deploy.sh @@ -0,0 +1,7 @@ +BIN_DIR=../target/armv7-unknown-linux-gnueabihf/debug +mv systemd_files/* /etc/systemd/system/ +mv $BIN_DIR/api_server /usr/local/bin/ +mv $BIN_DIR/desktopper /usr/local/bin/ +systemctl daemon-reload +systemctl enable desktopper task_api desktopper_display +systemctl start desktopper diff --git a/src/bin/api_server.rs b/src/bin/api_server.rs index b5e2705..568897e 100644 --- a/src/bin/api_server.rs +++ b/src/bin/api_server.rs @@ -43,7 +43,7 @@ mod data_model { use parking_lot::RwLock; - use wall_disp::tasks::ToDo; + use desktopper::tasks::ToDo; #[derive(Clone)] pub struct DataStore { @@ -69,7 +69,7 @@ mod filters { use warp::Filter; use crate::{handlers, DataStore}; - use wall_disp::tasks::{Priority, Task}; + use desktopper::tasks::{Priority, Task}; pub fn task_master( storage: DataStore, @@ -242,8 +242,8 @@ mod handlers { use crate::data_model::DataStore; use crate::SAVE_FILE_PATH; use chrono::{DateTime, Local}; + use desktopper::tasks::{CompletionStatus, EstTime, FlattenTasks, Priority, Task}; use std::ops::Deref; - use wall_disp::tasks::{CompletionStatus, EstTime, FlattenTasks, Priority, Task}; pub async fn add_task( uuid: Option, diff --git a/src/bin/desktopper.rs b/src/bin/desktopper.rs new file mode 100644 index 0000000..e8d15f2 --- /dev/null +++ b/src/bin/desktopper.rs @@ -0,0 +1,388 @@ +#[macro_use] +extern crate log; +extern crate pretty_env_logger; +#[macro_use] +extern crate anyhow; + +use clap::{App, Arg}; +use desktopper::tasks::*; +use gpio_cdev::*; +use gpio_lcd::lcd::LcdDriver; +use gpio_lcd::scheduler::{Job, ThreadedLcd}; +use nix::poll::{poll, PollFd, PollFlags}; +use reqwest::blocking::Client; +use std::os::unix::io::AsRawFd; +use std::str::FromStr; +use std::time::Duration; +use uuid::Uuid; + +struct State { + displays: Vec>, + idx: usize, +} + +impl State { + pub fn new() -> Self { + State { + displays: Vec::new(), + idx: 0, + } + } +} + +trait Display { + fn first_load(&mut self, lcd: &mut ThreadedLcd); + fn update_display( + &mut self, + lcd: &mut ThreadedLcd, + cycle_btn: bool, + btn_0: bool, + btn_1: bool, + btn_2: bool, + ); +} + +struct TaskDisplay { + client: Client, + cur_id: Option, + idx: usize, + tasks: Vec, + api_root: String, +} + +impl TaskDisplay { + pub fn new(api_host: &str, api_port: &str) -> Self { + let client = Client::new(); + let api_root = format!("http://{}:{}", api_host, api_port); + let url = format!("{}/todo/get", &api_root); + let resp_str = client.get(&url).send().unwrap().text().unwrap(); + let tasks = serde_json::from_str(&resp_str).unwrap(); + TaskDisplay { + client, + cur_id: None, + idx: 0, + tasks, + api_root, + } + } + pub fn update_tasks(&mut self) { + let url = format!( + "{}/todo/get/{}", + &self.api_root, + match self.cur_id { + Some(id) => format!("?id={}", id), + None => String::new(), + } + ); + let resp = self.client.get(&url).send().unwrap().text().unwrap(); + self.tasks = serde_json::from_str(&resp).unwrap(); + } +} + +impl Display for TaskDisplay { + fn first_load(&mut self, lcd: &mut ThreadedLcd) { + lcd.clear_jobs(); + self.update_tasks(); + if !self.tasks.is_empty() { + let top = self.tasks[self.idx].get_name(); + let bottom = self.tasks[self.idx].get_desc(); + lcd.clear_jobs(); + lcd.add_job(Job::new(top.as_str(), 0, Some(Duration::from_millis(250)))); + lcd.add_job(Job::new( + bottom.as_str(), + 1, + Some(Duration::from_millis(250)), + )); + } + } + + fn update_display( + &mut self, + lcd: &mut ThreadedLcd, + cycle_btn: bool, + _btn_0: bool, + _btn_1: bool, + _btn_2: bool, + ) { + if cycle_btn { + self.idx = (self.idx + 1) % self.tasks.len(); + let top = self.tasks[self.idx].get_name(); + let bottom = self.tasks[self.idx].get_desc(); + lcd.clear_jobs(); + lcd.add_job(Job::new(top.as_str(), 0, Some(Duration::from_millis(250)))); + lcd.add_job(Job::new( + bottom.as_str(), + 1, + Some(Duration::from_millis(250)), + )); + } + } +} + +struct TestDisplay {} + +impl Display for TestDisplay { + fn first_load(&mut self, lcd: &mut ThreadedLcd) { + lcd.clear_jobs(); + lcd.clear_row(0); + lcd.clear_row(1); + lcd.add_job(Job::new("HELLO", 0, None)); + } + + fn update_display( + &mut self, + lcd: &mut ThreadedLcd, + _cycle_btn: bool, + _btn_0: bool, + _btn_1: bool, + _btn_2: bool, + ) { + self.first_load(lcd) + } +} + +fn main() -> anyhow::Result<()> { + pretty_env_logger::init(); + let matches = App::new("Desktopper") + .arg( + Arg::with_name("api_host") + .short("a") + .long("api_host") + .value_name("API_HOST") + .default_value("localhost") + .takes_value(true), + ) + .arg( + Arg::with_name("api_port") + .short("p") + .long("api_port") + .long("API_PORT") + .default_value("3030") + .takes_value(true), + ) + .arg( + Arg::with_name("chip") + .short("c") + .long("chip") + .value_name("CHIP") + .help("Sets the chip to use for GPIO") + .default_value("/dev/gpiochip0") + .takes_value(true), + ) + .arg( + Arg::with_name("four_bit_mode") + .short("f") + .long("mode") + .help("Sets the bit mode for the LCD panel") + .takes_value(false), + ) + .arg( + Arg::with_name("rs") + .long("rs") + .value_name("RS_PIN") + .help("The pin to use for rs") + .takes_value(true) + .required(true), + ) + .arg( + Arg::with_name("rw") + .long("rw") + .value_name("RW_PIN") + .help("The pin to use for rw") + .default_value("255") + .takes_value(true), + ) + .arg( + Arg::with_name("enable") + .short("e") + .long("enable") + .value_name("ENABLE_PIN") + .help("The pin to use for enable") + .takes_value(true) + .required(true), + ) + .arg( + Arg::with_name("data_pins") + .short("d") + .long("data_pins") + .value_name("DATA_PINS") + .help("The 4/8 data pins") + .multiple(true) + .required(true), + ) + .arg( + Arg::with_name("mode_button") + .short("m") + .long("mode_button") + .value_name("MODE_PIN") + .help("The pin to change/reset the mode of the system") + .required(true), + ) + .arg( + Arg::with_name("cycle_button") + .long("cycle_button") + .value_name("CYCLE_PIN") + .help("The pin to cycle values in the system") + .required(true), + ) + .arg( + Arg::with_name("fn_button_0") + .long("fn_button_0") + .value_name("BUTTON_0") + .help("THe pin to use a function button 0") + .required(true), + ) + .arg( + Arg::with_name("fn_button_1") + .long("fn_button_1") + .value_name("BUTTON_1") + .help("THe pin to use a function button 1") + .required(true), + ) + .arg( + Arg::with_name("fn_button_2") + .long("fn_button_2") + .value_name("BUTTON_2") + .help("THe pin to use a function button 2") + .required(true), + ) + .get_matches(); + + let mut chip = Chip::new(matches.value_of("chip").unwrap())?; + + let data_pins_res: Vec> = matches + .values_of("data_pins") + .unwrap() + .map(|p| u8::from_str(p)) + .collect(); + + let mut data_pins = Vec::new(); + + if data_pins_res.len() != 8 && data_pins_res.iter().any(|res| res.is_err()) { + return Err(anyhow!("Invalid number of data_pins, must be 4 or 8")); + } + data_pins_res.iter().for_each(|pin_res| { + data_pins.push(pin_res.as_ref().unwrap()); + }); + + let lcd_driver = LcdDriver::new( + 16, + 2, + matches.value_of("chip").unwrap(), + true, + u8::from_str(matches.value_of("rs").unwrap()).unwrap(), + u8::from_str(matches.value_of("rw").unwrap()).unwrap(), + u8::from_str(matches.value_of("enable").unwrap()).unwrap(), + *data_pins[0], + *data_pins[1], + *data_pins[2], + *data_pins[3], + *data_pins[4], + *data_pins[5], + *data_pins[6], + *data_pins[7], + )?; + + let mut scheduled_lcd = ThreadedLcd::with_driver(lcd_driver); + + let mut button_fds = Vec::new(); + let mut event_handles = Vec::new(); + + create_poll_fd( + &mut chip, + u32::from_str(matches.value_of("mode_button").unwrap()).unwrap(), + &mut button_fds, + &mut event_handles, + ); + + create_poll_fd( + &mut chip, + u32::from_str(matches.value_of("cycle_button").unwrap()).unwrap(), + &mut button_fds, + &mut event_handles, + ); + + create_poll_fd( + &mut chip, + u32::from_str(matches.value_of("fn_button_0").unwrap()).unwrap(), + &mut button_fds, + &mut event_handles, + ); + + create_poll_fd( + &mut chip, + u32::from_str(matches.value_of("fn_button_1").unwrap()).unwrap(), + &mut button_fds, + &mut event_handles, + ); + + create_poll_fd( + &mut chip, + u32::from_str(matches.value_of("fn_button_2").unwrap()).unwrap(), + &mut button_fds, + &mut event_handles, + ); + + let mut state = State::new(); + state.displays.push(Box::new(TaskDisplay::new( + matches.value_of("api_host").unwrap(), + matches.value_of("api_port").unwrap(), + ))); + state.displays.push(Box::new(TestDisplay {})); + // TODO Add debouncing somehow + loop { + if poll(&mut button_fds, -1)? == 0 { + println!("Timeout?!?!?"); + } else { + for i in 0..button_fds.len() { + if let Some(revts) = button_fds[i].revents() { + let h = &mut event_handles[i]; + if revts.contains(PollFlags::POLLIN) { + let event = h.get_event()?; + let offset = h.line().offset(); + if offset == 27 { + info!("Changing display"); + state.idx = (state.idx + 1) % state.displays.len(); + state.displays[state.idx].first_load(&mut scheduled_lcd) + } else { + info!("Updating display state"); + let cycle_state = + event.event_type() == EventType::FallingEdge && offset == 27; + state.displays[state.idx].update_display( + &mut scheduled_lcd, + cycle_state, + false, + false, + false, + ); + } + } else if revts.contains(PollFlags::POLLPRI) { + println!("[{}] Got a POLLPRI", h.line().offset()); + } + } + } + } + } +} + +fn create_poll_fd( + chip: &mut Chip, + line_offset: u32, + button_fds: &mut Vec, + event_handles: &mut Vec, +) { + let line_handle = chip + .get_line(line_offset) + .unwrap() + .events( + LineRequestFlags::INPUT, + EventRequestFlags::BOTH_EDGES, + "desktopper", + ) + .unwrap(); + button_fds.push(PollFd::new( + (&line_handle).as_raw_fd(), + PollFlags::POLLIN | PollFlags::POLLPRI, + )); + event_handles.push(line_handle); +} diff --git a/src/tasks.rs b/src/tasks.rs index 7a7f2a3..34628a7 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -77,12 +77,12 @@ impl ToDo { parent.add_task(task.clone()); debug!("Parent: {:?}", parent); let mut new_path = path.clone(); - new_path.push(task.uuid.clone()); - self.paths.insert(task.uuid.clone(), new_path); + new_path.push(task.uuid); + self.paths.insert(task.uuid, new_path); } None => { - self.tasks.insert(task.uuid.clone(), Box::new(task.clone())); - self.paths.insert(task.uuid.clone(), vec![task.uuid]); + self.tasks.insert(task.uuid, Box::new(task.clone())); + self.paths.insert(task.uuid, vec![task.uuid]); } } debug!("{:?}", self);