mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
clean up timing and cosmetic issues on status updates
This commit is contained in:
parent
2d59adbe0e
commit
9a2bce24cb
4 changed files with 25 additions and 30 deletions
|
|
@ -109,7 +109,7 @@ fn add_chat_layout(gfx_conn: xous::CID, trng_conn: xous::CID, canvases: &mut Fnv
|
|||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
let debug1 = true; // debug level 1 - most general level
|
||||
let debug1 = false; // debug level 1 - most general level
|
||||
log_server::init_wait().unwrap();
|
||||
info!("GAM: my PID is {}", xous::process::id());
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub fn status_thread(canvas_gid: [u32; 4]) {
|
|||
let debug1 = false;
|
||||
let status_gid: Gid = Gid::new(canvas_gid);
|
||||
|
||||
info!("GAM|status: registering GAM|status thread");
|
||||
if debug1{info!("GAM|status: registering GAM|status thread");}
|
||||
let status_sid = xous_names::register_name(xous::names::SERVER_NAME_STATUS).expect("GAM|status: can't register server");
|
||||
|
||||
let ticktimer_conn = xous::connect(xous::SID::from_bytes(b"ticktimer-server").unwrap()).unwrap();
|
||||
|
|
@ -21,11 +21,11 @@ pub fn status_thread(canvas_gid: [u32; 4]) {
|
|||
let gfx_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GFX).expect("GAM|status: can't connect to COM");
|
||||
let gam_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_GAM).expect("GAM|status: can't connect to GAM");
|
||||
|
||||
info!("GAM|status: getting screen size");
|
||||
if debug1{info!("GAM|status: getting screen size");}
|
||||
let screensize = gam::get_canvas_bounds(gam_conn, status_gid).expect("GAM|status: Couldn't get canvas size");
|
||||
//let screensize: Point = Point::new(0, 336);
|
||||
|
||||
info!("GAM|status: building textview objects");
|
||||
if debug1{info!("GAM|status: building textview objects");}
|
||||
// build uptime text view: left half of status bar
|
||||
let mut uptime_tv = TextView::new(status_gid, 0,
|
||||
TextBounds::BoundingBox(Rectangle::new(Point::new(0,0),
|
||||
|
|
@ -35,8 +35,8 @@ pub fn status_thread(canvas_gid: [u32; 4]) {
|
|||
uptime_tv.draw_border = false;
|
||||
uptime_tv.margin = Point::new(0, 0);
|
||||
write!(uptime_tv, "Booting up...").expect("GAM|status: couldn't init uptime text");
|
||||
info!("GAM|status: screensize as reported: {:?}", screensize);
|
||||
info!("GAM|status: uptime initialized to '{:?}'", uptime_tv);
|
||||
if debug1{info!("GAM|status: screensize as reported: {:?}", screensize);}
|
||||
if debug1{info!("GAM|status: uptime initialized to '{:?}'", uptime_tv);}
|
||||
|
||||
// build battstats text view: right half of status bar
|
||||
let mut battstats_tv = TextView::new(status_gid, 0,
|
||||
|
|
@ -49,6 +49,7 @@ pub fn status_thread(canvas_gid: [u32; 4]) {
|
|||
let mut stats: BattStats = BattStats::default();
|
||||
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
||||
let mut stats_phase: usize = 0;
|
||||
let mut last_seconds: usize = ((last_time / 1000) % 60) as usize;
|
||||
|
||||
let style_dark = DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1);
|
||||
gam::draw_line(gam_conn, status_gid, Line::new_with_style(
|
||||
|
|
@ -60,16 +61,6 @@ pub fn status_thread(canvas_gid: [u32; 4]) {
|
|||
com::request_battstat_events(xous::names::SERVER_NAME_STATUS, com_conn).expect("GAM|status: couldn't request events from COM");
|
||||
info!("GAM|status: starting main loop");
|
||||
loop {
|
||||
/*
|
||||
if debug1{info!("GAM|status: periodic tasks: updating uptime, requesting battstats");}
|
||||
let elapsed_time = ticktimer_server::elapsed_ms(ticktimer_conn).expect("GAM|status: error requesting uptime");
|
||||
com::get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM");
|
||||
uptime_tv.clear_str();
|
||||
write!(&mut uptime_tv, "Up {:02}:{:02}:{:02}",
|
||||
(elapsed_time / 3_600_000), (elapsed_time / 60_000) % 60, (elapsed_time / 1000) % 60).expect("GAM|status: can't write string");
|
||||
if debug1{info!("GAM|status: requesting draw of '{}'", uptime_tv);}
|
||||
gam::post_textview(gam_conn, &mut uptime_tv).expect("GAM|status: can't draw uptime");*/
|
||||
|
||||
let maybe_env = xous::try_receive_message(status_sid).unwrap();
|
||||
match maybe_env {
|
||||
Some(envelope) => {
|
||||
|
|
@ -81,7 +72,7 @@ pub fn status_thread(canvas_gid: [u32; 4]) {
|
|||
stats = s.clone();
|
||||
battstats_tv.clear_str();
|
||||
// toggle between two views of the data; duration of toggle is set by the modulus and thresholds below
|
||||
if stats_phase > 4 {
|
||||
if stats_phase > 3 {
|
||||
write!(&mut battstats_tv, "{}mV {}mA", stats.voltage, stats.current).expect("GAM|status: can't write string");
|
||||
} else {
|
||||
write!(&mut battstats_tv, "{}mAh {}%", stats.remaining_capacity, stats.soc).expect("GAM|status: can't write string");
|
||||
|
|
@ -98,19 +89,22 @@ pub fn status_thread(canvas_gid: [u32; 4]) {
|
|||
_ => xous::yield_slice(),
|
||||
}
|
||||
|
||||
//ticktimer_server::sleep_ms(ticktimer_conn, 1000).expect("couldn't sleep");
|
||||
|
||||
if let Ok(elapsed_time) = ticktimer_server::elapsed_ms(ticktimer_conn) {
|
||||
let now_seconds: usize = ((elapsed_time / 1000) % 60) as usize;
|
||||
if now_seconds != last_seconds {
|
||||
last_seconds = now_seconds;
|
||||
uptime_tv.clear_str();
|
||||
write!(&mut uptime_tv, "Up {:02}:{:02}:{:02}",
|
||||
(elapsed_time / 3_600_000), (elapsed_time / 60_000) % 60, now_seconds).expect("GAM|status: can't write string");
|
||||
if debug1{info!("GAM|status: requesting draw of '{}'", uptime_tv);}
|
||||
gam::post_textview(gam_conn, &mut uptime_tv).expect("GAM|status: can't draw uptime");
|
||||
}
|
||||
|
||||
if elapsed_time - last_time > 500 {
|
||||
//info!("GAM|status: size of TextView type: {} bytes", core::mem::size_of::<TextView>());
|
||||
if debug1{info!("GAM|status: periodic tasks: updating uptime, requesting battstats");}
|
||||
last_time = elapsed_time;
|
||||
com::get_batt_stats_nb(com_conn).expect("Can't get battery stats from COM");
|
||||
uptime_tv.clear_str();
|
||||
write!(&mut uptime_tv, "Up {:02}:{:02}:{:02}",
|
||||
(elapsed_time / 3_600_000), (elapsed_time / 60_000) % 60, (elapsed_time / 1000) % 60).expect("GAM|status: can't write string");
|
||||
if debug1{info!("GAM|status: requesting draw of '{}'", uptime_tv);}
|
||||
gam::post_textview(gam_conn, &mut uptime_tv).expect("GAM|status: can't draw uptime");
|
||||
}
|
||||
} else {
|
||||
error!("error requesting ticktimer!")
|
||||
|
|
|
|||
|
|
@ -325,7 +325,7 @@ fn some_main() -> ! {
|
|||
)
|
||||
.expect("couldn't map GPIO CSR range");
|
||||
let mut gpio = CSR::new(gpio_base.as_mut_ptr() as *mut u32);
|
||||
gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 0); // 0 = kernel, 1 = log, 2 = app_uart
|
||||
gpio.wfo(utra::gpio::UARTSEL_UARTSEL, 1); // 0 = kernel, 1 = log, 2 = app_uart
|
||||
}
|
||||
|
||||
let mut output = implementation::init();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ const FAIL_TIMEOUT_MS: u64 = 100;
|
|||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
let debug1 = false;
|
||||
log_server::init_wait().unwrap();
|
||||
info!("NS: my PID is {}", xous::process::id());
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ fn xmain() -> ! {
|
|||
|
||||
loop {
|
||||
let envelope = xous::receive_message(name_server).unwrap();
|
||||
info!("NS: received message");
|
||||
if debug1{info!("NS: received message");}
|
||||
if let xous::Message::MutableBorrow(m) = &envelope.body {
|
||||
let mut buf = unsafe { buffer::XousBuffer::from_memory_message(m) };
|
||||
let value = unsafe {
|
||||
|
|
@ -45,14 +46,14 @@ fn xmain() -> ! {
|
|||
rkyv::Archived::<api::Request>::Register(registration_name) => {
|
||||
use rkyv::Unarchive;
|
||||
let name = registration_name.unarchive();
|
||||
info!("NS: registration request for '{}'", name);
|
||||
if debug1{info!("NS: registration request for '{}'", name);}
|
||||
if !name_table.contains_key(&name) {
|
||||
let new_sid =
|
||||
xous::create_server_id().expect("NS: create server failed, maybe OOM?");
|
||||
name_table
|
||||
.insert(name, new_sid)
|
||||
.expect("NS: register name failure, maybe out of HashMap capacity?");
|
||||
info!("NS: request successful, SID is {:?}", new_sid);
|
||||
if debug1{info!("NS: request successful, SID is {:?}", new_sid);}
|
||||
rkyv::Archived::<api::Request>::SID(new_sid.into())
|
||||
} else {
|
||||
// compute the next interval, rounded to a multiple of FAIL_TIMEOUT_MS to reduce timing side channels
|
||||
|
|
@ -70,7 +71,7 @@ fn xmain() -> ! {
|
|||
}
|
||||
}
|
||||
rkyv::Archived::<api::Request>::Lookup(lookup_name) => {
|
||||
info!("NS: Lookup request for '{}'", lookup_name);
|
||||
if debug1{info!("NS: Lookup request for '{}'", lookup_name);}
|
||||
let name = lookup_name.unarchive();
|
||||
if let Some(server_sid) = name_table.get(&name) {
|
||||
let sender_pid = envelope
|
||||
|
|
@ -81,7 +82,7 @@ fn xmain() -> ! {
|
|||
.expect("NS: can't broker connection")
|
||||
{
|
||||
xous::Result::ConnectionID(connection_id) => {
|
||||
info!("NS: lookup success, returning connection {}", connection_id);
|
||||
if debug1{info!("NS: lookup success, returning connection {}", connection_id);}
|
||||
rkyv::Archived::<api::Request>::CID(connection_id)
|
||||
}
|
||||
_ => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue