fix: various fixes for etherdream and debug
This commit is contained in:
parent
fd9ad62278
commit
4a87821c22
16
README.md
16
README.md
@ -0,0 +1,16 @@
|
||||
# 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
|
||||
|
||||
```
|
@ -1,4 +1,4 @@
|
||||
# file: Settings.toml
|
||||
# file: settings.toml
|
||||
# Rename me !
|
||||
|
||||
# The main key of your laser in LJ
|
||||
@ -12,11 +12,11 @@ redis_url = "redis://127.0.0.1:6379/"
|
||||
|
||||
# Either Helios or Etherdream
|
||||
# For Helios. USB Device Id of the DAC
|
||||
[dac.helios]
|
||||
id = 0
|
||||
#[dac.helios]
|
||||
#id = 0
|
||||
|
||||
# For dummy dac:
|
||||
# [dac.dummy]
|
||||
[dac.dummy]
|
||||
|
||||
# For Etherdream. IP of the DAC
|
||||
# [dac.etherdream]
|
||||
@ -26,6 +26,7 @@ id = 0
|
||||
[transformers.translate]
|
||||
x = 2000
|
||||
y = 2000
|
||||
|
||||
[[transformers]]
|
||||
[transformers.replicate]
|
||||
Until = 48
|
||||
|
@ -8,7 +8,7 @@ use crate::device::{Device, Status, PlaybackState};
|
||||
use crate::errors::{LJError, LJResult};
|
||||
use crate::point::{Color, Point};
|
||||
use ether_dream::protocol::{DacBroadcast, DacStatus};
|
||||
use log::info;
|
||||
use log::{info, warn};
|
||||
|
||||
#[warn(dead_code)]
|
||||
pub struct EtherdreamDevice {
|
||||
@ -38,20 +38,26 @@ impl EtherdreamDevice {
|
||||
pub fn get_dac(conf: &EtherDreamConf) -> LJResult<(DacBroadcast, SocketAddr, Stream)> {
|
||||
let ip = &conf.ip;
|
||||
let dac_broadcast = ether_dream::recv_dac_broadcasts()?;
|
||||
dac_broadcast.set_nonblocking(true)?;
|
||||
dac_broadcast.set_timeout(Some(time::Duration::new(60, 30)))?;
|
||||
dac_broadcast.set_timeout(Some(time::Duration::new(10, 0)))?;
|
||||
info!("Attempting to get DAC broadcast...");
|
||||
let broadcast = dac_broadcast
|
||||
.filter_map(|result| {
|
||||
info!("Received new broadcast {:?}", result);
|
||||
if result.is_err() { return None; }
|
||||
let (dac, source_addr) = result.unwrap();
|
||||
if source_addr.is_ipv6() { return None; }
|
||||
if source_addr.ip().to_string() != ip.clone() { return None; }
|
||||
info!("Valid broadcast");
|
||||
Some(Ok((dac, source_addr)))
|
||||
match result {
|
||||
Err(err) => {
|
||||
warn!( "Failed to find a valid DAC via broadcast. Error: {:?}", err);
|
||||
info!( "Retrying...");
|
||||
None
|
||||
},
|
||||
Ok((dac, source_addr)) => {
|
||||
if source_addr.is_ipv6() { return None; }
|
||||
if &source_addr.ip().to_string() != ip { return None; }
|
||||
info!("Valid broadcast");
|
||||
Some(Ok((dac, source_addr)))
|
||||
}
|
||||
}
|
||||
})
|
||||
.next()
|
||||
.ok_or(LJError::EtherdreamError("Failed to receive broadcast".to_string()))?;
|
||||
.expect("Failed to receive broadcast.");
|
||||
match broadcast {
|
||||
Err(err) => {
|
||||
Err(Box::new(LJError::EtherdreamConnectError(err)))
|
||||
|
@ -11,7 +11,6 @@ pub enum LJError {
|
||||
RedisConnect(RedisError),
|
||||
HeliosDeviceMissing,
|
||||
BadEDH,
|
||||
EtherdreamError(String),
|
||||
EtherdreamConnectError(io::Error),
|
||||
}
|
||||
|
||||
@ -32,9 +31,6 @@ impl fmt::Display for LJError {
|
||||
BadEDH => {
|
||||
write!(f, "EDH matrix is not a 3x3 matrix")
|
||||
}
|
||||
EtherdreamError(msg) => {
|
||||
write!(f, "Unexpected Etherdream device error: {msg}")
|
||||
}
|
||||
EtherdreamConnectError(err) => {
|
||||
write!(f, "Failed to retrieve Etherdream device: {err}")
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ fn run_all() -> LJResult<()> {
|
||||
// Setup Redis Service
|
||||
let mut rs = RedisCtrl::new(&config.redis_url, &config.laser_id)?;
|
||||
|
||||
let mut world_state = rs.init_world_state()?;
|
||||
let mut world_state = rs.init_world_state().unwrap();
|
||||
info!("WorldState: {:?}", world_state);
|
||||
|
||||
// Setup handler for interrupt Signals
|
||||
|
@ -101,10 +101,10 @@ impl RedisCtrl {
|
||||
|
||||
pub fn init_world_state( &mut self) -> LJResult<WorldState>{
|
||||
Ok(WorldState {
|
||||
client_key: self.get_client_key()?,
|
||||
edh: self.get_edh()?,
|
||||
kpps: self.get_int("kpps")?.try_into()?,
|
||||
intensity: self.get_int("intensity")?.try_into()?,
|
||||
client_key: self.get_client_key().unwrap(),
|
||||
edh: self.get_edh().unwrap(),
|
||||
kpps: self.get_int("kpps").unwrap().try_into().unwrap(),
|
||||
intensity: self.get_int("intensity").unwrap().try_into().unwrap(),
|
||||
..WorldState::default()
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user