fps stat per fixture driver & add separate display function for fps stats
This commit is contained in:
parent
253f125669
commit
768117ef65
7 changed files with 103 additions and 32 deletions
|
@ -35,26 +35,21 @@ impl Controller {
|
||||||
let inputs = self.inputs.read().unwrap();
|
let inputs = self.inputs.read().unwrap();
|
||||||
let lib = self.library.read().unwrap();
|
let lib = self.library.read().unwrap();
|
||||||
|
|
||||||
eprintln!("{}", termion::clear::All);
|
|
||||||
eprintln!("----------");
|
|
||||||
|
|
||||||
if inputs.active {
|
if inputs.active {
|
||||||
eprintln!("(ACTIVE)");
|
eprintln!("(ACTIVE)");
|
||||||
} else {
|
} else {
|
||||||
eprintln!("(FROZEN)");
|
eprintln!("(FROZEN)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(scene) = lib.get(inputs.scene_select) {
|
|
||||||
eprintln!("current animation: {}", scene.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
for si in 0..lib.len() {
|
for si in 0..lib.len() {
|
||||||
if let Some(scene) = lib.get(si) {
|
if let Some(scene) = lib.get(si) {
|
||||||
|
if si == inputs.scene_select {
|
||||||
|
eprintln!(">> {}({}) {} {} <<", termion::style::Bold, si, termion::style::Reset, scene.name());
|
||||||
|
} else {
|
||||||
eprintln!(" ({}) {} ", si, scene.name());
|
eprintln!(" ({}) {} ", si, scene.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
eprintln!("inputs:\n {:?}", inputs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_key(
|
pub fn handle_key(
|
||||||
|
|
|
@ -2,12 +2,18 @@ use {
|
||||||
prisma::{Rgb},
|
prisma::{Rgb},
|
||||||
cgmath::{Vector2},
|
cgmath::{Vector2},
|
||||||
std::boxed::Box,
|
std::boxed::Box,
|
||||||
crate::view::ColorGrid
|
crate::{
|
||||||
|
view::ColorGrid,
|
||||||
|
fpsstat::{FpsStat}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait FixtureDriver {
|
pub trait FixtureDriver {
|
||||||
fn send(&mut self, pixels: &Vec<Rgb<u8>>);
|
fn send(&mut self, pixels: &Vec<Rgb<u8>>);
|
||||||
fn sync(&mut self);
|
fn sync(&mut self);
|
||||||
|
|
||||||
|
fn connect_info(&self) -> String;
|
||||||
|
fn avg_fps(&self) -> f32;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Fixture {
|
pub struct Fixture {
|
||||||
|
@ -18,7 +24,7 @@ pub struct Fixture {
|
||||||
pub mirror_y: bool,
|
pub mirror_y: bool,
|
||||||
pub brightness: f32,
|
pub brightness: f32,
|
||||||
pub buffer: Vec< Rgb<u8> >,
|
pub buffer: Vec< Rgb<u8> >,
|
||||||
pub driver: Option<Box<dyn FixtureDriver>>
|
pub driver: Option<Box<dyn FixtureDriver>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Fixture {
|
impl Fixture {
|
||||||
|
|
30
src/fpsstat.rs
Normal file
30
src/fpsstat.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
|
||||||
|
use std::time::{Instant, Duration};
|
||||||
|
|
||||||
|
pub struct FpsStat {
|
||||||
|
frame_count: u64,
|
||||||
|
fps_sum_window: std::time::Instant,
|
||||||
|
pub avg_fps: f32
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FpsStat {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
FpsStat {
|
||||||
|
frame_count: 0,
|
||||||
|
fps_sum_window: std::time::Instant::now(),
|
||||||
|
avg_fps: 0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn refresh(&mut self) {
|
||||||
|
let tcur = std::time::Instant::now();
|
||||||
|
if (tcur - self.fps_sum_window).as_millis() > 5000 {
|
||||||
|
self.avg_fps = (1000.0 * self.frame_count as f32) / ((tcur - self.fps_sum_window).as_millis() as f32);
|
||||||
|
|
||||||
|
self.fps_sum_window = tcur;
|
||||||
|
self.frame_count = 0;
|
||||||
|
} else {
|
||||||
|
self.frame_count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,4 +46,18 @@ impl Default for Inputs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Inputs {
|
||||||
|
pub fn display(&self) {
|
||||||
|
eprintln!("transition: {:?}", self.transition_time);
|
||||||
|
eprintln!("cycle: {:?}", self.cycle_len);
|
||||||
|
eprintln!("wave peak: {:?}", self.wave_peak);
|
||||||
|
eprintln!("master wave: {:?}", self.master_wave);
|
||||||
|
eprintln!("master subdivision: {}", self.master_subdivision);
|
||||||
|
eprintln!("master intensity: {}", self.master_intensity);
|
||||||
|
eprintln!("wheel 1: {}", self.wheel);
|
||||||
|
eprintln!("wheel 2: {}", self.wheel2);
|
||||||
|
eprintln!("wheel 3: {}", self.wheel3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -22,6 +22,7 @@ mod stripe_driver;
|
||||||
mod jack;
|
mod jack;
|
||||||
mod waveform;
|
mod waveform;
|
||||||
mod controller;
|
mod controller;
|
||||||
|
mod fpsstat;
|
||||||
|
|
||||||
mod patterns;
|
mod patterns;
|
||||||
mod scene_library;
|
mod scene_library;
|
||||||
|
@ -82,8 +83,6 @@ async fn main() {
|
||||||
|
|
||||||
let mut controller = controller::Controller::new( scene_library, inputs.clone() );
|
let mut controller = controller::Controller::new( scene_library, inputs.clone() );
|
||||||
|
|
||||||
let mut frame_count = 0;
|
|
||||||
let mut fps_sum_window = std::time::Instant::now();
|
|
||||||
{
|
{
|
||||||
let inputs = controller.inputs.read().unwrap();
|
let inputs = controller.inputs.read().unwrap();
|
||||||
lighting_setup.advance(&(*inputs) );
|
lighting_setup.advance(&(*inputs) );
|
||||||
|
@ -100,16 +99,6 @@ async fn main() {
|
||||||
tcur + Duration::from_millis(25)
|
tcur + Duration::from_millis(25)
|
||||||
));
|
));
|
||||||
|
|
||||||
// FPS statistics
|
|
||||||
if (tcur - fps_sum_window).as_millis() > 5000 {
|
|
||||||
let avg_fps = (1000.0 * frame_count as f32) / ((tcur - fps_sum_window).as_millis() as f32);
|
|
||||||
eprintln!("avg fps: {}", avg_fps);
|
|
||||||
fps_sum_window = tcur;
|
|
||||||
frame_count = 0;
|
|
||||||
} else {
|
|
||||||
frame_count += 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// update animation
|
// update animation
|
||||||
let active = {
|
let active = {
|
||||||
let mut inputs = inputs.write().unwrap();
|
let mut inputs = inputs.write().unwrap();
|
||||||
|
@ -169,7 +158,14 @@ async fn main() {
|
||||||
controller.handle_key(
|
controller.handle_key(
|
||||||
event, &mut lighting_setup
|
event, &mut lighting_setup
|
||||||
);
|
);
|
||||||
|
|
||||||
|
eprintln!("{}", termion::clear::All);
|
||||||
|
eprintln!("----------");
|
||||||
controller.display();
|
controller.display();
|
||||||
|
inputs.read().unwrap().display();
|
||||||
|
eprintln!("----------");
|
||||||
|
lighting_setup.display();
|
||||||
|
eprintln!("----------");
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
26
src/setup.rs
26
src/setup.rs
|
@ -2,18 +2,19 @@ use {
|
||||||
crate::{
|
crate::{
|
||||||
fixture::Fixture,
|
fixture::Fixture,
|
||||||
inputs::Inputs,
|
inputs::Inputs,
|
||||||
view::{ColorGrid, Animation}
|
view::{ColorGrid, Animation},
|
||||||
|
fpsstat::{FpsStat}
|
||||||
},
|
},
|
||||||
cgmath::Vector2,
|
cgmath::Vector2,
|
||||||
std::time::Duration,
|
std::time::Duration,
|
||||||
std::sync::{Arc, RwLock}
|
std::sync::{Arc, RwLock},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct LightingSetup {
|
pub struct LightingSetup {
|
||||||
pub fixtures: Vec<Fixture>,
|
pub fixtures: Vec<Fixture>,
|
||||||
t: Arc<RwLock<Duration>>,
|
t: Arc<RwLock<Duration>>,
|
||||||
|
animation: Arc<RwLock<dyn Animation>>,
|
||||||
animation: Arc<RwLock<dyn Animation>>
|
pub preview_fpsstat: RwLock<FpsStat>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LightingSetup {
|
impl LightingSetup {
|
||||||
|
@ -22,7 +23,20 @@ impl LightingSetup {
|
||||||
LightingSetup {
|
LightingSetup {
|
||||||
fixtures,
|
fixtures,
|
||||||
t: t.clone(),
|
t: t.clone(),
|
||||||
animation
|
animation,
|
||||||
|
preview_fpsstat: RwLock::new(FpsStat::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn display(&self) {
|
||||||
|
println!("preview: {} fps", self.preview_fpsstat.read().unwrap().avg_fps);
|
||||||
|
for (i,fixture) in self.fixtures.iter().enumerate() {
|
||||||
|
if let Some(driver) = fixture.driver.as_ref() {
|
||||||
|
println!("F{} . ({}) {}", i, driver.connect_info(), driver.avg_fps());
|
||||||
|
} else {
|
||||||
|
println!("disconnected");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +73,8 @@ impl LightingSetup {
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32
|
height: u32
|
||||||
) {
|
) {
|
||||||
|
self.preview_fpsstat.write().unwrap().refresh();
|
||||||
|
|
||||||
// pixels per Unit
|
// pixels per Unit
|
||||||
let mindim = u32::min(width, height);
|
let mindim = u32::min(width, height);
|
||||||
let midx = width/2;
|
let midx = width/2;
|
||||||
|
|
|
@ -1,13 +1,17 @@
|
||||||
use {
|
use {
|
||||||
prisma::{Rgb},
|
prisma::{Rgb},
|
||||||
std::sync::{Arc, RwLock},
|
std::sync::{Arc, RwLock},
|
||||||
crate::fixture::FixtureDriver
|
crate::{
|
||||||
|
fixture::FixtureDriver,
|
||||||
|
fpsstat::FpsStat
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct StripeDriver {
|
pub struct StripeDriver {
|
||||||
socket: Arc<RwLock<std::net::UdpSocket>>,
|
socket: Arc<RwLock<std::net::UdpSocket>>,
|
||||||
timeout: usize,
|
timeout: usize,
|
||||||
addr: String
|
addr: String,
|
||||||
|
pub fpsstat: FpsStat
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StripeDriver {
|
impl StripeDriver {
|
||||||
|
@ -15,7 +19,8 @@ impl StripeDriver {
|
||||||
StripeDriver {
|
StripeDriver {
|
||||||
addr: addr.into(),
|
addr: addr.into(),
|
||||||
timeout: 0,
|
timeout: 0,
|
||||||
socket
|
socket,
|
||||||
|
fpsstat: FpsStat::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +38,7 @@ impl FixtureDriver for StripeDriver {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.socket.write().unwrap().send_to(&buf, &self.addr);
|
self.socket.write().unwrap().send_to(&buf, &self.addr);
|
||||||
|
self.fpsstat.refresh();
|
||||||
|
|
||||||
self.timeout = 100;
|
self.timeout = 100;
|
||||||
} else {
|
} else {
|
||||||
|
@ -43,5 +49,13 @@ impl FixtureDriver for StripeDriver {
|
||||||
fn sync(&mut self) {
|
fn sync(&mut self) {
|
||||||
self.timeout = 0;
|
self.timeout = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn connect_info(&self) -> String {
|
||||||
|
format!("(timeout = {})", self.timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn avg_fps(&self) -> f32 {
|
||||||
|
self.fpsstat.avg_fps
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue