Skip to content

Commit

Permalink
Remove tick rate notion
Browse files Browse the repository at this point in the history
(cherry picked from commit c38fe70)
  • Loading branch information
sunsided committed Jul 6, 2024
1 parent fe4bf07 commit 4be1340
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 20 deletions.
6 changes: 1 addition & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub enum Mode {

pub struct App {
pub config: Config,
pub tick_rate: f64,
pub frame_rate: f64,
pub components: Vec<Box<dyn Component>>,
pub should_quit: bool,
Expand All @@ -36,14 +35,13 @@ pub struct App {
}

impl App {
pub fn new(tick_rate: f64, frame_rate: f64, receiver: Arc<SensorDataBuffer>) -> Result<Self> {
pub fn new(frame_rate: f64, receiver: Arc<SensorDataBuffer>) -> Result<Self> {
let sensors = Sensors::new(receiver.clone());
let streaming = StreamingLog::new(receiver.clone());
let fps = FpsDisplay::new(receiver);
let config = Config::new()?;

Ok(Self {
tick_rate,
frame_rate,
components: vec![Box::new(sensors), Box::new(streaming), Box::new(fps)],
should_quit: false,
Expand All @@ -58,7 +56,6 @@ impl App {
let (action_tx, mut action_rx) = mpsc::unbounded_channel();

let mut tui = Tui::new()?;
tui.tick_rate(self.tick_rate);
tui.frame_rate(self.frame_rate);
tui.enter()?;

Expand Down Expand Up @@ -141,7 +138,6 @@ impl App {
tui.suspend()?;
action_tx.send(Action::Resume)?;
tui = Tui::new()?;
tui.tick_rate(self.tick_rate);
tui.frame_rate(self.frame_rate);
tui.enter()?;
} else if self.should_quit {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn main() -> Result<()> {
tokio::spawn(handle_data_recv(port, from_device, to_device));

// Run the app.
let mut app = App::new(args.tick_rate, args.frame_rate, buffer)?;
let mut app = App::new(args.frame_rate, buffer)?;
app.run().await?;

Ok(())
Expand Down
14 changes: 0 additions & 14 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ pub struct Tui {
pub event_rx: UnboundedReceiver<Event>,
pub event_tx: UnboundedSender<Event>,
pub frame_rate: f64,
pub tick_rate: f64,
}

impl Tui {
pub fn new() -> Result<Self> {
let tick_rate = 4.0;
let frame_rate = 60.0;
let terminal = ratatui::Terminal::new(Backend::new(std::io::stderr()))?;
let (event_tx, event_rx) = mpsc::unbounded_channel();
Expand All @@ -59,20 +57,14 @@ impl Tui {
event_rx,
event_tx,
frame_rate,
tick_rate,
})
}

pub fn tick_rate(&mut self, tick_rate: f64) {
self.tick_rate = tick_rate;
}

pub fn frame_rate(&mut self, frame_rate: f64) {
self.frame_rate = frame_rate;
}

pub fn start(&mut self) {
let tick_delay = Duration::from_secs_f64(1.0 / self.tick_rate);
let render_delay = Duration::from_secs_f64(1.0 / self.frame_rate);
self.cancel();

Expand All @@ -82,12 +74,10 @@ impl Tui {

self.task = tokio::spawn(async move {
let mut reader = crossterm::event::EventStream::new();
let mut tick_interval = tokio::time::interval(tick_delay);
let mut render_interval = tokio::time::interval(render_delay);
event_tx.send(Event::Init).unwrap();

loop {
let tick_delay = tick_interval.tick();
let render_delay = render_interval.tick();
let crossterm_event = reader.next().fuse();

Expand Down Expand Up @@ -129,10 +119,6 @@ impl Tui {
}
},

_ = tick_delay => {
event_tx.send(Event::Tick).unwrap();
},

_ = render_delay => {
event_tx.send(Event::Render).unwrap();
},
Expand Down

0 comments on commit 4be1340

Please sign in to comment.