mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
move wifi delay hook to the correct area
- remove modal pop-up for wifi connection, and replace with busy animation - specify units of delay in the constants (_MS to indicate milliseconds; this is a convention I'm trying to adhere to) - partial progress on debugging why the animation isn't running (value of animation variable is not being passed back at the GAM layer). Also a general note on coding styles that probably is going to cause confusion now that more people are contributing to the code base. Generally, when a lot of "generic" library functions fail, we've been passing an error message up the stack. However, these functions are actually meant to be infalliable, and when you kick the error up the stack you just end up with a panic at an unhelpful location (because you finally catch the error only at the main loop or something and by that point there's nothing you can really do about it but panic, since it's supposed to be an infalliable operation). As a result I have been trying to tamp down on needless error propagations and having them fail with a unwrap or expect at the point where the abstraction should be infalliable. This helps in debugging the actual failure root cause because you're closer to the line of code that actually broke, instead of just some line at a generic error handler. Of course if you build with stack unwinding the top-level unwraps are more useful because you can peer down into the call chain, but even then, with the limited screen real estate I think deeply nested failures would probably overflow any panic display. So even with panic unwinding I think we stil want to keep the root cause within a few stack frames, instead of errors being passed up sixteen levels of abstraction before finally dying. This only applies to things that are meant to be truly infalliable, like syscalls that should not fail, or like unpacking a buffer or memory message that has already been allocated. In this case the errors are more like asserts, and are helpful if they fail at the line where they break instead of being passed up the call stack (which was the original architecture). Probably I should add a note about this to the Xous Book.
This commit is contained in:
parent
4e027b676c
commit
4423339059
5 changed files with 25 additions and 18 deletions
|
|
@ -241,6 +241,10 @@
|
||||||
"ja": "WiFi not connected. Entering read-only mode *EN*",
|
"ja": "WiFi not connected. Entering read-only mode *EN*",
|
||||||
"zh": "WiFi not connected. Entering read-only mode *EN*"
|
"zh": "WiFi not connected. Entering read-only mode *EN*"
|
||||||
},
|
},
|
||||||
|
"mtxchat.wifi.warning_status": {
|
||||||
|
"en": "No connection! Read-only.",
|
||||||
|
"en-tts": "No connection! Read-only."
|
||||||
|
},
|
||||||
"mtxchat.listen.patience": {
|
"mtxchat.listen.patience": {
|
||||||
"en": "It takes a while to get new events from the [matrix] server.\nPlease be patient :-)",
|
"en": "It takes a while to get new events from the [matrix] server.\nPlease be patient :-)",
|
||||||
"en-tts": "It takes a while to get new events from the [matrix] server.\nPlease be patient."
|
"en-tts": "It takes a while to get new events from the [matrix] server.\nPlease be patient."
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ use listen::listen;
|
||||||
use locales::t;
|
use locales::t;
|
||||||
use modals::Modals;
|
use modals::Modals;
|
||||||
use pddb::Pddb;
|
use pddb::Pddb;
|
||||||
|
use ticktimer_server::Ticktimer;
|
||||||
use std::fmt::Write as _;
|
use std::fmt::Write as _;
|
||||||
use std::io::{Error, ErrorKind, Read, Write as StdWrite};
|
use std::io::{Error, ErrorKind, Read, Write as StdWrite};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
@ -35,8 +36,8 @@ const USER_DOMAIN_KEY: &str = "user_domain";
|
||||||
|
|
||||||
const DOMAIN_MATRIX: &str = "matrix.org";
|
const DOMAIN_MATRIX: &str = "matrix.org";
|
||||||
|
|
||||||
const MTX_LONG_TIMEOUT: i32 = 60000; // ms
|
const MTX_LONG_TIMEOUT_MS: i32 = 60000; // ms
|
||||||
const WIFI_TIMEOUT: u32 = 10; // seconds
|
const WIFI_TIMEOUT_MS: u32 = 30_000; // ms
|
||||||
|
|
||||||
pub const CLOCK_NOT_SET_ID: usize = 1;
|
pub const CLOCK_NOT_SET_ID: usize = 1;
|
||||||
pub const PDDB_NOT_MOUNTED_ID: usize = 2;
|
pub const PDDB_NOT_MOUNTED_ID: usize = 2;
|
||||||
|
|
@ -84,6 +85,7 @@ pub struct MtxChat<'a> {
|
||||||
new_username: bool,
|
new_username: bool,
|
||||||
new_room: bool,
|
new_room: bool,
|
||||||
status: String,
|
status: String,
|
||||||
|
tt: Ticktimer,
|
||||||
}
|
}
|
||||||
impl<'a> MtxChat<'a> {
|
impl<'a> MtxChat<'a> {
|
||||||
pub fn new(chat: &Chat) -> MtxChat {
|
pub fn new(chat: &Chat) -> MtxChat {
|
||||||
|
|
@ -117,6 +119,7 @@ impl<'a> MtxChat<'a> {
|
||||||
new_username: false,
|
new_username: false,
|
||||||
new_room: false,
|
new_room: false,
|
||||||
status,
|
status,
|
||||||
|
tt: ticktimer_server::Ticktimer::new().unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -674,25 +677,23 @@ impl<'a> MtxChat<'a> {
|
||||||
|
|
||||||
while self.wifi_try_modal() {
|
while self.wifi_try_modal() {
|
||||||
self.netmgr.connection_manager_wifi_on_and_run().unwrap();
|
self.netmgr.connection_manager_wifi_on_and_run().unwrap();
|
||||||
self.modals
|
self.chat.set_status_text(t!("mtxchat.busy.connecting", locales::LANG));
|
||||||
.start_progress("Connecting ...", 0, 10, 0)
|
self.chat.set_busy_state(true);
|
||||||
.expect("no progress bar");
|
let start = self.tt.elapsed_ms();
|
||||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
while self.tt.elapsed_ms() - start < WIFI_TIMEOUT_MS as u64 {
|
||||||
for wait in 0..WIFI_TIMEOUT {
|
|
||||||
tt.sleep_ms(1000).unwrap();
|
|
||||||
self.modals
|
|
||||||
.update_progress(wait)
|
|
||||||
.expect("no progress update");
|
|
||||||
if let Some(conf) = self.netmgr.get_ipv4_config() {
|
if let Some(conf) = self.netmgr.get_ipv4_config() {
|
||||||
if conf.dhcp == com_rs::DhcpState::Bound {
|
if conf.dhcp == com_rs::DhcpState::Bound {
|
||||||
self.modals
|
self.chat.set_busy_state(false);
|
||||||
.finish_progress()
|
self.chat.set_status_text(&self.status);
|
||||||
.expect("failed progress finish");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.tt.sleep_ms(1000).unwrap();
|
||||||
}
|
}
|
||||||
|
self.modals.show_notification(t!("mtxchat.wifi.warning", locales::LANG), None).unwrap();
|
||||||
}
|
}
|
||||||
|
self.chat.set_busy_state(false);
|
||||||
|
self.chat.set_status_text(t!("mtxchat.wifi.warning_status", locales::LANG));
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{get_username, web, MTX_LONG_TIMEOUT};
|
use crate::{get_username, web, MTX_LONG_TIMEOUT_MS};
|
||||||
use chat::ChatOp;
|
use chat::ChatOp;
|
||||||
use modals::Modals;
|
use modals::Modals;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
@ -18,7 +18,7 @@ pub fn listen(
|
||||||
) {
|
) {
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
let modals = Modals::new(&xns).expect("can't connect to Modals server");
|
let modals = Modals::new(&xns).expect("can't connect to Modals server");
|
||||||
log::info!("client_sync for {} ms...", MTX_LONG_TIMEOUT);
|
log::info!("client_sync for {} ms...", MTX_LONG_TIMEOUT_MS);
|
||||||
|
|
||||||
let mut agent = ureq::builder()
|
let mut agent = ureq::builder()
|
||||||
.tls_connector(Arc::new(TlsConnector{}))
|
.tls_connector(Arc::new(TlsConnector{}))
|
||||||
|
|
@ -27,7 +27,7 @@ pub fn listen(
|
||||||
url,
|
url,
|
||||||
filter,
|
filter,
|
||||||
since,
|
since,
|
||||||
MTX_LONG_TIMEOUT,
|
MTX_LONG_TIMEOUT_MS,
|
||||||
&room_id,
|
&room_id,
|
||||||
&token,
|
&token,
|
||||||
&mut agent,
|
&mut agent,
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ use xous::{MessageEnvelope, CID};
|
||||||
|
|
||||||
use xous_names::XousNames;
|
use xous_names::XousNames;
|
||||||
|
|
||||||
pub const BUSY_ANIMATION_RATE_MS: usize = 50;
|
pub const BUSY_ANIMATION_RATE_MS: usize = 200;
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(crate) struct Ui {
|
pub(crate) struct Ui {
|
||||||
|
|
@ -627,6 +627,7 @@ impl Ui {
|
||||||
pub(crate) fn redraw_busy(&mut self) -> Result<(), xous::Error> {
|
pub(crate) fn redraw_busy(&mut self) -> Result<(), xous::Error> {
|
||||||
let curtime = self.tt.elapsed_ms();
|
let curtime = self.tt.elapsed_ms();
|
||||||
if curtime - self.status_last_update_ms > BUSY_ANIMATION_RATE_MS as u64 {
|
if curtime - self.status_last_update_ms > BUSY_ANIMATION_RATE_MS as u64 {
|
||||||
|
log::info!("update!");
|
||||||
self.gam.post_textview(&mut self.status_tv)?;
|
self.gam.post_textview(&mut self.status_tv)?;
|
||||||
self.gam.redraw().expect("couldn't redraw screen");
|
self.gam.redraw().expect("couldn't redraw screen");
|
||||||
self.status_last_update_ms = curtime;
|
self.status_last_update_ms = curtime;
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,7 @@ impl Gam {
|
||||||
tv.bounds_computed = tvr.bounds_computed;
|
tv.bounds_computed = tvr.bounds_computed;
|
||||||
tv.cursor = tvr.cursor;
|
tv.cursor = tvr.cursor;
|
||||||
tv.overflow = tvr.overflow;
|
tv.overflow = tvr.overflow;
|
||||||
|
tv.busy_animation_state = tvr.busy_animation_state;
|
||||||
}
|
}
|
||||||
api::Return::NotCurrentlyDrawable => {
|
api::Return::NotCurrentlyDrawable => {
|
||||||
tv.bounds_computed = None;
|
tv.bounds_computed = None;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue