Compare commits

..

No commits in common. "f7f5c00d0faea735886f37efec8b37d3306fe742" and "4d5a19d0546db13be6a23925f944080dab55afb4" have entirely different histories.

3 changed files with 24 additions and 59 deletions

View File

@ -6,7 +6,6 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
ctrlc = "3.4.0"
helios-dac = { version = "0.1", default-features = false, features = ["native"] } helios-dac = { version = "0.1", default-features = false, features = ["native"] }
redis = "0.23.0" redis = "0.23.0"
ron = "0.8.0" ron = "0.8.0"

View File

@ -3,31 +3,30 @@
/// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md /// https://github.com/Grix/helios_dac/blob/master/docs/udev_rules_for_linux.md
/// ///
mod redis_ctrl;
use helios_dac::{Frame, use helios_dac::{Frame,
Point, Point,
DeviceStatus, DeviceStatus,
// Coordinate, // Coordinate,
Color}; Color};
use helios_dac::NativeHeliosDacController;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use redis_ctrl::RedisCtrl; use redis::{ //RedisResult,
Client,
Connection,
Commands
};
use ron::de::from_str;
type Line = Vec<(f32,f32,u32)>;
const CENTER : (u16,u16) = (2000, 2000); const CENTER : (u16,u16) = (2000, 2000);
pub fn main() -> Result<(), Box<dyn std::error::Error>> { pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let running = Arc::new(AtomicBool::new(true)); use helios_dac::NativeHeliosDacController;
let r = running.clone();
ctrlc::set_handler(move || { let client = Client::open("redis://127.0.0.1/")?;
r.store(false, Ordering::SeqCst); let mut con = client.get_connection()?;
}).expect("Error setting Ctrl-C handler");
let mut rs = RedisCtrl::new()?;
let controller = NativeHeliosDacController::new()?; let controller = NativeHeliosDacController::new()?;
let devices = controller.list_devices()?; let devices = controller.list_devices()?;
@ -35,25 +34,24 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
let device = devices.into_iter().next().unwrap(); let device = devices.into_iter().next().unwrap();
let mut device = device.open()?; let mut device = device.open()?;
while running.load(Ordering::SeqCst) { for _ in 0..100 {
let frame = get_next_frame(1000, &mut rs)?; let frame = get_next_frame(1000, &mut con)?;
while let Ok(DeviceStatus::NotReady) = device.status() { while let Ok(DeviceStatus::NotReady) = device.status() {
} }
device.write_frame(frame)?; device.write_frame(frame)?;
} }
println!("Exiting, stoping device.");
device.stop()?; device.stop()?;
Ok(()) Ok(())
} }
fn get_next_frame( fn get_next_frame(
speed: u32, speed: u32,
rs: &mut RedisCtrl con: &mut Connection
) -> Result<Frame, Box<dyn std::error::Error>> { ) -> Result<Frame, Box<dyn std::error::Error>> {
let val : String = con.get("/pl/0/0")?;
let line = rs.get("/pl/0/0")?; let line : Line = from_str(&val)?;
let line : Vec<Point> = line.iter() let line : Vec<Point> = line.iter()
.map(tuple_to_point) .map(tuple_to_point)
.collect(); .collect();

View File

@ -1,32 +0,0 @@
use redis::{
Client,
Connection,
Commands
};
use ron::de::from_str;
pub type Line = Vec<(f32,f32,u32)>;
pub struct RedisCtrl {
pub client: Client,
pub connection: Connection
}
impl RedisCtrl {
pub fn new() -> Result<Self, Box<dyn std::error::Error>> {
let client = Client::open("redis://127.0.0.1/")?;
let connection = client.get_connection()?;
Ok(RedisCtrl { client, connection })
}
pub fn get(
&mut self,
key: &str
) -> Result<Line, Box<dyn std::error::Error>> {
let val : String = self.connection.get(key)?;
let line : Line = from_str(&val)?;
Ok(line)
}
}