WIP: next servicepoint version #1

Draft
vinzenz wants to merge 4 commits from next into main
7 changed files with 62 additions and 48 deletions
Showing only changes of commit 3264eaa567 - Show all commits

3
Cargo.lock generated
View file

@ -1440,8 +1440,7 @@ dependencies = [
[[package]] [[package]]
name = "servicepoint" name = "servicepoint"
version = "0.13.2" version = "0.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://git.berlin.ccc.de/servicepoint/servicepoint/?branch=next#300bb5d6474f0f6152ab04feed4478995fcb3ec8"
checksum = "33abd53582a995aaf5d387be4a1f7eb294a084185f88f8cf61652b6272041660"
dependencies = [ dependencies = [
"bitvec", "bitvec",
"bzip2", "bzip2",

View file

@ -20,7 +20,7 @@ clap = { version = "4.5", features = ["derive"] }
thiserror = "2.0" thiserror = "2.0"
# package parsing # package parsing
servicepoint = { version = "0.13.2", features = ["all_compressions"] } servicepoint = { features = ["all_compressions"], git = "https://git.berlin.ccc.de/servicepoint/servicepoint/", branch = "next" }
# font rendering # font rendering
font-kit = "0.14.2" font-kit = "0.14.2"

View file

@ -1,13 +1,19 @@
use crate::command_executor::ExecutionResult::{Failure, Shutdown, Success}; use crate::{
use crate::cp437_font::Cp437Font; command_executor::ExecutionResult::{Failure, Shutdown, Success},
use crate::font_renderer::FontRenderer8x8; cp437_font::Cp437Font,
font_renderer::FontRenderer8x8,
};
use log::{debug, error, info, trace, warn}; use log::{debug, error, info, trace, warn};
use servicepoint::{ use servicepoint::{
BitVec, Bitmap, BrightnessGrid, CharGrid, Command, Cp437Grid, Grid, Offset, BinaryOperation, BitVec, BitVecCommand, Bitmap, BitmapCommand,
Origin, Tiles, PIXEL_COUNT, PIXEL_WIDTH, TILE_SIZE, BrightnessCommand, BrightnessGrid, BrightnessGridCommand, CharGrid,
CharGridCommand, Cp437Grid, Cp437GridCommand, Grid, Offset, Origin, Tiles,
TypedCommand, PIXEL_COUNT, PIXEL_WIDTH, TILE_SIZE,
};
use std::{
ops::{BitAnd, BitOr, BitXor},
sync::RwLock,
}; };
use std::ops::{BitAnd, BitOr, BitXor};
use std::sync::RwLock;
#[derive(Debug)] #[derive(Debug)]
pub struct CommandExecutor<'t> { pub struct CommandExecutor<'t> {
@ -38,53 +44,62 @@ impl<'t> CommandExecutor<'t> {
} }
} }
pub(crate) fn execute(&self, command: Command) -> ExecutionResult { pub(crate) fn execute(&self, command: TypedCommand) -> ExecutionResult {
debug!("received {command:?}"); debug!("received {command:?}");
match command { match command {
Command::Clear => { TypedCommand::Clear(_) => {
info!("clearing display"); info!("clearing display");
self.display.write().unwrap().fill(false); self.display.write().unwrap().fill(false);
Success Success
} }
Command::HardReset => { TypedCommand::HardReset(_) => {
warn!("display shutting down"); warn!("display shutting down");
Shutdown Shutdown
} }
Command::BitmapLinearWin(Origin { x, y, .. }, pixels, _) => { TypedCommand::Bitmap(BitmapCommand {
self.print_pixel_grid(x, y, &pixels) origin: Origin { x, y, .. },
} bitmap,
Command::Cp437Data(origin, grid) => { ..
}) => self.print_pixel_grid(x, y, &bitmap),
TypedCommand::Cp437Grid(Cp437GridCommand { origin, grid }) => {
self.print_cp437_data(origin, &grid) self.print_cp437_data(origin, &grid)
} }
#[allow(deprecated)] #[allow(deprecated)]
Command::BitmapLegacy => { TypedCommand::BitmapLegacy(_) => {
warn!("ignoring deprecated command {:?}", command); warn!("ignoring deprecated command {:?}", command);
Failure Failure
} }
Command::BitmapLinearAnd(offset, vec, _) => { TypedCommand::BitVec(command) => {
self.execute_bitmap_linear(offset, vec, BitAnd::bitand) let BitVecCommand {
offset,
bitvec,
operation,
..
} = command;
fn overwrite(_: bool, new: bool) -> bool {
new
} }
Command::BitmapLinearOr(offset, vec, _) => { let operation = match operation {
self.execute_bitmap_linear(offset, vec, BitOr::bitor) BinaryOperation::Overwrite => overwrite,
BinaryOperation::And => BitAnd::bitand,
BinaryOperation::Or => BitOr::bitor,
BinaryOperation::Xor => BitXor::bitxor,
};
self.execute_bitmap_linear(offset, bitvec, operation)
} }
Command::BitmapLinearXor(offset, vec, _) => { TypedCommand::BrightnessGrid(BrightnessGridCommand {
self.execute_bitmap_linear(offset, vec, BitXor::bitxor) origin,
} grid,
Command::BitmapLinear(offset, vec, _) => { }) => self.execute_char_brightness(origin, grid),
self.execute_bitmap_linear(offset, vec, move |_, new| new) TypedCommand::Brightness(BrightnessCommand { brightness }) => {
}
Command::CharBrightness(origin, grid) => {
self.execute_char_brightness(origin, grid)
}
Command::Brightness(brightness) => {
self.luma.write().unwrap().fill(brightness); self.luma.write().unwrap().fill(brightness);
Success Success
} }
Command::FadeOut => { TypedCommand::FadeOut(_) => {
error!("command not implemented: {command:?}"); error!("command not implemented: {command:?}");
Success Success
} }
Command::Utf8Data(origin, grid) => { TypedCommand::CharGrid(CharGridCommand { origin, grid }) => {
self.print_utf8_data(origin, &grid) self.print_utf8_data(origin, &grid)
} }
} }

View file

@ -17,7 +17,7 @@ impl Cp437Font {
impl Default for Cp437Font { impl Default for Cp437Font {
fn default() -> Self { fn default() -> Self {
let mut bitmaps = let mut bitmaps =
core::array::from_fn(|_| Bitmap::new(TILE_SIZE, TILE_SIZE)); core::array::from_fn(|_| Bitmap::new(TILE_SIZE, TILE_SIZE).unwrap());
for (char_code, bitmap) in bitmaps.iter_mut().enumerate() { for (char_code, bitmap) in bitmaps.iter_mut().enumerate() {
let bits = CP437_FONT_LINEAR[char_code]; let bits = CP437_FONT_LINEAR[char_code];

View file

@ -1,7 +1,6 @@
use std::{sync::mpsc::Sender, sync::RwLock};
use log::{info, warn}; use log::{info, warn};
use servicepoint::*; use servicepoint::*;
use std::{sync::mpsc::Sender, sync::RwLock};
use winit::{ use winit::{
application::ApplicationHandler, dpi::LogicalSize, event::WindowEvent, application::ApplicationHandler, dpi::LogicalSize, event::WindowEvent,
event_loop::ActiveEventLoop, keyboard::KeyCode::KeyC, window::WindowId, event_loop::ActiveEventLoop, keyboard::KeyCode::KeyC, window::WindowId,

View file

@ -32,7 +32,7 @@ fn main() {
.expect("could not create event loop"); .expect("could not create event loop");
event_loop.set_control_flow(ControlFlow::Wait); event_loop.set_control_flow(ControlFlow::Wait);
let display = RwLock::new(Bitmap::new(PIXEL_WIDTH, PIXEL_HEIGHT)); let display = RwLock::new(Bitmap::max_sized());
let luma = RwLock::new(BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT)); let luma = RwLock::new(BrightnessGrid::new(TILE_WIDTH, TILE_HEIGHT));
let (stop_udp_tx, stop_udp_rx) = mpsc::channel(); let (stop_udp_tx, stop_udp_rx) = mpsc::channel();
let font_renderer = cli let font_renderer = cli

View file

@ -1,11 +1,12 @@
use crate::command_executor::{CommandExecutor, ExecutionResult}; use crate::{
use crate::gui::AppEvents; command_executor::{CommandExecutor, ExecutionResult},
gui::AppEvents,
};
use log::{error, warn}; use log::{error, warn};
use servicepoint::Command; use servicepoint::TypedCommand;
use std::io::ErrorKind; use std::{
use std::net::UdpSocket; io::ErrorKind, net::UdpSocket, sync::mpsc::Receiver, time::Duration,
use std::sync::mpsc::Receiver; };
use std::time::Duration;
use winit::event_loop::EventLoopProxy; use winit::event_loop::EventLoopProxy;
const BUF_SIZE: usize = 8985; const BUF_SIZE: usize = 8985;
@ -65,13 +66,13 @@ impl<'t> UdpServer<'t> {
} }
} }
fn command_from_slice(slice: &[u8]) -> Option<Command> { fn command_from_slice(slice: &[u8]) -> Option<TypedCommand> {
let packet = servicepoint::Packet::try_from(slice) let packet = servicepoint::Packet::try_from(slice)
.inspect_err(|_| { .inspect_err(|_| {
warn!("could not load packet with length {}", slice.len()) warn!("could not load packet with length {}", slice.len())
}) })
.ok()?; .ok()?;
Command::try_from(packet) TypedCommand::try_from(packet)
.inspect_err(move |err| { .inspect_err(move |err| {
warn!("could not read command for packet: {:?}", err) warn!("could not read command for packet: {:?}", err)
}) })