From 4ad6d9da0b84e66b41d136b9755524468b913430 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Mon, 25 Oct 2021 16:50:23 +0200 Subject: [PATCH] updated hotreload branch --- src/config/mod.rs | 6 ++--- src/main.rs | 2 -- src/padcontrol/mod.rs | 60 +++++++++++++++++-------------------------- 3 files changed, 26 insertions(+), 42 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index a50f5a5..28559bf 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -67,10 +67,8 @@ impl Context { if events.len() > 0 { self.cfg.load(self.configfile.as_str()); println!( - "{cfg:?} {numevents} {events:?}", - cfg = self.cfg, - numevents = events.len(), - events = events + "Reloading {cfg}", + cfg = self.configfile ); break; } else { diff --git a/src/main.rs b/src/main.rs index 1033d15..bb1bdfc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,5 @@ use config::Context; fn main() { let mut context = Context::new(); - //padcontrol::draw(&mut canvas, &mut datamatrix, &mut context); - //padcontrol::test(&mut context) padcontrol::run(&mut context); } diff --git a/src/padcontrol/mod.rs b/src/padcontrol/mod.rs index 93c2fd8..4be2542 100644 --- a/src/padcontrol/mod.rs +++ b/src/padcontrol/mod.rs @@ -5,8 +5,9 @@ use launchy::{self, Canvas, CanvasLayout, CanvasLayoutPoller, MsgPollingWrapper, use std::thread::sleep; use std::time::Duration; -const MATRIX_WIDTH: i32 = 8; -const MATRIX_SIZE: i32 = MATRIX_WIDTH * MATRIX_WIDTH; +pub const MATRIX_WIDTH: i32 = 8; +pub const MATRIX_SIZE: i32 = MATRIX_WIDTH * MATRIX_WIDTH; +pub const REQUEST_TIMEOUT: i32 = 10; pub fn run(ctx: &mut Context) { match ctx.mode.as_str() { @@ -56,23 +57,35 @@ fn input(canvas: &mut CanvasLayout, poller: &mut CanvasLayoutPoller) { } } -fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) { +fn test(ctx: &mut Context) { println!( "Refresh rate is {sec} seconds", sec = ctx.cfg.refresh.unwrap() ); + loop { + let zabbix_data_result = get_zabbix_problems(&ctx.cfg); + let zabbix_data = match zabbix_data_result { + Ok(z) => z, + Err(_) => { + println!("Error requesting zabbix service, retrying in {}", REQUEST_TIMEOUT); + sleep(Duration::from_secs(REQUEST_TIMEOUT as u64)); + continue; + } + }; + println!("{}", zabbix_data); + ctx.hotreload(); + } +} + +pub fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) { + println!("Refresh rate is {} seconds", ctx.cfg.refresh.unwrap()); loop { let zabbix_data_result = get_zabbix_problems(&ctx.cfg); let zabbix_data = match zabbix_data_result { Ok(zabbix_data) => zabbix_data, - Err(err) => { - let duration = 10; - println!( - "Error requesting zabbix service, err is {err}, retrying in {duration}", - err = err, - duration = duration - ); - sleep(Duration::from_secs(duration)); + Err(_) => { + println!("Error requesting zabbix service, retrying in {}", REQUEST_TIMEOUT); + sleep(Duration::from_secs(REQUEST_TIMEOUT as u64)); continue; } }; @@ -105,31 +118,6 @@ fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) { } } -fn test(ctx: &mut Context) { - println!( - "Refresh rate is {sec} seconds", - sec = ctx.cfg.refresh.unwrap() - ); - loop { - let zabbix_data_result = get_zabbix_problems(&ctx.cfg); - let zabbix_data = match zabbix_data_result { - Ok(z) => z, - Err(err) => { - let duration = 10; - println!( - "Error requesting zabbix service, err is {err}, retrying in {duration}", - err = err, - duration = duration - ); - sleep(Duration::from_secs(duration)); - continue; - } - }; - println!("{zabbix_data}", zabbix_data = zabbix_data); - ctx.hotreload(); - } -} - fn effect(canvas: &mut CanvasLayout, poller: &mut CanvasLayoutPoller) { for color in (0u64..).map(|f| Color::red_green_color(f as f32 / 60.0 / 2.5)) { for msg in poller.iter_for_millis(17).filter(|msg| msg.is_press()) {