mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 18:10:14 +01:00
only require into Packet for sendable data
This commit is contained in:
parent
0bc13fee81
commit
e9dc4b59d2
|
@ -21,7 +21,7 @@ fn main() {
|
||||||
|
|
||||||
let connection = Connection::open(&cli.destination).unwrap();
|
let connection = Connection::open(&cli.destination).unwrap();
|
||||||
if cli.clear {
|
if cli.clear {
|
||||||
connection.send(Command::Clear.into()).unwrap();
|
connection.send(Command::Clear).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let max_width = cli.text.iter().map(|t| t.len()).max().unwrap();
|
let max_width = cli.text.iter().map(|t| t.len()).max().unwrap();
|
||||||
|
@ -37,6 +37,6 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
connection
|
connection
|
||||||
.send(Command::Cp437Data(Origin(0, 0), chars).into())
|
.send(Command::Cp437Data(Origin(0, 0), chars))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,6 @@ fn main() {
|
||||||
field.clone(),
|
field.clone(),
|
||||||
CompressionCode::Lzma,
|
CompressionCode::Lzma,
|
||||||
)
|
)
|
||||||
.into(),
|
|
||||||
)
|
)
|
||||||
.expect("could not send");
|
.expect("could not send");
|
||||||
thread::sleep(FRAME_PACING);
|
thread::sleep(FRAME_PACING);
|
||||||
|
|
|
@ -29,7 +29,6 @@ fn main() {
|
||||||
pixels.clone(),
|
pixels.clone(),
|
||||||
CompressionCode::Lzma,
|
CompressionCode::Lzma,
|
||||||
)
|
)
|
||||||
.into(),
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
thread::sleep(FRAME_PACING);
|
thread::sleep(FRAME_PACING);
|
||||||
|
|
|
@ -30,12 +30,12 @@ fn main() {
|
||||||
|
|
||||||
let command =
|
let command =
|
||||||
BitmapLinearWin(Origin(0, 0), filled_grid, CompressionCode::Lzma);
|
BitmapLinearWin(Origin(0, 0), filled_grid, CompressionCode::Lzma);
|
||||||
connection.send(command.into()).expect("send failed");
|
connection.send(command).expect("send failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
// set all pixels to the same random brightness
|
// set all pixels to the same random brightness
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
connection.send(Brightness(rng.gen()).into()).unwrap();
|
connection.send(Brightness(rng.gen())).unwrap();
|
||||||
|
|
||||||
// continuously update random windows to new random brightness
|
// continuously update random windows to new random brightness
|
||||||
loop {
|
loop {
|
||||||
|
@ -56,7 +56,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
connection
|
connection
|
||||||
.send(CharBrightness(origin, luma).into())
|
.send(CharBrightness(origin, luma))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
std::thread::sleep(wait_duration);
|
std::thread::sleep(wait_duration);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ fn main() {
|
||||||
connection
|
connection
|
||||||
.send(
|
.send(
|
||||||
Command::BitmapLinearAnd(0, bit_vec, CompressionCode::Lzma)
|
Command::BitmapLinearAnd(0, bit_vec, CompressionCode::Lzma)
|
||||||
.into(),
|
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
thread::sleep(sleep_duration);
|
thread::sleep(sleep_duration);
|
||||||
|
|
|
@ -10,6 +10,8 @@ pub struct Connection {
|
||||||
socket: UdpSocket,
|
socket: UdpSocket,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
/// Open a new UDP socket and connect to the provided host.
|
/// Open a new UDP socket and connect to the provided host.
|
||||||
///
|
///
|
||||||
|
@ -51,7 +53,7 @@ impl Connection {
|
||||||
/// .expect("connection failed");
|
/// .expect("connection failed");
|
||||||
///
|
///
|
||||||
/// // turn off all pixels
|
/// // turn off all pixels
|
||||||
/// connection.send(Command::Clear.into())
|
/// connection.send(Command::Clear)
|
||||||
/// .expect("send failed");
|
/// .expect("send failed");
|
||||||
///
|
///
|
||||||
/// // turn on all pixels
|
/// // turn on all pixels
|
||||||
|
@ -59,10 +61,11 @@ impl Connection {
|
||||||
/// pixels.fill(true);
|
/// pixels.fill(true);
|
||||||
///
|
///
|
||||||
/// // send pixels to display
|
/// // send pixels to display
|
||||||
/// connection.send(Command::BitmapLinearWin(servicepoint2::Origin(0, 0), pixels, CompressionCode::Uncompressed).into())
|
/// connection.send(Command::BitmapLinearWin(servicepoint2::Origin(0, 0), pixels, CompressionCode::Uncompressed))
|
||||||
/// .expect("send failed");
|
/// .expect("send failed");
|
||||||
/// ```
|
/// ```
|
||||||
pub fn send(&self, packet: Packet) -> Result<(), std::io::Error> {
|
pub fn send(&self, packet: impl Into<Packet>) -> Result<(), std::io::Error> {
|
||||||
|
let packet = packet.into();
|
||||||
debug!("sending {packet:?}");
|
debug!("sending {packet:?}");
|
||||||
let data: Vec<u8> = packet.into();
|
let data: Vec<u8> = packet.into();
|
||||||
self.socket.send(&data)?;
|
self.socket.send(&data)?;
|
||||||
|
|
Loading…
Reference in a new issue