updated hotreload branch

This commit is contained in:
Paul Lecuq 2021-10-25 16:50:23 +02:00
parent b322e4bdb1
commit 4ad6d9da0b
3 changed files with 26 additions and 42 deletions

View File

@ -67,10 +67,8 @@ impl Context {
if events.len() > 0 { if events.len() > 0 {
self.cfg.load(self.configfile.as_str()); self.cfg.load(self.configfile.as_str());
println!( println!(
"{cfg:?} {numevents} {events:?}", "Reloading {cfg}",
cfg = self.cfg, cfg = self.configfile
numevents = events.len(),
events = events
); );
break; break;
} else { } else {

View File

@ -9,7 +9,5 @@ use config::Context;
fn main() { fn main() {
let mut context = Context::new(); let mut context = Context::new();
//padcontrol::draw(&mut canvas, &mut datamatrix, &mut context);
//padcontrol::test(&mut context)
padcontrol::run(&mut context); padcontrol::run(&mut context);
} }

View File

@ -5,8 +5,9 @@ use launchy::{self, Canvas, CanvasLayout, CanvasLayoutPoller, MsgPollingWrapper,
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
const MATRIX_WIDTH: i32 = 8; pub const MATRIX_WIDTH: i32 = 8;
const MATRIX_SIZE: i32 = MATRIX_WIDTH * MATRIX_WIDTH; pub const MATRIX_SIZE: i32 = MATRIX_WIDTH * MATRIX_WIDTH;
pub const REQUEST_TIMEOUT: i32 = 10;
pub fn run(ctx: &mut Context) { pub fn run(ctx: &mut Context) {
match ctx.mode.as_str() { 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!( println!(
"Refresh rate is {sec} seconds", "Refresh rate is {sec} seconds",
sec = ctx.cfg.refresh.unwrap() 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 { loop {
let zabbix_data_result = get_zabbix_problems(&ctx.cfg); let zabbix_data_result = get_zabbix_problems(&ctx.cfg);
let zabbix_data = match zabbix_data_result { let zabbix_data = match zabbix_data_result {
Ok(zabbix_data) => zabbix_data, Ok(zabbix_data) => zabbix_data,
Err(err) => { Err(_) => {
let duration = 10; println!("Error requesting zabbix service, retrying in {}", REQUEST_TIMEOUT);
println!( sleep(Duration::from_secs(REQUEST_TIMEOUT as u64));
"Error requesting zabbix service, err is {err}, retrying in {duration}",
err = err,
duration = duration
);
sleep(Duration::from_secs(duration));
continue; 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) { 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 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()) { for msg in poller.iter_for_millis(17).filter(|msg| msg.is_press()) {