diff --git a/.gitignore b/.gitignore index f2f9e58..80ddb49 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -target -Cargo.lock \ No newline at end of file +debug/ +target/ +Cargo.lock diff --git a/Cargo.lock b/Cargo.lock index 2934d55..005bc38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,64 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "ftdi-mpsse" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7cfcda69930a8d2fdcdd7ffb9234fe4c79a8c73934ed4904327d77bfb5078a" +dependencies = [ + "static_assertions", +] + +[[package]] +name = "libftd2xx" +version = "0.32.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f20d68b3138aaabb97edc3db8ed8f418d60f8abd2a7d8220d562906fb38ff08e" +dependencies = [ + "ftdi-mpsse", + "libftd2xx-ffi", + "log", + "paste", + "static_assertions", +] + +[[package]] +name = "libftd2xx-ffi" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40bed7f53ea45282e0e4f1361d1a8094e62abe0ccfd9a6dbf7e3db932b2789ce" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "wacca-led" version = "0.1.0" +dependencies = [ + "libftd2xx", +] diff --git a/Cargo.toml b/Cargo.toml index 0372518..0315a26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,4 @@ default-target="x86_64-pc-windows-gnu" crate-type = ["cdylib"] [dependencies] +libftd2xx = "0.32.5" \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 032008c..e1d2576 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,11 +39,11 @@ pub extern fn USBIntLED_getVersion() -> i64 { pub extern fn USBIntLED_Init() -> bool { println!("Init"); // let _ = SOCKET.set(UdpSocket::bind("0.0.0.0:0").unwrap()); - let e = output::udprealtime::output { - socket: None + let mut e = output::udprealtime::output { + socket: Some(UdpSocket::bind("0.0.0.0:0").unwrap()) }; - e.init(); - let _ = SOCKET.set(output::Sockets(e)); + // e.init(); + let _ = SOCKET.set(output::sockets::udprealtime(e)); return true } @@ -71,10 +71,10 @@ pub extern fn USBIntLED_set(_a1: i64, a2: usize) { // let mut flattened: Vec = leds.into_iter().flatten().collect(); // header.append(&mut flattened); match SOCKET.get() { - Some(&ref socket) => { + Some(socket) => { // let sock: UdpSocket = socket.try_clone().unwrap(); // let _ = sock.send_to(&header, addr); - socket.send(&mut leds); + socket.send(&leds); // output::sockets::udprealtime(*socket).send(leds) }, None => { diff --git a/src/output/mod.rs b/src/output/mod.rs index d8ceef5..cdd8a5b 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -5,10 +5,10 @@ pub enum sockets { } impl sockets { - pub fn send(&mut self, leds: &mut Vec) -> bool { + pub fn send(&self, leds: &Vec) -> bool { match self { sockets::udprealtime(s) => { - s.send(leds) + s.send(&leds) } } } diff --git a/src/output/udprealtime.rs b/src/output/udprealtime.rs index d8b35fb..4e4dc5b 100644 --- a/src/output/udprealtime.rs +++ b/src/output/udprealtime.rs @@ -6,16 +6,17 @@ pub struct output { } impl output { - pub fn init(&mut self) -> bool { - self.socket = Some(UdpSocket::bind("0.0.0.0:0").unwrap()); - return true; - } - pub fn send(&mut self, leds: &mut Vec) -> bool { + // pub fn init(&mut self) -> bool { + // self.socket = + // return true; + // } + pub fn send(&self, leds: &Vec) -> bool { let mut header: Vec = vec![2, 2]; - let mut flattened: Vec = *leds.into_iter().flatten().collect(); + let leds2 = Vec::clone(leds); + let mut flattened: Vec = leds2.into_iter().flatten().collect(); let addr = SocketAddr::from(([100, 64, 0, 79], 21324)); header.append(&mut flattened); - match self.socket { + match &self.socket { Some(s) => { let _ = s.send_to(&header, addr); }, None => () } diff --git a/src/rgb.rs b/src/rgb.rs index 2441a43..575b47b 100644 --- a/src/rgb.rs +++ b/src/rgb.rs @@ -1,3 +1,4 @@ +#[derive(Clone)] pub struct RGB { pub red: u8, pub green: u8,