fix: etherdream should work with device trait adjustments
This commit is contained in:
parent
6f04925ea5
commit
514f4cc7c9
@ -42,7 +42,7 @@ pub struct Status {
|
|||||||
pub last_traced_at: String,
|
pub last_traced_at: String,
|
||||||
pub properties: Vec<String>,
|
pub properties: Vec<String>,
|
||||||
pub playback_state: PlaybackState,
|
pub playback_state: PlaybackState,
|
||||||
pub capacity: u16,
|
pub capacity: usize,
|
||||||
pub lack: String,
|
pub lack: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
use std::time;
|
#[warn(unused_imports)]
|
||||||
|
use log::{ debug, info, warn};
|
||||||
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
use std::thread::sleep;
|
||||||
use ether_dream::dac::stream::{CommunicationError, connect};
|
use ether_dream::dac::stream::{CommunicationError, connect};
|
||||||
use ether_dream::dac::{Playback, Stream};
|
use ether_dream::dac::{Playback, Stream};
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
use std::time::SystemTime;
|
use std::time;
|
||||||
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
use crate::conf::EtherDreamConf;
|
use crate::conf::EtherDreamConf;
|
||||||
use crate::device::{Device, Status, PlaybackState};
|
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, DacResponse};
|
use ether_dream::protocol::{DacBroadcast, DacResponse};
|
||||||
use log::{debug, info, warn};
|
|
||||||
|
|
||||||
#[warn(dead_code)]
|
#[warn(dead_code)]
|
||||||
pub struct EtherdreamDevice {
|
pub struct EtherdreamDevice {
|
||||||
@ -114,14 +118,20 @@ impl EtherdreamDevice {
|
|||||||
Ok(stream)
|
Ok(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn points_capacity(&self) -> u16 {
|
fn points_capacity(&self) -> usize {
|
||||||
/***
|
/***
|
||||||
Determine the number of points needed to fill the DAC.
|
Determine the number of points needed to fill the DAC.
|
||||||
***/
|
***/
|
||||||
// Fixme thread 'main' panicked at 'attempt to subtract with overflow', src/device/etherdream.rs:144:24
|
// Fixme thread 'main' panicked at 'attempt to subtract with overflow', src/device/etherdream.rs:144:24
|
||||||
let n_points = self.dac.buffer_capacity as u16 - self.stream.dac().dac.status.buffer_fullness as u16 - 1;
|
let n_points = self.dac.buffer_capacity as usize - self.stream.dac().dac.status.buffer_fullness as usize - 1;
|
||||||
n_points
|
n_points
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ping(&mut self) -> LJResult<()> {
|
||||||
|
|
||||||
|
Ok(self.stream.queue_commands().ping().submit()?)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Device for EtherdreamDevice {
|
impl Device for EtherdreamDevice {
|
||||||
@ -135,37 +145,46 @@ impl Device for EtherdreamDevice {
|
|||||||
let now: DateTime<Utc> = now.into();
|
let now: DateTime<Utc> = now.into();
|
||||||
let now = now.to_rfc3339();
|
let now = now.to_rfc3339();
|
||||||
|
|
||||||
let status = Status {
|
Status {
|
||||||
last_traced_at: now,
|
last_traced_at: now,
|
||||||
properties: vec!["foo".to_string()],
|
properties: vec!["foo".to_string()],
|
||||||
playback_state,
|
playback_state,
|
||||||
capacity: self.points_capacity(),
|
capacity: self.points_capacity(),
|
||||||
lack: self.dac_response.to_string(),
|
lack: self.dac_response.to_string(),
|
||||||
};
|
}
|
||||||
// debug!("Dac Status: {:?} ", status );
|
// debug!("Dac Status: {:?} ", status );
|
||||||
// debug!("Etherdream Dac {:?} ", self.dac );
|
// debug!("Etherdream Dac {:?} ", self.dac );
|
||||||
debug!("Stream dac{:?}", self.stream.dac());
|
// debug!("Stream dac{:?}", self.stream.dac());
|
||||||
status
|
// status
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(&mut self,
|
fn draw(&mut self,
|
||||||
line: Vec<Point>,
|
line: Vec<Point>,
|
||||||
_speed: u32,
|
_speed: u32,
|
||||||
) -> LJResult<()> {
|
) -> LJResult<()> {
|
||||||
let n_points = self.points_capacity();
|
let chunk_size = 64;
|
||||||
// let n_points = &line.len();
|
let points_iter = line.into_iter();
|
||||||
debug!("Etherdream::device draw Generating {:?} points", n_points);
|
for chunk in points_iter.as_slice().chunks(chunk_size){
|
||||||
|
debug!("New chunk length: {:?}", chunk.len());
|
||||||
|
loop {
|
||||||
|
let capacity = self.points_capacity();
|
||||||
|
if chunk.len() > capacity as usize {
|
||||||
|
debug!("Sleep, capacity : {:?}", capacity);
|
||||||
|
// Sleep for 1/100th of a sec
|
||||||
|
sleep(Duration::new( 0, 10000000));
|
||||||
|
self.ping();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug!("drawing");
|
||||||
match self.stream
|
match self.stream
|
||||||
.queue_commands()
|
.queue_commands()
|
||||||
.data(
|
.data(
|
||||||
line.into_iter()
|
chunk.into_iter()
|
||||||
.map(|point| point.into())
|
.map(|point| (*point).into())
|
||||||
.take(n_points as usize)
|
.take(chunk_size as usize)
|
||||||
)
|
)
|
||||||
// .data(sine_wave.by_ref().take(n_points as usize))
|
|
||||||
|
|
||||||
.submit() {
|
.submit() {
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
// We should account for
|
// We should account for
|
||||||
@ -188,9 +207,10 @@ impl Device for EtherdreamDevice {
|
|||||||
}
|
}
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.dac_response = DacResponse::ACK;
|
self.dac_response = DacResponse::ACK;
|
||||||
debug!("Draw is ok");
|
// debug!("Draw is ok");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -274,7 +294,7 @@ impl Iterator for SineWave {
|
|||||||
u1,
|
u1,
|
||||||
u2,
|
u2,
|
||||||
};
|
};
|
||||||
debug!("{:?}",p);
|
// debug!("{:?}",p);
|
||||||
self.point += 1;
|
self.point += 1;
|
||||||
Some(p)
|
Some(p)
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ impl Device for HeliosDevice {
|
|||||||
last_traced_at: self.last_traced_at.clone(),
|
last_traced_at: self.last_traced_at.clone(),
|
||||||
properties: vec!["foo".to_string()],
|
properties: vec!["foo".to_string()],
|
||||||
playback_state: self.state,
|
playback_state: self.state,
|
||||||
capacity: self.sent_points,
|
capacity: self.sent_points as usize,
|
||||||
lack,
|
lack,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user