diff --git a/src/padcontrol/mod.rs b/src/padcontrol/mod.rs index 49864fc..7c66f7e 100644 --- a/src/padcontrol/mod.rs +++ b/src/padcontrol/mod.rs @@ -4,6 +4,8 @@ use crate::zabbix::problems::ZabbixLayout; use launchy::Color; use launchy::{self, Canvas, CanvasLayout, CanvasLayoutPoller, MsgPollingWrapper, Pad}; +pub const MATRIX_SIZE: i32 = 8; + pub fn initpad() -> (CanvasLayout<'static>, CanvasLayoutPoller) { let (mut canvas, poller) = launchy::CanvasLayout::new_polling(); match canvas.add_by_guess_rotated::(0, 0, launchy::Rotation::None) { @@ -33,19 +35,22 @@ pub fn draw(canvas: &mut CanvasLayout, datamatrix: &mut ZabbixLayout, cfg: &mut loop { let zabbix_data = get_zabbix_problems(cfg); datamatrix.compute(&zabbix_data); + let mut x = 0i32; let mut y = 1i32; - for (x, j) in datamatrix.layout.iter().enumerate() { - if y % 8 == 0 { - y += 1; - }; - let p = Pad { x: x as i32, y: y }; + for j in datamatrix.layout.iter() { + let p = Pad { x: x, y: y }; let c = match j.status { 4 => Color::RED, - 3 => Color::YELLOW, - 2 => Color::WHITE, + 3 => Color::from_hue(0.05), + 2 => Color::from_hue(1.24), _ => Color::GREEN, }; canvas[p] = c; + x += 1; + if x % MATRIX_SIZE == 0 { + y += 1; + x = 0; + }; } let _a = canvas.flush(); std::thread::sleep(std::time::Duration::from_secs(cfg.refresh.unwrap_or(5)));