diff --git a/Cargo.lock b/Cargo.lock index d149d2e..e9e700a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -202,7 +202,7 @@ dependencies = [ [[package]] name = "restream" -version = "0.1.0" +version = "1.1.0" dependencies = [ "anyhow", "clap", diff --git a/reStream.sh b/reStream.sh index 64e43e9..eec29d3 100755 --- a/reStream.sh +++ b/reStream.sh @@ -101,16 +101,22 @@ case "$rm_version" in "reMarkable 1.0") width=1408 height=1872 + bytes_per_pixel=2 + fb_file="/dev/fb0" pixel_format="rgb565le" ;; "reMarkable 2.0") if ssh_cmd "[ -f /dev/shm/swtfb.01 ]"; then width=1404 height=1872 + bytes_per_pixel=2 + fb_file="/dev/shm/swtfb.01" pixel_format="rgb565le" else width=1872 height=1404 + bytes_per_pixel=1 + fb_file=":mem:" pixel_format="gray8" video_filters="$video_filters,transpose=2" fi @@ -191,8 +197,10 @@ fi set -e # stop if an error occurs -restream_rs='PATH="$PATH:/opt/bin/:." restream' +restream_options="-h $height -w $width -b $bytes_per_pixel -f $fb_file" +# shellcheck disable=SC2089 +restream_rs="PATH=\"\$PATH:/opt/bin/:.\" restream $restream_options" if $unsecure_connection; then listen_port=16789 ssh_cmd "$restream_rs --listen $listen_port" & @@ -202,7 +210,7 @@ else receive_cmd="ssh_cmd $restream_rs" fi -# shellcheck disable=SC2086 +# shellcheck disable=SC2086,SC2090 $receive_cmd \ | $decompress \ | $host_passthrough \ diff --git a/src/main.rs b/src/main.rs index 26552d4..cc28c25 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,6 @@ use lz_fear::CompressionSettings; use std::default::Default; use std::fs::File; -use std::path::Path; use std::io::{BufRead, BufReader, Read, Seek, SeekFrom, Write}; use std::net::{TcpStream, TcpListener}; use std::process::Command; @@ -26,36 +25,55 @@ pub struct Opts { about = "Listen for an (unsecure) TCP connection to send the data to which reduces some load on the reMarkable and improves fps." )] listen: Option, + + #[clap( + long, + name = "height", + short = 'h', + about = "Height (in pixels) of the framebuffer." + )] + height: usize, + + #[clap( + long, + name = "width", + short = 'w', + about = "Width (in pixels) of the framebuffer." + )] + width: usize, + + #[clap( + long, + name = "bytes", + short = 'b', + about = "How many bytes represent one pixel in the framebuffer." + )] + bytes_per_pixel: usize, + + #[clap( + long, + name = "path", + short = 'f', + about = "File containing the framebuffer data. If this equals the string ':mem:' it will try to read the framebuffer from xochitl's process memory (rM2 only)." + )] + file: String, + } fn main() -> Result<()> { let ref opts: Opts = Opts::parse(); - let version = remarkable_version()?; - let height = 1872; - let streamer = if version == "reMarkable 1.0\n" { - let width = 1408; - let bytes_per_pixel = 2; - ReStreamer::init("/dev/fb0", 0, width, height, bytes_per_pixel)? - } else if version == "reMarkable 2.0\n" { - let width = 1404; - if Path::new("/dev/shm/swtfb.01").exists() { - let bytes_per_pixel = 2; - ReStreamer::init("/dev/shm/swtfb.01", 0, width, height, bytes_per_pixel)? - } else { - let bytes_per_pixel = 1; - let pid = xochitl_pid()?; - let offset = rm2_fb_offset(pid)?; - let mem = format!("/proc/{}/mem", pid); - ReStreamer::init(&mem, offset, width, height, bytes_per_pixel)? - } + let (file, offset) = if opts.file == ":mem:" { + let pid = xochitl_pid()?; + let offset = rm2_fb_offset(pid)?; + let mem = format!("/proc/{}/mem", pid); + (mem, offset) } else { - Err(anyhow!( - "Unknown reMarkable version: {}\nPlease open a feature request to support your device.", - version - ))? + (opts.file.to_owned(), 0) }; + let streamer = ReStreamer::init(&file, offset, opts.width, opts.height, opts.bytes_per_pixel)?; + let stdout = std::io::stdout(); let data_target: Box = if let Some(port) = opts.listen { Box::new(listen_timeout(port, Duration::from_secs(3))?) @@ -85,12 +103,6 @@ fn listen_timeout(port: usize, timeout: Duration) -> Result { Ok(conn) } -fn remarkable_version() -> Result { - let content = std::fs::read("/sys/devices/soc0/machine") - .context("Failed to read /sys/devices/soc0/machine")?; - Ok(String::from_utf8(content)?) -} - fn xochitl_pid() -> Result { let output = Command::new("/bin/pidof") .args(&["xochitl"])