* Code cleanup, feature updated
- cleanup unsed variables - added dynamic slow effect based on number of issues
This commit is contained in:
parent
72d12319c1
commit
55dc677b46
17
.drone.yml
Normal file
17
.drone.yml
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: test
|
||||
image: rust:1
|
||||
commands:
|
||||
- cargo build --verbose --all
|
||||
- cargo test --verbose --all
|
||||
- name: release
|
||||
image: rust:1
|
||||
commands:
|
||||
- cargo build --release --verbose --all
|
||||
when:
|
||||
event: tag
|
@ -14,4 +14,4 @@ args:
|
||||
short: m
|
||||
value_name: MODE
|
||||
help: Handles mode
|
||||
takes_value: true
|
||||
takes_value: true
|
||||
|
@ -68,10 +68,7 @@ impl Context {
|
||||
Err(_) => vec![],
|
||||
};
|
||||
if events.len() > 0 {
|
||||
println!(
|
||||
"Reloading {cfg}",
|
||||
cfg = self.configfile
|
||||
);
|
||||
println!("Reloading {cfg}", cfg = self.configfile);
|
||||
self.cfg.load(self.configfile.as_str());
|
||||
get_zabbix_authtoken(&mut self.cfg);
|
||||
break;
|
||||
@ -118,7 +115,7 @@ impl<'a> Config {
|
||||
};
|
||||
|
||||
if !fileexists {
|
||||
let _a = File::create(configfile);
|
||||
File::create(configfile).unwrap();
|
||||
}
|
||||
fileopen = File::open(configfile);
|
||||
|
||||
@ -135,15 +132,33 @@ impl<'a> Config {
|
||||
Ok(ncfg) => {
|
||||
let tmpcfg = Config::new();
|
||||
Config {
|
||||
server: ncfg["server"].as_str().unwrap_or(tmpcfg.server.as_str()).to_string(),
|
||||
username: ncfg["username"].as_str().unwrap_or(tmpcfg.username.as_str()).to_string(),
|
||||
password: ncfg["password"].as_str().unwrap_or(tmpcfg.password.as_str()).to_string(),
|
||||
authtoken: Some(ncfg["authtoken"].as_str().unwrap_or(self.authtoken.clone().unwrap().as_str()).to_string()),
|
||||
sloweffect: Some(ncfg["sloweffect"].as_bool().unwrap_or(tmpcfg.sloweffect.unwrap())),
|
||||
server: ncfg["server"]
|
||||
.as_str()
|
||||
.unwrap_or(tmpcfg.server.as_str())
|
||||
.to_string(),
|
||||
username: ncfg["username"]
|
||||
.as_str()
|
||||
.unwrap_or(tmpcfg.username.as_str())
|
||||
.to_string(),
|
||||
password: ncfg["password"]
|
||||
.as_str()
|
||||
.unwrap_or(tmpcfg.password.as_str())
|
||||
.to_string(),
|
||||
authtoken: Some(
|
||||
ncfg["authtoken"]
|
||||
.as_str()
|
||||
.unwrap_or(self.authtoken.clone().unwrap().as_str())
|
||||
.to_string(),
|
||||
),
|
||||
sloweffect: Some(
|
||||
ncfg["sloweffect"]
|
||||
.as_bool()
|
||||
.unwrap_or(tmpcfg.sloweffect.unwrap()),
|
||||
),
|
||||
refresh: Some(ncfg["refresh"].as_u64().unwrap_or(tmpcfg.refresh.unwrap())),
|
||||
limit: Some(ncfg["limit"].as_u64().unwrap_or(tmpcfg.limit.unwrap())),
|
||||
}
|
||||
},
|
||||
}
|
||||
Err(err) => {
|
||||
errorreading = true;
|
||||
println!("error occured: '{}'", err);
|
||||
|
@ -10,6 +10,7 @@ pub const MATRIX_SIZE: i32 = MATRIX_WIDTH * MATRIX_WIDTH;
|
||||
pub const REQUEST_TIMEOUT: i32 = 5;
|
||||
pub const ZERO_COLOR: f32 = 0.;
|
||||
pub const ONE_COLOR: f32 = 1.;
|
||||
pub const SLOWEFFECT_FACTOR: f32 = 800.0;
|
||||
|
||||
pub fn run(ctx: &mut Context) {
|
||||
match ctx.mode.as_str() {
|
||||
@ -36,16 +37,14 @@ pub fn run(ctx: &mut Context) {
|
||||
fn initpad() -> (CanvasLayout<'static>, CanvasLayoutPoller) {
|
||||
let (mut canvas, poller) = launchy::CanvasLayout::new_polling();
|
||||
match canvas.add_by_guess_rotated::<launchy::mini::Canvas>(0, 0, launchy::Rotation::None) {
|
||||
Ok(o) => o,
|
||||
Ok(o) => {
|
||||
println!("Connected to device using USB {o:?}");
|
||||
clear(&mut canvas);
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!(
|
||||
"Failed to connect to device, check USB connection {err}",
|
||||
err = err
|
||||
);
|
||||
eprintln!("Failed to connect to device, check USB connection {err}",);
|
||||
}
|
||||
};
|
||||
println!("Connected to device using USB");
|
||||
clear(&mut canvas);
|
||||
(canvas, poller)
|
||||
}
|
||||
|
||||
@ -55,7 +54,7 @@ fn input(canvas: &mut CanvasLayout, poller: &mut CanvasLayoutPoller) {
|
||||
canvas[msg.pad()] = color;
|
||||
println!("{msg:?}", msg = msg.pad())
|
||||
}
|
||||
let _res = canvas.flush();
|
||||
canvas.flush().unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,7 +68,10 @@ fn test(ctx: &mut Context) {
|
||||
let zabbix_data = match get_zabbix_problems(&ctx.cfg) {
|
||||
Ok(z) => z,
|
||||
Err(_) => {
|
||||
println!("Error requesting zabbix service, retrying in {} seconds", REQUEST_TIMEOUT);
|
||||
println!(
|
||||
"Error requesting zabbix service, retrying in {} seconds",
|
||||
REQUEST_TIMEOUT
|
||||
);
|
||||
sleep(Duration::from_secs(REQUEST_TIMEOUT as u64));
|
||||
continue;
|
||||
}
|
||||
@ -85,7 +87,10 @@ pub fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) {
|
||||
let zabbix_data = match get_zabbix_problems(&ctx.cfg) {
|
||||
Ok(zabbix_data) => zabbix_data,
|
||||
Err(_) => {
|
||||
println!("Error requesting zabbix service, retrying in {}", REQUEST_TIMEOUT);
|
||||
println!(
|
||||
"Error requesting zabbix service, retrying in {}",
|
||||
REQUEST_TIMEOUT
|
||||
);
|
||||
sleep(Duration::from_secs(REQUEST_TIMEOUT as u64));
|
||||
continue;
|
||||
}
|
||||
@ -107,7 +112,9 @@ pub fn draw(canvas: &mut CanvasLayout, ctx: &mut Context) {
|
||||
};
|
||||
canvas[p] = c;
|
||||
if ctx.cfg.sloweffect.unwrap() {
|
||||
sleep(Duration::from_millis(15));
|
||||
sleep(Duration::from_millis(
|
||||
(SLOWEFFECT_FACTOR * (1.0 / ctx.datamatrix.layout.len() as f32)) as u64,
|
||||
));
|
||||
}
|
||||
canvas.flush().unwrap();
|
||||
max += 1;
|
||||
@ -125,7 +132,7 @@ fn effect(canvas: &mut CanvasLayout, poller: &mut CanvasLayoutPoller) {
|
||||
canvas[msg.pad()] = color;
|
||||
println!("{msg:?}", msg = msg.pad())
|
||||
}
|
||||
let _res = canvas.flush();
|
||||
canvas.flush().unwrap();
|
||||
|
||||
canvas.iter().for_each(|pad| {
|
||||
let surrounding_color = pad
|
||||
@ -143,7 +150,7 @@ fn effect(canvas: &mut CanvasLayout, poller: &mut CanvasLayoutPoller) {
|
||||
|
||||
fn clear(canvas: &mut CanvasLayout) {
|
||||
for a in 0..MATRIX_WIDTH {
|
||||
for b in 0..MATRIX_WIDTH+1 {
|
||||
for b in 0..MATRIX_WIDTH + 1 {
|
||||
canvas[Pad { x: a, y: b }] = Color {
|
||||
r: ZERO_COLOR,
|
||||
g: ZERO_COLOR,
|
||||
@ -151,5 +158,5 @@ fn clear(canvas: &mut CanvasLayout) {
|
||||
};
|
||||
}
|
||||
}
|
||||
let _res = canvas.flush();
|
||||
canvas.flush().unwrap();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user