Compare commits
No commits in common. "cc29d5226b26742d669efffe7c058ae24381b9f6" and "893fcb8fb1ebd3e8e6b14981d0893bd88716b669" have entirely different histories.
cc29d5226b
...
893fcb8fb1
5 changed files with 27 additions and 137 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -49,12 +49,6 @@ version = "1.3.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bracket-color"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c1d1b160817fb74eebedccd678055cd688d1a73dc1a14519fa30ff4c9a5bdee"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.10.0"
|
||||
|
@ -668,7 +662,6 @@ name = "splink_client"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bracket-color",
|
||||
"clap",
|
||||
"image",
|
||||
"rand",
|
||||
|
|
|
@ -7,7 +7,6 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0.57"
|
||||
bracket-color = "0.8.2"
|
||||
clap = { version = "3.1.18", features = ["derive", "deprecated"] }
|
||||
image = "0.24.2"
|
||||
rand = "0.8.5"
|
||||
|
|
|
@ -4,7 +4,7 @@ mod strandifier;
|
|||
pub use strandifier::{Strandifier, StrandifierError};
|
||||
|
||||
mod sender;
|
||||
pub use sender::{send_frame, send_strand, SenderError};
|
||||
pub use sender::{SenderError, send_strand, send_frame};
|
||||
|
||||
/// The LED wall's layout.
|
||||
///
|
||||
|
@ -33,9 +33,6 @@ pub struct Layout {
|
|||
|
||||
pub num_panels_h: u32,
|
||||
pub num_panels_v: u32,
|
||||
|
||||
pub total_strands: u32,
|
||||
pub first_strand_index: u32,
|
||||
}
|
||||
|
||||
impl Layout {
|
||||
|
|
109
src/main.rs
109
src/main.rs
|
@ -4,20 +4,15 @@ use std::{
|
|||
f32::consts::FRAC_PI_2,
|
||||
io::stdout,
|
||||
net::{Ipv4Addr, SocketAddr, UdpSocket},
|
||||
num::ParseIntError,
|
||||
path::PathBuf,
|
||||
str::FromStr,
|
||||
thread::sleep,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use bracket_color::prelude::{HSV, RGB};
|
||||
use clap::{Parser, Subcommand};
|
||||
use clap::Parser;
|
||||
use image::{Pixel, Rgb, RgbImage};
|
||||
use rand::Rng;
|
||||
|
||||
use splink_client::{send_frame, Layout};
|
||||
use thiserror::Error;
|
||||
use splink_client::{Layout, send_frame};
|
||||
|
||||
/// Blinkenwall v3 prototype client
|
||||
#[derive(Parser, Debug)]
|
||||
|
@ -33,60 +28,10 @@ struct Args {
|
|||
|
||||
/// Controller's address
|
||||
remote_addr: SocketAddr,
|
||||
|
||||
/// The action to perform
|
||||
#[clap(subcommand, rename_all = "kebab-case")]
|
||||
action: Action,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
struct Color {
|
||||
r: u8,
|
||||
g: u8,
|
||||
b: u8,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Error)]
|
||||
enum ColorError {
|
||||
#[error("Wrong parameter length")]
|
||||
WrongLength,
|
||||
#[error("Illegal integer")]
|
||||
BadNumber(#[from] ParseIntError),
|
||||
}
|
||||
|
||||
impl FromStr for Color {
|
||||
type Err = ColorError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let s = s.strip_prefix('#').unwrap_or(s);
|
||||
|
||||
if s.len() != 6 {
|
||||
return Err(ColorError::WrongLength);
|
||||
}
|
||||
|
||||
let r = u8::from_str_radix(&s[0..2], 16)?;
|
||||
let g = u8::from_str_radix(&s[2..4], 16)?;
|
||||
let b = u8::from_str_radix(&s[4..6], 16)?;
|
||||
|
||||
Ok(Self { r, g, b })
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Color> for Rgb<u8> {
|
||||
fn from(c: Color) -> Rgb<u8> {
|
||||
Rgb([c.r, c.g, c.b])
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Subcommand)]
|
||||
enum Action {
|
||||
Rainbow,
|
||||
Solid { color: Color },
|
||||
Image { path: PathBuf },
|
||||
Clear,
|
||||
}
|
||||
|
||||
fn bling(layout: Layout, frame: u32) -> RgbImage {
|
||||
fn get_frame(layout: Layout, frame: u32) -> RgbImage {
|
||||
#![allow(
|
||||
clippy::cast_precision_loss,
|
||||
clippy::cast_lossless,
|
||||
|
@ -126,24 +71,6 @@ fn bling(layout: Layout, frame: u32) -> RgbImage {
|
|||
})
|
||||
}
|
||||
|
||||
fn rainbow(layout: Layout, frame: u32) -> RgbImage {
|
||||
#![allow(
|
||||
clippy::cast_precision_loss,
|
||||
clippy::cast_lossless,
|
||||
clippy::cast_possible_truncation,
|
||||
clippy::cast_sign_loss
|
||||
)]
|
||||
|
||||
let w = layout.width_px();
|
||||
let h = layout.height_px();
|
||||
|
||||
RgbImage::from_fn(w, h, |x, y| {
|
||||
let RGB { r, g, b } =
|
||||
HSV::from_f32((x + y + frame) as f32 / 100.0 % 1.0, 1.0, 0.1).to_rgb();
|
||||
Rgb([(r * 255.0) as u8, (g * 255.0) as u8, (b * 255.0) as u8])
|
||||
})
|
||||
}
|
||||
|
||||
fn print_image(image: &RgbImage) {
|
||||
let _hide = termion::cursor::HideCursor::from(stdout());
|
||||
|
||||
|
@ -176,32 +103,10 @@ fn main() -> anyhow::Result<()> {
|
|||
|
||||
num_panels_h: 6,
|
||||
num_panels_v: 1,
|
||||
|
||||
total_strands: 24,
|
||||
first_strand_index: 8,
|
||||
};
|
||||
|
||||
match args.action {
|
||||
Action::Solid { color } => {
|
||||
let image = RgbImage::from_pixel(layout.width_px(), layout.height_px(), color.into());
|
||||
let frame_num: u32 = rand::thread_rng().gen();
|
||||
send_frame(&socket, layout, frame_num, &image)?;
|
||||
}
|
||||
Action::Clear => {
|
||||
let image = RgbImage::new(layout.width_px(), layout.height_px());
|
||||
let frame_num: u32 = rand::thread_rng().gen();
|
||||
send_frame(&socket, layout, frame_num, &image)?;
|
||||
}
|
||||
Action::Image { path } => {
|
||||
let image = RgbImage::new(layout.width_px(), layout.height_px());
|
||||
let frame_num: u32 = rand::thread_rng().gen();
|
||||
send_frame(&socket, layout, frame_num, &image)?;
|
||||
}
|
||||
Action::Rainbow => {
|
||||
print!("{}", termion::clear::All);
|
||||
|
||||
for frame in 0.. {
|
||||
let image = rainbow(layout, frame);
|
||||
let image = get_frame(layout, frame);
|
||||
|
||||
print_image(&image);
|
||||
|
||||
|
@ -210,8 +115,10 @@ fn main() -> anyhow::Result<()> {
|
|||
|
||||
sleep(Duration::from_millis(16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let image = RgbImage::from_fn(96, 64, |_x, y| {
|
||||
[Rgb([0, 3, 1]), Rgb([1, 3, 0]), Rgb([3, 0, 1])][y as usize % 3]
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
use std::{io, net::UdpSocket};
|
||||
use std::{
|
||||
io::{self, ErrorKind},
|
||||
net::UdpSocket,
|
||||
};
|
||||
|
||||
use image::{Rgb, RgbImage};
|
||||
use thiserror::Error;
|
||||
|
@ -64,27 +67,18 @@ pub fn send_frame(
|
|||
frame_num: u32,
|
||||
image: &RgbImage,
|
||||
) -> Result<(), SenderError> {
|
||||
for strand_num in 0..layout.total_strands {
|
||||
if strand_num >= layout.first_strand_index
|
||||
&& strand_num < layout.num_strands() + layout.first_strand_index
|
||||
{
|
||||
let data =
|
||||
Strandifier::make_strand(layout, image, strand_num - layout.first_strand_index)?;
|
||||
send_strand(socket, strand_num as u32, frame_num, data)?;
|
||||
} else {
|
||||
send_strand(
|
||||
socket,
|
||||
strand_num as u32,
|
||||
frame_num,
|
||||
vec![Rgb([0, 0, 0]); layout.strand_len() as usize],
|
||||
)?;
|
||||
}
|
||||
for strand_num in 0..layout.num_strands() {
|
||||
let data = Strandifier::make_strand(layout, image, strand_num)?;
|
||||
send_strand(socket, strand_num, frame_num, data)?;
|
||||
}
|
||||
|
||||
let mut buf = vec![0; 100];
|
||||
let len = socket
|
||||
.recv(&mut buf)
|
||||
.map_err(|_| SenderError::ConfirmationTimeout)?;
|
||||
let len = match socket.recv(&mut buf) {
|
||||
Ok(len) => len,
|
||||
//Err(e) if e.kind() == ErrorKind::TimedOut => return Err(SenderError::ConfirmationTimeout),
|
||||
Err(e) => return Err(SenderError::ConfirmationTimeout),
|
||||
Err(e) => return Err(SenderError::Io(e)),
|
||||
};
|
||||
let buf = &buf[..len];
|
||||
let response_frame_num = u32::from_be_bytes(
|
||||
buf.try_into()
|
||||
|
|
Loading…
Reference in a new issue