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 {
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 {

View File

@ -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);
}

View File

@ -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()) {