mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
catch potential div by 0 on status redraw
This commit is contained in:
parent
89e7849bc5
commit
be7d8a76a5
1 changed files with 9 additions and 4 deletions
|
|
@ -406,8 +406,9 @@ fn wrapped_main() -> ! {
|
|||
pump_run.store(true, Ordering::Relaxed); // start status thread updating
|
||||
loop {
|
||||
let msg = xous::receive_message(status_sid).unwrap();
|
||||
log::trace!("|status: Message: {:?}", msg);
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
let opcode: Option<StatusOpcode> = FromPrimitive::from_usize(msg.body.id());
|
||||
log::debug!("{:?}", opcode);
|
||||
match opcode {
|
||||
Some(StatusOpcode::EnableAutomaticBacklight) => {
|
||||
*enabled.lock().unwrap() = true;
|
||||
|
||||
|
|
@ -530,12 +531,16 @@ fn wrapped_main() -> ! {
|
|||
let (latest_activity, period) = llio
|
||||
.activity_instantaneous()
|
||||
.expect("couldn't get CPU activity");
|
||||
let activity_to_width = ((latest_activity as u64) * 1000u64 * (cpuload_rect.width() as u64 - 4)) / (period as u64 * 1000u64);
|
||||
let activity_to_width = if period == 0 {
|
||||
cpuload_rect.width() as i16 - 4
|
||||
} else {
|
||||
(((latest_activity as u64) * 1000u64 * (cpuload_rect.width() as u64 - 4)) / (period as u64 * 1000u64)) as i16
|
||||
};
|
||||
draw_list.push(GamObjectType::Rect(
|
||||
Rectangle::new_coords_with_style(
|
||||
cpuload_rect.tl().x + 2,
|
||||
cpuload_rect.tl().y + 2,
|
||||
cpuload_rect.tl().x + 2 + activity_to_width as i16,
|
||||
cpuload_rect.tl().x + 2 + (activity_to_width).min(cpuload_rect.width() as i16 - 4),
|
||||
cpuload_rect.br().y - 2,
|
||||
DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 0))
|
||||
)).unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue