refactor: move some stuff about

This commit is contained in:
Noa Aarts 2024-07-12 20:08:08 +02:00
parent 350b0911ff
commit 43f4147b2a

View file

@ -102,6 +102,7 @@ const SET_PX_RGBA_BIN: u8 = 129;
const SET_PX_W_BIN: u8 = 130; const SET_PX_W_BIN: u8 = 130;
const SET_PX_RGB_BIN_LENGTH: usize = 8; const SET_PX_RGB_BIN_LENGTH: usize = 8;
const GRID_LENGTH: usize = 1;
fn set_pixel_rgba(grids: &mut [FlutGrid<u32>], canvas: u8, x: u16, y: u16, rgb: u32) { fn set_pixel_rgba(grids: &mut [FlutGrid<u32>], canvas: u8, x: u16, y: u16, rgb: u32) {
match grids.get_mut(canvas as usize) { match grids.get_mut(canvas as usize) {
@ -117,7 +118,7 @@ fn get_pixel(grids: &mut [FlutGrid<u32>], canvas: u8, x: u16, y: u16) -> Option<
} }
} }
async fn process_msg< async fn process_lock<
R: AsyncReadExt + std::marker::Unpin, R: AsyncReadExt + std::marker::Unpin,
W: AsyncWriteExt + std::marker::Unpin, W: AsyncWriteExt + std::marker::Unpin,
>( >(
@ -125,15 +126,6 @@ async fn process_msg<
writer: &mut W, writer: &mut W,
grids: &mut [FlutGrid<u32>; GRID_LENGTH], grids: &mut [FlutGrid<u32>; GRID_LENGTH],
) -> io::Result<()> { ) -> io::Result<()> {
let fst = reader.read_u8().await;
match fst {
Ok(i) => match i {
HELP_TEXT => todo!("HELP command check and message"),
SIZE_TEXT => todo!("SIZE command check and message"),
PX_TEXT => todo!("PX command handling"),
HELP_BIN => todo!("HELP command message"),
SIZE_BIN => todo!("SIZE command check and message"),
LOCK => {
let amount = reader.read_u16_le().await?; let amount = reader.read_u16_le().await?;
let command = reader.read_u8().await?; let command = reader.read_u8().await?;
let lockmask = reader.read_u16().await?; let lockmask = reader.read_u16().await?;
@ -155,7 +147,7 @@ async fn process_msg<
return b; return b;
} }
0 => None, 0 => None,
_ => todo!("WTF"), k => panic!("WTF, how is {} not 0 or 1", k),
}) })
.collect(); .collect();
let mut mod_buf: Vec<u8> = vec![0; per]; let mut mod_buf: Vec<u8> = vec![0; per];
@ -193,7 +185,25 @@ async fn process_msg<
} }
return Ok(()); return Ok(());
} }
async fn process_msg<
R: AsyncReadExt + std::marker::Unpin,
W: AsyncWriteExt + std::marker::Unpin,
>(
reader: &mut R,
writer: &mut W,
grids: &mut [FlutGrid<u32>; GRID_LENGTH],
) -> io::Result<()> {
let fst = reader.read_u8().await;
match fst {
Ok(i) => match i {
HELP_TEXT => todo!("HELP command check and message"),
SIZE_TEXT => todo!("SIZE command check and message"),
PX_TEXT => todo!("PX command handling"),
HELP_BIN => todo!("HELP command message"),
SIZE_BIN => todo!("SIZE command check and message"),
LOCK => process_lock(reader, writer, grids).await,
GET_PX_BIN => { GET_PX_BIN => {
let canvas = reader.read_u8().await?; let canvas = reader.read_u8().await?;
let x = reader.read_u16_le().await?; let x = reader.read_u16_le().await?;
@ -267,8 +277,6 @@ async fn root() -> &'static str {
return "hiii"; return "hiii";
} }
const GRID_LENGTH: usize = 1;
#[tokio::main] #[tokio::main]
async fn main() -> io::Result<()> { async fn main() -> io::Result<()> {
println!("Start initialisation"); println!("Start initialisation");