This commit is contained in:
alban 2023-07-06 22:18:44 +02:00
parent 538f13f539
commit 76cc1c1275
4 changed files with 116 additions and 1 deletions

View File

@ -10,6 +10,7 @@ chrono = "0.4.26"
config = "0.13.3" config = "0.13.3"
ctrlc = "3.4.0" ctrlc = "3.4.0"
env_logger = "0.10.0" env_logger = "0.10.0"
ether-dream = "0.2.5"
helios-dac = { version = "0.1", default-features = false, features = ["native"] } helios-dac = { version = "0.1", default-features = false, features = ["native"] }
log = "0.4.18" log = "0.4.18"

View File

@ -29,3 +29,8 @@ y = 2000
[[transformers]] [[transformers]]
[transformers.replicate] [transformers.replicate]
Until = 48 Until = 48
# Never remove this : this is mandatory
[[transformers]]
[transformers.intensity]

View File

@ -1,6 +1,7 @@
mod helios; mod helios;
mod dummy; mod dummy;
mod etherdream;
use std::fmt; use std::fmt;
use crate::conf::{Conf, DacFamily /*EtherDreamConf, HeliosConf*/}; use crate::conf::{Conf, DacFamily /*EtherDreamConf, HeliosConf*/};
@ -35,7 +36,7 @@ impl fmt::Display for PlaybackState {
} }
} }
#[derive(Debug)] #[derive(Debug, Default )]
pub struct Status { pub struct Status {
pub last_traced_at: String, pub last_traced_at: String,
pub properties: Vec<String>, pub properties: Vec<String>,

108
src/device/etherdream.rs Normal file
View File

@ -0,0 +1,108 @@
use ether_dream::{dac};
use crate::conf::EtherDreamConf;
use crate::device::{Device, Status, PlaybackState};
use crate::errors::{LJError, LJResult};
use crate::point::Point;
use chrono::Utc;
pub struct EtherdreamDevice {
pub conf: EtherDreamConf,
dac: dac,
sent_points: u16,
state: PlaybackState,
lack: String,
last_traced_at : String
}
impl EtherdreamDevice {
pub fn new(conf: &EtherDreamConf) -> LJResult<Self> {
let id = conf.id;
// // Todo : use the config
// let (dac_broadcast, source_addr) = ether_dream::recv_dac_broadcasts()
// .expect("failed to bind to UDP socket")
// .filter_map(Result::ok)
// .next()
// .unwrap();
// let mac_address = dac::MacAddress(dac_broadcast.mac_address);
//
// println!(
// "Discovered DAC \"{}\" at \"{}\"! Connecting...",
// mac_address, source_addr
// );
// Establish the TCP connection.
let mut stream = dac::stream::connect(&dac_broadcast, source_addr.ip().clone()).unwrap();
// If we want to create an animation (in our case a moving sine wave) we need a frame rate.
let frames_per_second = 60.0;
// Lets use the DAC at an eighth the maximum scan rate.
let points_per_second = stream.dac().max_point_rate / 32;
// Determine the number of points per frame given our target frame and point rates.
let points_per_frame = (points_per_second as f32 / frames_per_second) as u16;
// Prepare the DAC's playback engine and await the repsonse.
stream
.queue_commands()
.prepare_stream()
.submit()
.err()
.map(|err| {
eprintln!(
"err occurred when submitting PREPARE_STREAM \
command and listening for response: {}",
err
);
});
println!("Ready for playback!");
Ok(Self {
conf: (*conf).clone(),
dac,
sent_points: 0,
state: PlaybackState::PREPARE,
lack: "".to_string(),
last_traced_at: "1985-04-12T23:20:50.52Z".to_string()
})
}
}
impl Device for EtherdreamDevice {
fn status(&self) -> Status {
let lack = self.lack.clone();
Status {
last_traced_at: self.last_traced_at.clone(),
properties: vec!["foo".to_string()],
playback_state: self.state,
capacity: self.sent_points,
lack,
}
}
fn draw(&mut self,
line: Vec<Point>,
speed: u32,
) -> LJResult<()> {
self.state = PlaybackState::IDLE;
while let Ok(DeviceStatus::NotReady) = self.dac.status() {}
self.state = PlaybackState::PLAYING;
let points: Vec<helios_dac::Point> = line.into_iter().map(|p| p.into()).collect();
let frame = Frame::new(speed, points.clone());
self.dac.write_frame(frame.clone())?;
self.sent_points = points.len() as u16;
self.last_traced_at = Utc::now().to_rfc3339();
Ok(())
}
fn stop(&mut self) -> LJResult<()> {
self.dac.stop()?;
Ok(())
}
}