From 7bfb51bc58440bba94c72f61f63d9f31c499071f Mon Sep 17 00:00:00 2001 From: Ollo Date: Wed, 3 May 2023 21:24:12 +0200 Subject: [PATCH] Rust client sending 100% brightness and first 8 LEDs --- README.md | 24 ++++++++++++++++++++++++ client/.gitignore | 2 ++ client/Cargo.toml | 8 ++++++++ client/src/main.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 client/.gitignore create mode 100644 client/Cargo.toml create mode 100644 client/src/main.rs diff --git a/README.md b/README.md index 9044c42..fed8aa9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,27 @@ # LED-Board ## Project Page [C3MA](https://www.ccc-mannheim.de/wiki/LED-Board) + +## Controller +* PlatformIO + +### Hardware +* Arduino MEGA2560 +* Ethernet shield + +### Firmware +* PlatformIO based + +see **platformio.ini** + +## Client Software +stored in folder **/client** + +### Dependency +* rust +* cargo + +### Build +go to **/client** +* cargo build +* cargo run diff --git a/client/.gitignore b/client/.gitignore new file mode 100644 index 0000000..4fffb2f --- /dev/null +++ b/client/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/client/Cargo.toml b/client/Cargo.toml new file mode 100644 index 0000000..9366195 --- /dev/null +++ b/client/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "LEDboardClient" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/client/src/main.rs b/client/src/main.rs new file mode 100644 index 0000000..9b19b8f --- /dev/null +++ b/client/src/main.rs @@ -0,0 +1,43 @@ +use std::net::UdpSocket; +use std::env; + +const IMAGE_WIDTH_BYTE : usize = (5*32) / 8; /* one byte contains 8 lets, one in each bit */ +const IMAGE_HEIGHT_BYTE : usize = 40; + +fn send_package(ipaddress: String) { + let mut image = [0; (IMAGE_WIDTH_BYTE*IMAGE_HEIGHT_BYTE)+1]; + image[0] = 0xFF; + image[1] = 0xFF; + let socket = UdpSocket::bind("0.0.0.0:4242").expect("couldn't bind to address"); + socket.send_to(&image, ipaddress + ":4242").expect("couldn't send data"); + println!("Packet sent"); +} + +fn help() { + println!("usage: +LEDboardClient "); +println!("one argument necessary!"); + println!(""); +} + +fn main() { + let args: Vec = env::args().collect(); + + match args.len() { + // no arguments passed + 1 => { + // show a help message + help(); + }, + // one argument passed + 2 => { + let ip = &args[1]; + send_package(ip.to_string()); + }, + // all the other cases + _ => { + // show a help message + help(); + } + } +}