From bb652d6a4b9ab01043846e2c7e69894a6d839897 Mon Sep 17 00:00:00 2001
From: Jonathan Krebs <jonathan.krebs@bruckbu.de>
Date: Sun, 4 Apr 2021 13:54:24 +0200
Subject: [PATCH 1/4] Makefile fuer tipa

---
 .cargo/config |  5 -----
 Makefile      | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 5 deletions(-)
 delete mode 100644 .cargo/config
 create mode 100644 Makefile

diff --git a/.cargo/config b/.cargo/config
deleted file mode 100644
index 6c01b3b..0000000
--- a/.cargo/config
+++ /dev/null
@@ -1,5 +0,0 @@
-[build]
-# Set the default --target flag
-target = "armv7-unknown-linux-gnueabihf"
-
-
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..aab2e14
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,32 @@
+TARGET ?= armv7-unknown-linux-gnueabihf
+STRIP = arm-linux-gnueabihf-strip
+#PROFILE ?= release
+
+SSH_HOST ?= remarkable
+
+.PHONY: release bloat debug
+
+debug: target/$(TARGET)/debug/tipa
+
+release: target/$(TARGET)/release/tipa
+
+remotedebug: target/$(TARGET)/debug/tipa
+	scp $< $(SSH_HOST):
+	ssh  $(SSH_HOST) -L 1234:127.0.0.1:1234 ./gdbserver 127.0.0.1:1234 $(basename $<) &
+	gdb-multiarch -ex 'target remote localhost:1234'
+	
+
+target/$(TARGET)/release/%:
+	cross build --target $(TARGET) --release --bin $*
+	#$(STRIP) target/$(TARGET)/$(PROFILE)/tipa
+	#ls -lh target/$(TARGET)/$(PROFILE)/tipa
+
+target/$(TARGET)/debug/%:
+	cross build --target $(TARGET) --bin $*
+
+
+bloat: # TODO: cross compile
+	cargo clean
+	cargo bloat --$(PROFILE) --bin tipa
+	strip target/$(PROFILE)/tipa
+	ls -lh target/$(PROFILE)/tipa
-- 
GitLab


From e85d7db33de953236c99d8076bd67bbe3f89d86b Mon Sep 17 00:00:00 2001
From: Jonathan Krebs <jonathan.krebs@bruckbu.de>
Date: Sun, 4 Apr 2021 17:58:56 +0200
Subject: [PATCH 2/4] obvious fix for Cargo.toml

---
 Cargo.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Cargo.toml b/Cargo.toml
index c97e1d5..a34b2f2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
 [package]
 name = "rm2canvas"
 version = "0.1.0"
-authors = ["Florian Unger <florian.unger@posteo.net>"]
+authors = ["Florian Unger <florian.unger@posteo.net>", "Jonathan Krebs <jonathan.krebs@rm2canvas-2020.bruckbu.de>"]
 edition = "2018"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-- 
GitLab


From b0b0550232e05b3dac51c3dc1980279c1e4dd34d Mon Sep 17 00:00:00 2001
From: Jonathan Krebs <jonathan.krebs@bruckbu.de>
Date: Sun, 4 Apr 2021 18:26:03 +0200
Subject: [PATCH 3/4] makefile for quick build, install, remote debug

---
 .gitignore |  3 +++
 Makefile   | 31 ++++++++++++++++++-------------
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/.gitignore b/.gitignore
index 992c4be..99d8631 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
 /target
 *.swp
 Cargo.lock
+*.debug
+*.release
+.gdb*
diff --git a/Makefile b/Makefile
index aab2e14..0b75561 100644
--- a/Makefile
+++ b/Makefile
@@ -4,29 +4,34 @@ STRIP = arm-linux-gnueabihf-strip
 
 SSH_HOST ?= remarkable
 
-.PHONY: release bloat debug
+.PHONY: clean all
 
-debug: target/$(TARGET)/debug/tipa
+all: tipa.debug screenshot.release
 
-release: target/$(TARGET)/release/tipa
+clean:
+	rm -rf target *.release *.debug Cargo.lock
 
-remotedebug: target/$(TARGET)/debug/tipa
+%.release: target/$(TARGET)/release/%
+	cp --reflink=auto $< $@
+	$(STRIP) $@
+
+%.debug: target/$(TARGET)/debug/%
+	cp --reflink=auto $< $@
+
+%.remotedebug: %.debug
 	scp $< $(SSH_HOST):
 	ssh  $(SSH_HOST) -L 1234:127.0.0.1:1234 ./gdbserver 127.0.0.1:1234 $(basename $<) &
 	gdb-multiarch -ex 'target remote localhost:1234'
-	
 
-target/$(TARGET)/release/%:
+%.install: %.release
+	scp $< $(SSH_HOST):
+
+target/$(TARGET)/release/%: FORCE
 	cross build --target $(TARGET) --release --bin $*
 	#$(STRIP) target/$(TARGET)/$(PROFILE)/tipa
 	#ls -lh target/$(TARGET)/$(PROFILE)/tipa
 
-target/$(TARGET)/debug/%:
+target/$(TARGET)/debug/%: FORCE
 	cross build --target $(TARGET) --bin $*
 
-
-bloat: # TODO: cross compile
-	cargo clean
-	cargo bloat --$(PROFILE) --bin tipa
-	strip target/$(PROFILE)/tipa
-	ls -lh target/$(PROFILE)/tipa
+FORCE:
-- 
GitLab


From e9a2989c7f4537852057faf9f78595e6ed017dd6 Mon Sep 17 00:00:00 2001
From: Jonathan Krebs <jonathan.krebs@bruckbu.de>
Date: Sun, 4 Apr 2021 20:55:57 +0200
Subject: [PATCH 4/4] replace blocking reads in event reader with .await

---
 src/tipa.rs | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/tipa.rs b/src/tipa.rs
index 0882a18..ec13b1f 100644
--- a/src/tipa.rs
+++ b/src/tipa.rs
@@ -1,5 +1,5 @@
-use std::io::BufReader;
-use std::fs::File;
+use tokio::io::AsyncReadExt;
+use tokio::fs::File;
 
 use structure::{structure, structure_impl};
 
@@ -25,8 +25,7 @@ const MAX_PRESSURE:u32 = 4095;
 fn input_stream_parser() -> impl Stream<Item = std::io::Result<CanvasInputEvent>> {
     let mut state = ParserState{x:0, y:0, pressure:0, tool:2};
     try_stream! {
-        let f = File::open("/dev/input/event1")?;
-        let mut reader = BufReader::with_capacity(16, f);
+        let mut f = File::open("/dev/input/event1").await?;
 
         loop {
             // See https://github.com/canselcik/libremarkable/wiki/Reading-from-Wacom-I2C-Digitizer
@@ -36,7 +35,9 @@ fn input_stream_parser() -> impl Stream<Item = std::io::Result<CanvasInputEvent>
             // 2 byte unsigned int for code, 
             // 4 byte unsigned int for value.
 
-            let (s, us, typ, code, val) = structure!("<IIHHI").unpack_from(&mut reader)?;
+            let mut event_buf = [0u8; 16];
+            f.read_exact(&mut event_buf).await?;
+            let (s, us, typ, code, val) = structure!("<IIHHI").unpack(&mut event_buf)?;
             // absolute position
             if typ == 3 {
                 if code == 0 {
-- 
GitLab