lossy fast mode

This commit is contained in:
Vinzenz Schroeter 2024-11-10 14:41:02 +01:00
parent 89e391f846
commit 299d361010
2 changed files with 32 additions and 11 deletions

View file

@ -2,7 +2,7 @@
Pipe text to the servicepoint-display. Pipe text to the servicepoint-display.
For more information, see (here)[https://github.com/cccb/servicepoint]. For more information, see [here](https://github.com/cccb/servicepoint).
```shell ```shell
dmesg --follow > servicepoint-tty dmesg --follow > servicepoint-tty

View file

@ -1,3 +1,4 @@
use clap::{ArgAction};
use clap::Parser; use clap::Parser;
use servicepoint::cp437::char_to_cp437; use servicepoint::cp437::char_to_cp437;
use servicepoint::{ use servicepoint::{
@ -13,9 +14,16 @@ struct Args {
short, short,
long, long,
default_value = "localhost:2342", default_value = "localhost:2342",
help = "Address of the display" help = "Address of the display. Try '172.23.42.29:2342'."
)] )]
destination: String, destination: String,
#[arg(
short,
long,
action = ArgAction::Count,
help = "Increase speed, but loose some packages. Add multiple times to go faster."
)]
fast: u8,
} }
struct App { struct App {
@ -23,19 +31,25 @@ struct App {
mirror: CharGrid, mirror: CharGrid,
x: usize, x: usize,
y: usize, y: usize,
fast: bool,
faster: bool,
} }
impl App { impl App {
fn new(connection: Connection) -> Self { fn new(args: Args) -> Self {
let connection = Connection::open(args.destination).unwrap();
Self { Self {
connection, connection,
mirror: CharGrid::new(TILE_WIDTH, TILE_HEIGHT), mirror: CharGrid::new(TILE_WIDTH, TILE_HEIGHT),
x: 0, x: 0,
y: 0, y: 0,
fast: args.fast > 0,
faster: args.fast > 1,
} }
} }
fn run(&mut self) { fn run(&mut self) {
self.connection.send(Command::Clear).unwrap();
for byte in std::io::stdin().bytes() { for byte in std::io::stdin().bytes() {
let byte = match byte { let byte = match byte {
Err(err) => { Err(err) => {
@ -52,8 +66,9 @@ impl App {
fn shift_rows(&mut self) { fn shift_rows(&mut self) {
let data = self.mirror.data_ref_mut(); let data = self.mirror.data_ref_mut();
data.rotate_left(TILE_WIDTH); data.rotate_left(TILE_WIDTH);
data.last_chunk_mut() if let Some(row) = data.last_chunk_mut::<TILE_WIDTH>() {
.map(move |row: &mut [char; TILE_WIDTH]| row.fill(' ')); row.fill(' ')
}
} }
fn handle_char(&mut self, char: char) { fn handle_char(&mut self, char: char) {
@ -67,8 +82,10 @@ impl App {
self.connection self.connection
.send(Command::Cp437Data(Origin::new(self.x, self.y), grid)) .send(Command::Cp437Data(Origin::new(self.x, self.y), grid))
.unwrap(); .unwrap();
if !self.fast {
sleep(FRAME_PACING); sleep(FRAME_PACING);
} }
}
self.x += 1; self.x += 1;
} }
@ -86,19 +103,23 @@ impl App {
} }
fn send_mirror(&self) { fn send_mirror(&self) {
if self.fast && !self.faster {
sleep(FRAME_PACING);
}
self.connection self.connection
.send(Command::Cp437Data( .send(Command::Cp437Data(
Origin::ZERO, Origin::ZERO,
Cp437Grid::from(&self.mirror), Cp437Grid::from(&self.mirror),
)) ))
.unwrap(); .unwrap();
if !self.fast {
sleep(FRAME_PACING); sleep(FRAME_PACING);
} }
}
} }
fn main() { fn main() {
let args = Args::parse(); App::new(Args::parse()).run()
let connection = Connection::open(&args.destination).unwrap();
connection.send(Command::Clear).unwrap();
App::new(connection).run()
} }