fix: dac/etherdream should work
This commit is contained in:
parent
810a3677de
commit
f45b9e5748
@ -70,6 +70,7 @@ fn main() {
|
|||||||
err
|
err
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
eprintln!("Stream dac{:?}", stream.dac());
|
||||||
|
|
||||||
// Loop and continue to send points forever.
|
// Loop and continue to send points forever.
|
||||||
loop {
|
loop {
|
||||||
|
@ -71,6 +71,7 @@ impl EtherdreamDevice {
|
|||||||
Err(Box::new(LJError::EtherdreamConnectError(err)))
|
Err(Box::new(LJError::EtherdreamConnectError(err)))
|
||||||
}
|
}
|
||||||
Ok((dac, source_addr)) => {
|
Ok((dac, source_addr)) => {
|
||||||
|
info!("Trying to open TCP stream...");
|
||||||
let stream = EtherdreamDevice::get_tcp_stream(&dac, &source_addr)?;
|
let stream = EtherdreamDevice::get_tcp_stream(&dac, &source_addr)?;
|
||||||
info!("Finished configuring DAC and TCP stream.");
|
info!("Finished configuring DAC and TCP stream.");
|
||||||
Ok((dac, source_addr, stream))
|
Ok((dac, source_addr, stream))
|
||||||
@ -87,18 +88,29 @@ impl EtherdreamDevice {
|
|||||||
Err(err) => warn!("err occurred when submitting PREPARE_STREAM command and listening for response: {}",err),
|
Err(err) => warn!("err occurred when submitting PREPARE_STREAM command and listening for response: {}",err),
|
||||||
Ok(_) => info!("Prepared Stream.")
|
Ok(_) => info!("Prepared Stream.")
|
||||||
}
|
}
|
||||||
let begin_list = vec![
|
// If we want to create an animation (in our case a moving sine wave) we need a frame rate.
|
||||||
DacPoint { control: 0, x: 0, y: 0, i: 255, r: 0, g: 0, b: 0, u1: 0, u2: 0 },
|
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;
|
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;
|
||||||
|
|
||||||
|
let mut sine_wave = SineWave {
|
||||||
|
point: 0,
|
||||||
|
points_per_frame,
|
||||||
|
frames_per_second,
|
||||||
|
};
|
||||||
|
|
||||||
match stream
|
match stream
|
||||||
.queue_commands()
|
.queue_commands()
|
||||||
.data(begin_list.into_iter().take(1 as usize))
|
.data(sine_wave.by_ref().take(400))
|
||||||
|
// .data(begin_list.into_iter().take(400 as usize))
|
||||||
.begin(0, points_per_second)
|
.begin(0, points_per_second)
|
||||||
.submit() {
|
.submit() {
|
||||||
Err(err) => warn!("err occurred when submitting first data: {}",err),
|
Err(err) => warn!("err occurred when submitting first data: {}",err),
|
||||||
Ok(_) => info!("Sent first data to Etherdream.")
|
Ok(_) => info!("Sent first data to Etherdream.")
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(stream)
|
Ok(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,9 +142,9 @@ impl Device for EtherdreamDevice {
|
|||||||
capacity: self.points_capacity(),
|
capacity: self.points_capacity(),
|
||||||
lack: self.dac_response.to_string(),
|
lack: self.dac_response.to_string(),
|
||||||
};
|
};
|
||||||
// info!("Dac Status: {:?} ", status );
|
// debug!("Dac Status: {:?} ", status );
|
||||||
// info!("Etherdream Dac {:?} ", self.dac );
|
// debug!("Etherdream Dac {:?} ", self.dac );
|
||||||
// info!("Stream dac{:?}", self.stream.dac());
|
debug!("Stream dac{:?}", self.stream.dac());
|
||||||
status
|
status
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +155,17 @@ impl Device for EtherdreamDevice {
|
|||||||
let n_points = self.points_capacity();
|
let n_points = self.points_capacity();
|
||||||
// let n_points = &line.len();
|
// let n_points = &line.len();
|
||||||
debug!("Etherdream::device draw Generating {:?} points", n_points);
|
debug!("Etherdream::device draw Generating {:?} points", n_points);
|
||||||
|
let frames_per_second = 60.0;
|
||||||
|
// Lets use the DAC at an eighth the maximum scan rate.
|
||||||
|
let points_per_second = self.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;
|
||||||
|
|
||||||
|
let mut sine_wave = SineWave {
|
||||||
|
point: 0,
|
||||||
|
points_per_frame,
|
||||||
|
frames_per_second,
|
||||||
|
};
|
||||||
match self.stream
|
match self.stream
|
||||||
.queue_commands()
|
.queue_commands()
|
||||||
.data(
|
.data(
|
||||||
@ -151,6 +174,8 @@ impl Device for EtherdreamDevice {
|
|||||||
// .take(line.len() as usize)
|
// .take(line.len() as usize)
|
||||||
.take(n_points as usize)
|
.take(n_points 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
|
||||||
@ -170,7 +195,6 @@ impl Device for EtherdreamDevice {
|
|||||||
err.response.response
|
err.response.response
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
self.dac_response = DacResponse::ACK;
|
self.dac_response = DacResponse::ACK;
|
||||||
@ -220,3 +244,53 @@ impl Device for EtherdreamDevice {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine the number of points needed to fill the DAC.
|
||||||
|
fn points_to_generate(dac: ðer_dream::dac::Dac) -> usize {
|
||||||
|
dac.buffer_capacity as usize - 1 - dac.status.buffer_fullness as usize
|
||||||
|
}
|
||||||
|
|
||||||
|
// An iterator that endlessly generates a sine wave of DAC points.
|
||||||
|
//
|
||||||
|
// The sine wave oscillates at a rate of once per second.
|
||||||
|
struct SineWave {
|
||||||
|
point: u32,
|
||||||
|
points_per_frame: u16,
|
||||||
|
frames_per_second: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Iterator for SineWave {
|
||||||
|
type Item = ether_dream::protocol::DacPoint;
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
let coloured_points_per_frame = self.points_per_frame - 1;
|
||||||
|
let i = (self.point % self.points_per_frame as u32) as u16;
|
||||||
|
let hz = 1.0;
|
||||||
|
let fract = i as f32 / coloured_points_per_frame as f32;
|
||||||
|
let phase = (self.point as f32 / coloured_points_per_frame as f32) / self.frames_per_second;
|
||||||
|
let amp = (hz * (fract + phase) * 2.0 * std::f32::consts::PI).sin();
|
||||||
|
let (r, g, b) = match i {
|
||||||
|
i if i == coloured_points_per_frame || i < 13 => (0, 0, 0),
|
||||||
|
_ => (std::u16::MAX, std::u16::MAX, std::u16::MAX),
|
||||||
|
};
|
||||||
|
let x_min = std::i16::MIN;
|
||||||
|
let x_max = std::i16::MAX;
|
||||||
|
let x = (x_min as f32 + fract * (x_max as f32 - x_min as f32)) as i16;
|
||||||
|
let y = (amp * x_max as f32) as i16;
|
||||||
|
let control = 0;
|
||||||
|
let (u1, u2) = (0, 0);
|
||||||
|
let p = ether_dream::protocol::DacPoint {
|
||||||
|
control,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
i,
|
||||||
|
r,
|
||||||
|
g,
|
||||||
|
b,
|
||||||
|
u1,
|
||||||
|
u2,
|
||||||
|
};
|
||||||
|
debug!("{:?}",p);
|
||||||
|
self.point += 1;
|
||||||
|
Some(p)
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
use ether_dream::protocol::DacPoint;
|
use ether_dream::protocol::DacPoint;
|
||||||
|
use log::debug;
|
||||||
|
|
||||||
fn clamp(val: f32, min: f32, max: f32) -> f32 {
|
fn clamp(val: f32, min: f32, max: f32) -> f32 {
|
||||||
if val < min {
|
if val < min {
|
||||||
@ -67,9 +68,9 @@ impl From<Point> for DacPoint {
|
|||||||
x: x as i16,
|
x: x as i16,
|
||||||
y: y as i16,
|
y: y as i16,
|
||||||
i,
|
i,
|
||||||
r: pt.color.r.into(),
|
r: (pt.color.r as u16) * 255,
|
||||||
g: pt.color.g.into(),
|
g: (pt.color.g as u16) * 255,
|
||||||
b: pt.color.b.into(),
|
b: (pt.color.b as u16) * 255,
|
||||||
u1,
|
u1,
|
||||||
u2,
|
u2,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user