Add string and binary msgs
This commit is contained in:
@@ -7,4 +7,5 @@ edition = "2021"
|
|||||||
address = "0.11.0"
|
address = "0.11.0"
|
||||||
clap = { version = "4.5.23", features = ["derive"] }
|
clap = { version = "4.5.23", features = ["derive"] }
|
||||||
image = "0.25.5"
|
image = "0.25.5"
|
||||||
|
io-uring = "0.7.3"
|
||||||
tokio = "1.42.0"
|
tokio = "1.42.0"
|
||||||
|
|||||||
26
src/flutr.rs
26
src/flutr.rs
@@ -1,26 +1,40 @@
|
|||||||
use crate::pixelmsgs::PixelMsgs;
|
use crate::pixelmsgs::PixelMsgs;
|
||||||
use address::Host;
|
use address::Host;
|
||||||
use std::{io::Write, net::TcpStream};
|
use io_uring::{opcode, types, IoUring};
|
||||||
|
use std::{io::Write, net::TcpStream, os::fd::AsRawFd};
|
||||||
|
|
||||||
pub struct FlutR {
|
pub struct FlutR {
|
||||||
stream: TcpStream,
|
stream: TcpStream,
|
||||||
|
stream_fd: i32,
|
||||||
msgs: PixelMsgs,
|
msgs: PixelMsgs,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FlutR {
|
impl FlutR {
|
||||||
pub fn new(host: Host, port: u16, msgs: PixelMsgs) -> Result<Self, std::io::Error> {
|
pub fn new(host: Host, port: u16, msgs: PixelMsgs) -> Result<Self, std::io::Error> {
|
||||||
let stream = TcpStream::connect(format!("{host}:{port}"))?;
|
let stream = TcpStream::connect(format!("{host}:{port}"))?;
|
||||||
Ok(FlutR { stream, msgs })
|
let stream_fd = stream.as_raw_fd();
|
||||||
|
Ok(FlutR {
|
||||||
|
stream,
|
||||||
|
stream_fd,
|
||||||
|
msgs,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn flut(&mut self) {
|
pub fn flut(&mut self) {
|
||||||
|
loop {
|
||||||
|
//self.write_sequential();
|
||||||
|
self.write_io_uring();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_sequential(&mut self) {
|
||||||
for msg in self.msgs.clone() {
|
for msg in self.msgs.clone() {
|
||||||
let result = self.stream.write(&msg);
|
let _ = self.stream.write(&msg);
|
||||||
match result {
|
|
||||||
Ok(_) => (),
|
|
||||||
Err(err) => eprintln!("{err}"),
|
|
||||||
}
|
}
|
||||||
let _ = self.stream.flush();
|
let _ = self.stream.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_io_uring(&mut self) {
|
||||||
|
for msg in self.msgs.clone() {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
use image::Rgb;
|
use image::Rgb;
|
||||||
|
|
||||||
pub type PixelMsg = [u8; 10];
|
pub type PixelBinaryMsg = [u8; 11];
|
||||||
pub type PixelMsgs = Vec<PixelMsg>;
|
pub type PixelBinaryMsgs = Vec<PixelBinaryMsg>;
|
||||||
|
pub type PixelStringMsg<'a> = &'a [u8];
|
||||||
|
pub type PixelStringMsgs<'a> = Vec<PixelStringMsg<'a>>;
|
||||||
|
|
||||||
pub trait Add {
|
pub trait Add {
|
||||||
fn add(&mut self, item: (u32, u32, &Rgb<u8>));
|
fn add(&mut self, item: (u32, u32, &Rgb<u8>));
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Add for PixelMsgs {
|
impl Add for PixelBinaryMsgs {
|
||||||
fn add(&mut self, item: (u32, u32, &Rgb<u8>)) {
|
fn add(&mut self, item: (u32, u32, &Rgb<u8>)) {
|
||||||
let pb: &[u8] = &[80, 66];
|
let pb: &[u8] = &[80, 66];
|
||||||
let x = (item.0 as u16).to_le_bytes();
|
let x = (item.0 as u16).to_le_bytes();
|
||||||
@@ -22,3 +24,14 @@ impl Add for PixelMsgs {
|
|||||||
self.push(msg.try_into().unwrap());
|
self.push(msg.try_into().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> Add for PixelStringMsgs<'a> {
|
||||||
|
fn add(&mut self, item: (u32, u32, &Rgb<u8>)) {
|
||||||
|
let color: &Rgb<u8> = item.2;
|
||||||
|
let r = color.0[0];
|
||||||
|
let g = color.0[1];
|
||||||
|
let b = color.0[2];
|
||||||
|
let msg = format!("PX {} {} {r:02x}{g:02x}{b:02x}\n", item.0, item.1).as_bytes();
|
||||||
|
self.push(msg.to_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user