Some modifcations and automating builds
This commit is contained in:
parent
255a24b5fe
commit
395d8b3cdb
5 changed files with 60 additions and 18 deletions
26
.github/workflows/ci.yml
vendored
Normal file
26
.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
name: Cargo Build Release
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Update rust to nightly
|
||||
run: rustup update nightly && rustup default nightly
|
||||
- name: Check for errors
|
||||
run: cargo check
|
||||
- name: Build with release profile
|
||||
run: cargo build --release
|
||||
- name: Archive output from build
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build
|
||||
path: target/x86_64-pc-windows-gnu/release/*.dll
|
15
src/lib.rs
15
src/lib.rs
|
@ -2,7 +2,6 @@
|
|||
use std::ptr;
|
||||
use std::net::{SocketAddr, UdpSocket};
|
||||
use std::sync::OnceLock;
|
||||
use std::convert::TryFrom;
|
||||
|
||||
mod output;
|
||||
mod rgb;
|
||||
|
@ -39,12 +38,18 @@ 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 mut e = output::udprealtime::output {
|
||||
socket: Some(UdpSocket::bind("0.0.0.0:0").unwrap())
|
||||
// let mut e = output::udprealtime::output {
|
||||
// socket: Some(UdpSocket::bind("0.0.0.0:0").unwrap())
|
||||
// };
|
||||
let ok = match output::udprealtime::Output::create(SocketAddr::from(([127, 0, 0, 1], 21324))) {
|
||||
Ok(e) => { match SOCKET.set(output::sockets::udprealtime(e)) {
|
||||
Ok(_) => true,
|
||||
Err(_) => false,
|
||||
}},
|
||||
Err(e) => { println!("{:?}",e); false },
|
||||
};
|
||||
// e.init();
|
||||
let _ = SOCKET.set(output::sockets::udprealtime(e));
|
||||
return true
|
||||
return ok
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
pub mod udprealtime;
|
||||
use crate::rgb;
|
||||
pub enum sockets {
|
||||
udprealtime(udprealtime::output)
|
||||
udprealtime(udprealtime::Output)
|
||||
}
|
||||
|
||||
impl sockets {
|
||||
|
|
|
@ -1,25 +1,31 @@
|
|||
use std::net::{SocketAddr, UdpSocket};
|
||||
use crate::rgb::RGB;
|
||||
use crate::rgb;
|
||||
|
||||
pub struct output {
|
||||
pub socket: Option<UdpSocket>
|
||||
pub struct Output {
|
||||
pub socket: UdpSocket,
|
||||
pub target: SocketAddr
|
||||
}
|
||||
|
||||
impl output {
|
||||
impl Output {
|
||||
// pub fn init(&mut self) -> bool {
|
||||
// self.socket =
|
||||
// return true;
|
||||
// }
|
||||
pub fn send(&self, leds: &Vec<RGB>) -> bool {
|
||||
pub fn create(addr: SocketAddr) -> Result<Output, &'static str> {
|
||||
let socket = match UdpSocket::bind("0.0.0.0:0") {
|
||||
Ok(socket) => socket,
|
||||
Err(_) => todo!(),
|
||||
};
|
||||
return Ok(Output {
|
||||
socket: socket,
|
||||
target: addr,
|
||||
})
|
||||
}
|
||||
pub fn send(&self, leds: &Vec<rgb::RGB>) -> bool {
|
||||
let mut header: Vec<u8> = vec![2, 2];
|
||||
let leds2 = Vec::clone(leds);
|
||||
let mut flattened: Vec<u8> = leds2.into_iter().flatten().collect();
|
||||
let addr = SocketAddr::from(([100, 64, 0, 79], 21324));
|
||||
let mut flattened: Vec<u8> = rgb::serialize(&leds);
|
||||
header.append(&mut flattened);
|
||||
match &self.socket {
|
||||
Some(s) => { let _ = s.send_to(&header, addr); },
|
||||
None => ()
|
||||
}
|
||||
let _ = &self.socket.send_to(&header, &self.target);
|
||||
return true
|
||||
}
|
||||
}
|
|
@ -13,3 +13,8 @@ impl IntoIterator for RGB {
|
|||
IntoIterator::into_iter([self.red, self.green, self.blue])
|
||||
}
|
||||
}
|
||||
|
||||
pub fn serialize(s: &Vec<RGB>) -> Vec<u8> {
|
||||
let p = s.clone();
|
||||
p.into_iter().flatten().collect()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue