2023-06-01 21:11:40 +00:00
|
|
|
///
|
|
|
|
/// Configure udev:
|
|
|
|
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
|
|
|
|
///
|
|
|
|
|
2023-06-03 13:21:36 +00:00
|
|
|
mod redis_ctrl;
|
|
|
|
|
2023-06-01 21:11:40 +00:00
|
|
|
use helios_dac::{Frame,
|
|
|
|
Point,
|
|
|
|
DeviceStatus,
|
|
|
|
// Coordinate,
|
|
|
|
Color};
|
2023-06-03 13:21:36 +00:00
|
|
|
use helios_dac::NativeHeliosDacController;
|
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
|
|
|
use std::sync::Arc;
|
2023-06-01 21:11:40 +00:00
|
|
|
|
2023-06-03 13:21:36 +00:00
|
|
|
use redis_ctrl::RedisCtrl;
|
2023-06-01 21:11:40 +00:00
|
|
|
|
|
|
|
const CENTER : (u16,u16) = (2000, 2000);
|
|
|
|
|
|
|
|
|
2023-06-03 13:21:36 +00:00
|
|
|
pub fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let running = Arc::new(AtomicBool::new(true));
|
|
|
|
let r = running.clone();
|
2023-06-01 21:11:40 +00:00
|
|
|
|
2023-06-03 13:21:36 +00:00
|
|
|
ctrlc::set_handler(move || {
|
|
|
|
r.store(false, Ordering::SeqCst);
|
|
|
|
}).expect("Error setting Ctrl-C handler");
|
|
|
|
|
|
|
|
let mut rs = RedisCtrl::new()?;
|
|
|
|
|
2023-06-01 21:11:40 +00:00
|
|
|
let controller = NativeHeliosDacController::new()?;
|
|
|
|
let devices = controller.list_devices()?;
|
|
|
|
|
|
|
|
let device = devices.into_iter().next().unwrap();
|
|
|
|
let mut device = device.open()?;
|
|
|
|
|
2023-06-03 13:21:36 +00:00
|
|
|
while running.load(Ordering::SeqCst) {
|
|
|
|
let frame = get_next_frame(1000, &mut rs)?;
|
|
|
|
|
2023-06-01 21:11:40 +00:00
|
|
|
while let Ok(DeviceStatus::NotReady) = device.status() {
|
|
|
|
}
|
|
|
|
device.write_frame(frame)?;
|
|
|
|
}
|
2023-06-03 13:21:36 +00:00
|
|
|
|
|
|
|
println!("Exiting, stoping device.");
|
2023-06-01 21:11:40 +00:00
|
|
|
device.stop()?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_next_frame(
|
|
|
|
speed: u32,
|
2023-06-03 13:21:36 +00:00
|
|
|
rs: &mut RedisCtrl
|
2023-06-01 21:11:40 +00:00
|
|
|
) -> Result<Frame, Box<dyn std::error::Error>> {
|
2023-06-03 13:21:36 +00:00
|
|
|
|
|
|
|
let line = rs.get("/pl/0/0")?;
|
2023-06-01 21:11:40 +00:00
|
|
|
let line : Vec<Point> = line.iter()
|
|
|
|
.map(tuple_to_point)
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let mut line2 = vec![];
|
|
|
|
while line2.len() < 48 {
|
|
|
|
for p in &line {
|
|
|
|
line2.push(*p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(Frame::new(speed, line2))
|
|
|
|
}
|
|
|
|
|
|
|
|
fn tuple_to_point(tpl: &(f32,f32,u32)) -> Point {
|
|
|
|
let (x, y, col) = tpl;
|
|
|
|
|
2023-06-03 13:21:36 +00:00
|
|
|
let r = (col >> 16) as u8 ;
|
|
|
|
let g = ((col >> 8) & 255) as u8 ;
|
|
|
|
let b = (col & 255) as u8 ;
|
2023-06-01 21:11:40 +00:00
|
|
|
|
|
|
|
let x = CENTER.0 + *x as u16;
|
|
|
|
let y = CENTER.1 + *y as u16;
|
|
|
|
|
|
|
|
if x >= 4096 || y >= 4096 {
|
|
|
|
println!("WARN: coordinate out of range: {} {}", x, y);
|
|
|
|
}
|
|
|
|
let x = x.clamp(0, 4095);
|
|
|
|
let y = y.clamp(0, 4095);
|
|
|
|
|
|
|
|
Point {
|
|
|
|
coordinate: (x, y).into(),
|
|
|
|
color: Color::new(r, g, b),
|
|
|
|
intensity: 0xFF
|
|
|
|
}
|
|
|
|
}
|