remove Window, fix examples, add logging
This commit is contained in:
parent
40de106f46
commit
27f891cd92
17 changed files with 707 additions and 61 deletions
|
@ -1,4 +1,6 @@
|
|||
use std::fmt::Debug;
|
||||
use std::net::{ToSocketAddrs, UdpSocket};
|
||||
use log::{debug, info};
|
||||
use crate::Packet;
|
||||
|
||||
pub struct Connection {
|
||||
|
@ -7,14 +9,16 @@ pub struct Connection {
|
|||
|
||||
impl Connection {
|
||||
/// Open a new UDP socket and create a display instance
|
||||
pub fn open(addr: impl ToSocketAddrs) -> std::io::Result<Self> {
|
||||
pub fn open(addr: impl ToSocketAddrs + Debug) -> std::io::Result<Self> {
|
||||
info!("connecting to {addr:?}");
|
||||
let socket = UdpSocket::bind("0.0.0.0:0")?;
|
||||
socket.connect(addr)?;
|
||||
Ok(Self { socket })
|
||||
}
|
||||
|
||||
/// Send a command to the display
|
||||
pub fn send(&self, packet: impl Into<Packet>) -> std::io::Result<()> {
|
||||
pub fn send(&self, packet: impl Into<Packet> + Debug) -> std::io::Result<()> {
|
||||
debug!("sending {packet:?}");
|
||||
let packet = packet.into();
|
||||
let data: Vec<u8> = packet.into();
|
||||
self.socket.send(&*data)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue