fix some ergonomics around the status bar

This commit is contained in:
bunnie 2022-01-28 16:28:06 +08:00
parent 25bccd9446
commit f7ea782e73
3 changed files with 55 additions and 27 deletions

View file

@ -171,6 +171,12 @@ pub(crate) fn connection_manager(sid: xous::SID, activity_interval: Arc<AtomicU3
} }
} }
LinkState::WFXError => { LinkState::WFXError => {
// reset the stats cache, and update subscribers that we're disconnected
wifi_stats_cache = WlanStatus::from_ipc(WlanStatusIpc::default());
for &sub in status_subscribers.keys() {
let buf = Buffer::into_buf(com::WlanStatusIpc::from_status(wifi_stats_cache)).or(Err(xous::Error::InternalError)).unwrap();
buf.send(sub, WifiStateCallback::Update.to_u32().unwrap()).or(Err(xous::Error::InternalError)).unwrap();
}
wifi_state = WifiState::Error; wifi_state = WifiState::Error;
} }
_ => { // should approximately be a "disconnected" state. _ => { // should approximately be a "disconnected" state.

View file

@ -1,4 +1,20 @@
{ {
"stats.measuring": {
"en": "Measuring...",
"zh": "进行测量...",
"en-audio": "Measuring..."
},
"stats.disconnected": {
"en": "Not connected",
"zh": "没有连接",
"en-audio": "Not connected"
},
"stats.uptime": {
"translator-note": "This needs to be a very short string, 2 chars max. Trailing space is necessary for English due to proportional font.",
"en": "Up ",
"zh": "运行",
"en-audio": "Uptime"
},
"secnote.usb_unlock": { "secnote.usb_unlock": {
"en": " USB unlocked", "en": " USB unlocked",
"zh": "USB解锁", "zh": "USB解锁",

View file

@ -357,34 +357,39 @@ fn xmain() -> ! {
battstats_tv.clear_str(); battstats_tv.clear_str();
// have to clear the entire rectangle area, because the SSID has a variable width and can be much wider or shorter than battstats // have to clear the entire rectangle area, because the SSID has a variable width and can be much wider or shorter than battstats
gam.draw_rectangle(status_gid, stats_rect).ok(); gam.draw_rectangle(status_gid, stats_rect).ok();
// toggle between two views of the data every time we have a status update
let mut wattage = stats.current as f32 / 1000.0 * stats.voltage as f32 / 1000.0; if stats.current == 0xdddd || stats.current == 0xffff
let sign = if wattage > 0.005 { || stats.voltage == 0xdddd || stats.voltage == 0xffff
'\u{2b06}' // up arrow || stats.soc == 0xdddd || stats.soc == 0xffff {
} else if wattage < -0.005 { write!(&mut battstats_tv, "{}", t!("stats.measuring", xous::LANG)).unwrap();
'\u{2b07}' // down arrow
} else { } else {
'\u{1f50c}' // plugged in icon (e.g., fully charged, running on wall power now) // toggle between two views of the data every time we have a status update
}; let mut wattage = stats.current as f32 / 1000.0 * stats.voltage as f32 / 1000.0;
wattage = wattage.abs(); let sign = if wattage > 0.005 {
if battstats_phase { '\u{2b06}' // up arrow
write!(&mut battstats_tv, "{:.3}W{}{:.2}V {}%", wattage, sign, stats.voltage as f32 / 1000.0, stats.soc) } else if wattage < -0.005 {
.expect("|status: can't write string"); '\u{2b07}' // down arrow
} else {
if let Some(ssid) = wifi_status.ssid {
write!(
&mut battstats_tv,
"{} -{}dBm",
ssid.name.as_str().unwrap_or("UTF-8 Erorr"),
ssid.rssi,
)
.expect("|status: can't write string");
} else { } else {
write!( '\u{1f50c}' // plugged in icon (e.g., fully charged, running on wall power now)
&mut battstats_tv, };
"Not connected" wattage = wattage.abs();
) if battstats_phase {
.expect("|status: can't write string"); write!(&mut battstats_tv, "{:.3}W{}{:.2}V {}%", wattage, sign, stats.voltage as f32 / 1000.0, stats.soc).unwrap();
} else {
if let Some(ssid) = wifi_status.ssid {
write!(
&mut battstats_tv,
"{} -{}dBm",
ssid.name.as_str().unwrap_or("UTF-8 Erorr"),
ssid.rssi,
).unwrap();
} else {
write!(
&mut battstats_tv,
"{}",
t!("stats.disconnected", xous::LANG)
).unwrap();
}
} }
} }
gam.post_textview(&mut battstats_tv) gam.post_textview(&mut battstats_tv)
@ -539,7 +544,8 @@ fn xmain() -> ! {
// use ticktimer, not stats_phase, because stats_phase encodes some phase drift due to task-switching overhead // use ticktimer, not stats_phase, because stats_phase encodes some phase drift due to task-switching overhead
write!( write!(
&mut uptime_tv, &mut uptime_tv,
" Up {}:{:02}:{:02}", " {}{}:{:02}:{:02}",
t!("stats.uptime", xous::LANG),
(elapsed_time / 3_600_000), (elapsed_time / 3_600_000),
(elapsed_time / 60_000) % 60, (elapsed_time / 60_000) % 60,
(elapsed_time / 1000) % 60, (elapsed_time / 1000) % 60,