mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
fix bugs in progress bar computation
This commit is contained in:
parent
5129b42dd9
commit
55abbd3f3e
2 changed files with 7 additions and 4 deletions
|
|
@ -137,6 +137,7 @@ fn xmain() -> ! {
|
||||||
end_work = config.end_work;
|
end_work = config.end_work;
|
||||||
last_percentage = compute_checked_percentage(
|
last_percentage = compute_checked_percentage(
|
||||||
config.current_work, start_work, end_work);
|
config.current_work, start_work, end_work);
|
||||||
|
log::info!("init percentage: {}, current: {}, start: {}, end: {}", last_percentage, config.current_work, start_work, end_work);
|
||||||
progress_action.set_state(last_percentage);
|
progress_action.set_state(last_percentage);
|
||||||
|
|
||||||
renderer_modal.modify(
|
renderer_modal.modify(
|
||||||
|
|
@ -191,7 +192,8 @@ fn xmain() -> ! {
|
||||||
Some(RendererOp::UpdateProgress) => msg_scalar_unpack!(msg, current, _, _, _, {
|
Some(RendererOp::UpdateProgress) => msg_scalar_unpack!(msg, current, _, _, _, {
|
||||||
let new_percentage = compute_checked_percentage(
|
let new_percentage = compute_checked_percentage(
|
||||||
current as u32, start_work, end_work);
|
current as u32, start_work, end_work);
|
||||||
if new_percentage != last_percentage {
|
log::trace!("percentage: {}, current: {}, start: {}, end: {}", new_percentage, current, start_work, end_work);
|
||||||
|
if new_percentage != last_percentage {
|
||||||
last_percentage = new_percentage;
|
last_percentage = new_percentage;
|
||||||
progress_action.set_state(last_percentage);
|
progress_action.set_state(last_percentage);
|
||||||
|
|
||||||
|
|
@ -527,7 +529,8 @@ fn compute_checked_percentage(current: u32, start: u32, end: u32) -> u32 {
|
||||||
} else if current >= end {
|
} else if current >= end {
|
||||||
100
|
100
|
||||||
} else {
|
} else {
|
||||||
(current * 100) / (end - start)
|
// do math in higher precision because we could overflow a u32
|
||||||
|
(((current as u64 - start as u64) * 100) / (end as u64 - start as u64)) as u32
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -28,8 +28,8 @@ pub(crate) fn spawn_test() {
|
||||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||||
|
|
||||||
// test progress bar
|
// test progress bar
|
||||||
modals.start_progress("Progress Quest", 100, 500, 100).expect("couldn't raise progress bar");
|
modals.start_progress("Progress Quest", xous::PDDB_LOC, xous::PDDB_LOC + 64*1024*128, xous::PDDB_LOC).expect("couldn't raise progress bar");
|
||||||
for i in (100..500).step_by(8) {
|
for i in (xous::PDDB_LOC..xous::PDDB_LOC + 64*1024*128).step_by(64*1024) {
|
||||||
modals.update_progress(i).expect("couldn't update progress bar");
|
modals.update_progress(i).expect("couldn't update progress bar");
|
||||||
tt.sleep_ms(100).unwrap();
|
tt.sleep_ms(100).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue