mirror of
https://github.com/kaesaecracker/servicepoint-simulator.git
synced 2025-01-18 10:30:14 +01:00
extract handle_package function, make window resizable as content gets scaled
This commit is contained in:
parent
64e85bcd4f
commit
1584a2685e
81
src/main.rs
81
src/main.rs
|
@ -102,7 +102,7 @@ fn main() {
|
||||||
let mut buf = [0; 8985];
|
let mut buf = [0; 8985];
|
||||||
|
|
||||||
while rx.try_recv().is_err() {
|
while rx.try_recv().is_err() {
|
||||||
let (amount, source) = match socket.recv_from(&mut buf) {
|
let (amount, _) = match socket.recv_from(&mut buf) {
|
||||||
Err(err) if err.kind() == ErrorKind::WouldBlock => {
|
Err(err) if err.kind() == ErrorKind::WouldBlock => {
|
||||||
thread::sleep(Duration::from_millis(1));
|
thread::sleep(Duration::from_millis(1));
|
||||||
continue;
|
continue;
|
||||||
|
@ -110,45 +110,8 @@ fn main() {
|
||||||
Ok(result) => result,
|
Ok(result) => result,
|
||||||
other => other.unwrap(),
|
other => other.unwrap(),
|
||||||
};
|
};
|
||||||
let received = &mut buf[..amount];
|
|
||||||
|
|
||||||
let header = read_hdr_window(&received[..10]);
|
handle_package(&mut buf[..amount]);
|
||||||
if let Err(err) = header {
|
|
||||||
warn!("could not read header: {}", err);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let header = header.unwrap();
|
|
||||||
let payload = &received[10..];
|
|
||||||
|
|
||||||
info!(
|
|
||||||
"received from {:?}: {:?} (and {} bytes of payload)",
|
|
||||||
source,
|
|
||||||
header,
|
|
||||||
payload.len()
|
|
||||||
);
|
|
||||||
|
|
||||||
match header.command {
|
|
||||||
DisplayCommand::CmdClear => {
|
|
||||||
info!("(imagine an empty screen now)")
|
|
||||||
}
|
|
||||||
DisplayCommand::CmdHardReset => {
|
|
||||||
warn!("display shutting down");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
DisplayCommand::CmdBitmapLinearWin => {
|
|
||||||
print_bitmap_linear_win(&header, payload);
|
|
||||||
}
|
|
||||||
DisplayCommand::CmdCp437data => {
|
|
||||||
print_cp437_data(&header, payload);
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
error!(
|
|
||||||
"command {:?} sent by {:?} not implemented yet",
|
|
||||||
header.command, source
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -164,6 +127,42 @@ fn main() {
|
||||||
thread.join().expect("could not join threads");
|
thread.join().expect("could not join threads");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn handle_package(received: &mut [u8]) {
|
||||||
|
let header = read_hdr_window(&received[..10]);
|
||||||
|
if let Err(err) = header {
|
||||||
|
warn!("could not read header: {}", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let header = header.unwrap();
|
||||||
|
let payload = &received[10..];
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"received from {:?} (and {} bytes of payload)",
|
||||||
|
header,
|
||||||
|
payload.len()
|
||||||
|
);
|
||||||
|
|
||||||
|
match header.command {
|
||||||
|
DisplayCommand::CmdClear => {
|
||||||
|
info!("(imagine an empty screen now)")
|
||||||
|
}
|
||||||
|
DisplayCommand::CmdHardReset => {
|
||||||
|
warn!("display shutting down");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DisplayCommand::CmdBitmapLinearWin => {
|
||||||
|
print_bitmap_linear_win(&header, payload);
|
||||||
|
}
|
||||||
|
DisplayCommand::CmdCp437data => {
|
||||||
|
print_cp437_data(&header, payload);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
error!("command {:?} not implemented yet", header.command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct App {
|
struct App {
|
||||||
window: Option<Window>,
|
window: Option<Window>,
|
||||||
|
@ -175,9 +174,7 @@ impl ApplicationHandler for App {
|
||||||
let size = Size::from(LogicalSize::new(PIXEL_WIDTH as f64, PIXEL_HEIGHT as f64));
|
let size = Size::from(LogicalSize::new(PIXEL_WIDTH as f64, PIXEL_HEIGHT as f64));
|
||||||
let attributes = Window::default_attributes()
|
let attributes = Window::default_attributes()
|
||||||
.with_title("pixel-receiver-rs")
|
.with_title("pixel-receiver-rs")
|
||||||
.with_inner_size(size)
|
.with_inner_size(size);
|
||||||
.with_resizable(false)
|
|
||||||
.with_visible(true);
|
|
||||||
|
|
||||||
let window = event_loop.create_window(attributes).unwrap();
|
let window = event_loop.create_window(attributes).unwrap();
|
||||||
self.window = Some(window);
|
self.window = Some(window);
|
||||||
|
|
Loading…
Reference in a new issue