diff --git a/.gitignore b/.gitignore index bba7b53..d642a68 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /target/ /.idea/ +/release/pipes-and-rust +/*.zip diff --git a/Cargo.lock b/Cargo.lock index 0da5e85..b2877d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -70,6 +70,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -103,7 +109,27 @@ checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "hermit-abi" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6ccf5ede3a895d8856620237b2f02972c1bbc78d2965ad7fe8838d4a0ed41f0" +dependencies = [ + "bytes", + "fnv", + "itoa", ] [[package]] @@ -132,6 +158,12 @@ dependencies = [ "libc", ] +[[package]] +name = "itoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -154,6 +186,15 @@ version = "0.2.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743" +[[package]] +name = "log" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" +dependencies = [ + "log 0.4.11", +] + [[package]] name = "log" version = "0.4.11" @@ -181,7 +222,7 @@ dependencies = [ "iovec", "kernel32-sys", "libc", - "log", + "log 0.4.11", "miow", "net2", "slab", @@ -195,7 +236,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52403fe290012ce777c4626790c8951324a2b9e3316b3143779c72b029742f19" dependencies = [ "lazycell", - "log", + "log 0.4.11", "mio", "slab", ] @@ -223,6 +264,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + [[package]] name = "opaque-debug" version = "0.2.3" @@ -239,6 +290,8 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" name = "pipes-and-rust" version = "0.1.0" dependencies = [ + "rust-embed", + "simple-server", "ws", ] @@ -248,6 +301,24 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c36fa947111f5c62a733b652544dd0016a43ce89619538a8ef92724a6f501a20" +[[package]] +name = "proc-macro2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + [[package]] name = "rand" version = "0.7.3" @@ -289,6 +360,53 @@ dependencies = [ "rand_core", ] +[[package]] +name = "rust-embed" +version = "5.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213acf1bc5a6dfcd70b62db1e9a7d06325c0e73439c312fcb8599d456d9686ee" +dependencies = [ + "rust-embed-impl", + "rust-embed-utils", + "walkdir", +] + +[[package]] +name = "rust-embed-impl" +version = "5.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7903c2cf599db8f310b392332f38367ca4acc84420fa1aee3536299f433c10d5" +dependencies = [ + "quote", + "rust-embed-utils", + "syn", + "walkdir", +] + +[[package]] +name = "rust-embed-utils" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97655158074ccb2d2cfb1ccb4c956ef0f4054e43a2c1e71146d4991e6961e105" +dependencies = [ + "walkdir", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" + [[package]] name = "sha-1" version = "0.8.2" @@ -301,12 +419,48 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "simple-server" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b47624fcb3e3416bd7f764b2319875043ce22b0eff78f5c7684de07c88ba5761" +dependencies = [ + "http", + "httparse", + "log 0.3.9", + "num_cpus", + "scoped_threadpool", + "time", +] + [[package]] name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +[[package]] +name = "syn" +version = "1.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi 0.3.9", +] + [[package]] name = "tinyvec" version = "0.3.4" @@ -337,6 +491,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + [[package]] name = "url" version = "2.1.1" @@ -348,12 +508,29 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "walkdir" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "777182bc735b6424e1a57516d35ed72cb8019d85c8c9bf536dccb3445c1a2f7d" +dependencies = [ + "same-file", + "winapi 0.3.9", + "winapi-util", +] + [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + [[package]] name = "winapi" version = "0.2.8" @@ -382,6 +559,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -397,7 +583,7 @@ dependencies = [ "byteorder", "bytes", "httparse", - "log", + "log 0.4.11", "mio", "mio-extras", "rand", diff --git a/Cargo.toml b/Cargo.toml index 5f9ccee..b1f70dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,5 @@ edition = "2018" [dependencies] ws = "0.9.1" +rust-embed = "5.6.0" +simple-server = "0.4.0" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..653576e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Simon Struck + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..e8e1768 --- /dev/null +++ b/Readme.md @@ -0,0 +1,37 @@ +# Pipes and Rust + +Draw on a html canvas directly from your reMarkable 2. + +![](images/wiriting_test_canvas.png) + +# Usage + +1. Install the software with one of the methods below. +2. Connect to http://remarkable (or device IP) +3. Done! + +# Requirements + +1. SSH access to the reMarkable for installation +2. (when building from source) Rust + +# Installation (from Binary) + +1. Download the [latest release](https://github.com/AnyTimeTraveler/pipes-and-rust/releases) +2. Set IP or hostname in `install.sh` +3. Run install.sh + +# Installation (from Source) + +1. Install [Rust](https://rustup.rs/) +2. Install [Cross](https://github.com/rust-embedded/cross) to build for armv7 +3. Set hostname in `build_push_run.sh` +4. Run `build_push_run.sh` with either 'debug' or 'release' as parameter + +# Credits + +This work is based on [pipes-and-paper](https://gitlab.com/afandian/pipes-and-paper) by Joe Wass and uses his code to read the stylus coordinates. + +# License + +MIT-License diff --git a/build_pack.sh b/build_pack.sh new file mode 100755 index 0000000..fbad243 --- /dev/null +++ b/build_pack.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env zsh + +if [ $# -ne 1 ]; then + echo "parameter 'debug' or 'release' required" + exit +fi + +build_type="$1" +arch="armv7-unknown-linux-musleabihf" +#arch="armv7-unknown-linux-gnueabihf" + +echo "Compiling..." +if [ "$build_type" = "release" ]; then + cross build --target "$arch" --release +else + cross build --target "$arch" +fi +echo "Done" + +# shellcheck disable=SC2181 +if [ $? -eq 0 ]; then + echo "Copying to directory..." + cp "./target/$arch/$build_type/pipes-and-rust" "release/pipes-and-rust" + echo "Done" +fi + +version="$(grep 'version' Cargo.toml | head -n 1 | cut -d\" -f2)" + +(cd release && zip "../pipes-and-rust-release-$version.zip" ./install.sh ./pipes-and-rust ./pipes-and-rust.service) diff --git a/build_push_run.sh b/build_push_run.sh index ad2e2e0..d75d57c 100755 --- a/build_push_run.sh +++ b/build_push_run.sh @@ -19,5 +19,5 @@ if [ $? -eq 0 ]; then ssh remarkable "killall pipes-and-rust" echo "Done" echo "Copying to device..." - scp "./target/$arch/$version/pipes-and-rust" "$host:" && echo "Done" && ssh "$host" "./pipes-and-rust" + scp "./target/$arch/$version/pipes-and-rust" "$host:/opt/pipes-and-rust" && echo "Done" && ssh "$host" "/opt/pipes-and-rust" fi diff --git a/images/wiriting_test_canvas.png b/images/wiriting_test_canvas.png new file mode 100644 index 0000000..7712493 Binary files /dev/null and b/images/wiriting_test_canvas.png differ diff --git a/release/install.sh b/release/install.sh new file mode 100755 index 0000000..9add973 --- /dev/null +++ b/release/install.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env sh + +# Set hostname or ip address of your reMarkable +host="remarkable" + + + +ssh "$host" "mkdir -p /opt/" +echo "Copying files to device..." +scp "./pipes-and-rust" "$host:/opt/pipes-and-rust" || exit +scp "./pipes-and-rust.service" "$host:/lib/systemd/system/pipes-and-rust.service" || exit +echo "Done" + +echo "Installing service..." +ssh "$host" "systemctl daemon-reload" || exit +ssh "$host" "systemctl enable pipes-and-rust.service" || exit +ssh "$host" "systemctl start pipes-and-rust.service" || exit +echo "Done" diff --git a/release/pipes-and-rust.service b/release/pipes-and-rust.service new file mode 100644 index 0000000..8cd34d6 --- /dev/null +++ b/release/pipes-and-rust.service @@ -0,0 +1,10 @@ +[Unit] +Description=pipes-and-rust +After=home.mount + +[Service] +ExecStart=/opt/pipes-and-rust +Restart=never + +[Install] +WantedBy=multi-user.target diff --git a/res/index.html b/res/index.html index 528745c..775120a 100644 --- a/res/index.html +++ b/res/index.html @@ -6,7 +6,7 @@ - +
Status:
not yet connected
@@ -16,6 +16,7 @@
+

Enter to clear screen

diff --git a/src/main.rs b/src/main.rs index 9258940..bf41f49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,28 @@ +extern crate simple_server; + use std::fs::File; use std::io::Read; use std::thread; +use rust_embed::RustEmbed; +use simple_server::Server; use ws::{listen, Message}; +#[derive(RustEmbed)] +#[folder = "res/"] +struct Asset; + fn main() { - println!("Listening..."); + let server = Server::new(|_, mut response| { + Ok(response.body(Vec::from(Asset::get("index.html").unwrap()))?) + }); + + thread::spawn(move || { + println!("Listening for http connections on port 80..."); + server.listen("0.0.0.0", "80"); + }); + + println!("Listening for websocket connections on port 55555..."); listen("0.0.0.0:55555", |out| { thread::Builder::new() .name(format!("connection_handler_{}", out.connection_id())) @@ -45,5 +62,4 @@ fn main() { Ok(()) } }).unwrap(); - println!("Ended!"); }