Compare commits

..

No commits in common. "4a87821c22264078c892ec12dd4999d15db867a3" and "60121a01c263a7c8ba84edd75b6d376acade61b1" have entirely different histories.

7 changed files with 24 additions and 67 deletions

View File

@ -1,16 +0,0 @@
# LJ rust
## Crashcourse
```shell
# Copy and edit the settings file
$ cp copyme.settings.toml settings.toml
# Populate the redis database
$ cargo run --example populate_redis
# Run
$ cargo run --release
```

View File

@ -1,4 +1,4 @@
# file: settings.toml # file: Settings.toml
# Rename me ! # Rename me !
# The main key of your laser in LJ # The main key of your laser in LJ
@ -12,11 +12,11 @@ redis_url = "redis://127.0.0.1:6379/"
# Either Helios or Etherdream # Either Helios or Etherdream
# For Helios. USB Device Id of the DAC # For Helios. USB Device Id of the DAC
#[dac.helios] [dac.helios]
#id = 0 id = 0
# For dummy dac: # For dummy dac:
[dac.dummy] # [dac.dummy]
# For Etherdream. IP of the DAC # For Etherdream. IP of the DAC
# [dac.etherdream] # [dac.etherdream]
@ -26,7 +26,6 @@ redis_url = "redis://127.0.0.1:6379/"
[transformers.translate] [transformers.translate]
x = 2000 x = 2000
y = 2000 y = 2000
[[transformers]] [[transformers]]
[transformers.replicate] [transformers.replicate]
Until = 48 Until = 48

View File

@ -1,24 +0,0 @@
///
/// $ cargo run --example populate_redis
///
use redis::{
//RedisResult,
Client,
Commands,
Connection,
};
fn do_something() -> redis::RedisResult<()> {
let client = Client::open("redis://127.0.0.1/")?;
let mut con: Connection = client.get_connection()?;
let _ = con.set("/clientkey", "/pl/0/")?;
let _ = con.set("/EDH/0", "[[1.0, 0.0, 0.0],\n [ 0.0, 1.0, 0.0],\n [ 0.0, 0.0, 1.0]]")?;
let _ = con.set("/kpps/0", "5000")?;
let _ = con.set("/intensity/0", "255")?;
Ok(())
}
fn main() {
_ = do_something();
}

View File

@ -8,7 +8,7 @@ use crate::device::{Device, Status, PlaybackState};
use crate::errors::{LJError, LJResult}; use crate::errors::{LJError, LJResult};
use crate::point::{Color, Point}; use crate::point::{Color, Point};
use ether_dream::protocol::{DacBroadcast, DacStatus}; use ether_dream::protocol::{DacBroadcast, DacStatus};
use log::{info, warn}; use log::info;
#[warn(dead_code)] #[warn(dead_code)]
pub struct EtherdreamDevice { pub struct EtherdreamDevice {
@ -38,26 +38,20 @@ impl EtherdreamDevice {
pub fn get_dac(conf: &EtherDreamConf) -> LJResult<(DacBroadcast, SocketAddr, Stream)> { pub fn get_dac(conf: &EtherDreamConf) -> LJResult<(DacBroadcast, SocketAddr, Stream)> {
let ip = &conf.ip; let ip = &conf.ip;
let dac_broadcast = ether_dream::recv_dac_broadcasts()?; let dac_broadcast = ether_dream::recv_dac_broadcasts()?;
dac_broadcast.set_timeout(Some(time::Duration::new(10, 0)))?; dac_broadcast.set_nonblocking(true)?;
info!("Attempting to get DAC broadcast..."); dac_broadcast.set_timeout(Some(time::Duration::new(60, 30)))?;
let broadcast = dac_broadcast let broadcast = dac_broadcast
.filter_map(|result| { .filter_map(|result| {
match result { info!("Received new broadcast {:?}", result);
Err(err) => { if result.is_err() { return None; }
warn!( "Failed to find a valid DAC via broadcast. Error: {:?}", err); let (dac, source_addr) = result.unwrap();
info!( "Retrying...");
None
},
Ok((dac, source_addr)) => {
if source_addr.is_ipv6() { return None; } if source_addr.is_ipv6() { return None; }
if &source_addr.ip().to_string() != ip { return None; } if source_addr.ip().to_string() != ip.clone() { return None; }
info!("Valid broadcast"); info!("Valid broadcast");
Some(Ok((dac, source_addr))) Some(Ok((dac, source_addr)))
}
}
}) })
.next() .next()
.expect("Failed to receive broadcast."); .ok_or(LJError::EtherdreamError("Failed to receive broadcast".to_string()))?;
match broadcast { match broadcast {
Err(err) => { Err(err) => {
Err(Box::new(LJError::EtherdreamConnectError(err))) Err(Box::new(LJError::EtherdreamConnectError(err)))

View File

@ -11,6 +11,7 @@ pub enum LJError {
RedisConnect(RedisError), RedisConnect(RedisError),
HeliosDeviceMissing, HeliosDeviceMissing,
BadEDH, BadEDH,
EtherdreamError(String),
EtherdreamConnectError(io::Error), EtherdreamConnectError(io::Error),
} }
@ -31,6 +32,9 @@ impl fmt::Display for LJError {
BadEDH => { BadEDH => {
write!(f, "EDH matrix is not a 3x3 matrix") write!(f, "EDH matrix is not a 3x3 matrix")
} }
EtherdreamError(msg) => {
write!(f, "Unexpected Etherdream device error: {msg}")
}
EtherdreamConnectError(err) => { EtherdreamConnectError(err) => {
write!(f, "Failed to retrieve Etherdream device: {err}") write!(f, "Failed to retrieve Etherdream device: {err}")
} }

View File

@ -50,7 +50,7 @@ fn run_all() -> LJResult<()> {
// Setup Redis Service // Setup Redis Service
let mut rs = RedisCtrl::new(&config.redis_url, &config.laser_id)?; let mut rs = RedisCtrl::new(&config.redis_url, &config.laser_id)?;
let mut world_state = rs.init_world_state().unwrap(); let mut world_state = rs.init_world_state()?;
info!("WorldState: {:?}", world_state); info!("WorldState: {:?}", world_state);
// Setup handler for interrupt Signals // Setup handler for interrupt Signals

View File

@ -101,10 +101,10 @@ impl RedisCtrl {
pub fn init_world_state( &mut self) -> LJResult<WorldState>{ pub fn init_world_state( &mut self) -> LJResult<WorldState>{
Ok(WorldState { Ok(WorldState {
client_key: self.get_client_key().unwrap(), client_key: self.get_client_key()?,
edh: self.get_edh().unwrap(), edh: self.get_edh()?,
kpps: self.get_int("kpps").unwrap().try_into().unwrap(), kpps: self.get_int("kpps")?.try_into()?,
intensity: self.get_int("intensity").unwrap().try_into().unwrap(), intensity: self.get_int("intensity")?.try_into()?,
..WorldState::default() ..WorldState::default()
}) })
} }