Merge branch 'bunnie-dev' into main

This commit is contained in:
bunnie 2022-03-28 15:40:10 +08:00
commit 6a7ac73034
8 changed files with 274 additions and 233 deletions

View file

@ -94,6 +94,7 @@ pub(crate) struct ContextManager {
main_menu_app_token: Option<[u32; 4]>, // app_token of the main menu, if it has been registered
/// for internal generation of deface states
pub trng: trng::Trng,
tt: ticktimer_server::Ticktimer,
}
impl ContextManager {
pub fn new(xns: &xous_names::XousNames) -> Self {
@ -114,6 +115,7 @@ impl ContextManager {
kbd,
main_menu_app_token: None,
trng: trng::Trng::new(&xns).expect("couldn't connect to trng"),
tt: ticktimer_server::Ticktimer::new().unwrap(),
}
}
pub(crate) fn claim_token(&mut self, name: &str) -> Option<[u32; 4]> {
@ -465,10 +467,15 @@ impl ContextManager {
pub(crate) fn redraw(&self) -> Result<(), xous::Error> { // redraws the currently focused context
if let Some(token) = self.focused_app() {
if let Some(context) = self.contexts.get(&token) {
log::trace!("redraw msg to {}, id {}", context.listener, context.redraw_id);
return xous::send_message(context.listener,
log::info!("redraw msg to {}, id {}", context.listener, context.redraw_id);
let ret = xous::send_message(context.listener,
xous::Message::new_scalar(context.redraw_id as usize, 0, 0, 0, 0)
).map(|_| ())
).map(|_| ());
// this delay helps ensure that the previously requested UX redraw has time to complete
// in particular, this helps sequence the case where one modal is erased, and the next one is
// raised, in quick succession.
self.tt.sleep_ms(20).unwrap();
return ret
}
} else {
return Err(xous::Error::UseBeforeInit)

View file

@ -292,6 +292,8 @@ impl<'a> Menu<'a> {
// give up focus before issuing the command, as some commands conflict with loss of focus...
if mi.close_on_select {
self.gam.relinquish_focus().unwrap();
#[cfg(not(any(target_os = "none", target_os = "xous")))]
ticktimer_server::Ticktimer::new().unwrap().sleep_ms(100).unwrap();
}
if let Some(action) = mi.action_conn {
log::debug!("doing menu action for {}", mi.name);
@ -314,8 +316,10 @@ impl<'a> Menu<'a> {
}
}
self.index = 0; // reset the index to 0
log::trace!("menu redraw## select key");
self.gam.redraw().unwrap();
if !mi.close_on_select { // fix a double-redraw issue. I relinquish_focus() maps to active() which contains a redraw() already.
log::trace!("menu redraw## select key");
self.gam.redraw().unwrap();
}
break; // drop any characters that happened to trail the select key, it's probably a fat-finger error.
},
'←' => {

View file

@ -561,7 +561,7 @@ fn xmain() -> ! {
Some(Opcode::GetRtcValue) => msg_blocking_scalar_unpack!(msg, _, _, _, _, {
use chrono::prelude::*;
let now = Local::now();
let total_secs = now.timestamp_millis() - 148409348; // sets the offset to something like 1974, which is roughly where an RTC value ends up in reality
let total_secs = now.timestamp_millis() / 1000 - 148409348; // sets the offset to something like 1974, which is roughly where an RTC value ends up in reality
xous::return_scalar2(msg.sender,
((total_secs >> 32) & 0xFFFF_FFFF) as usize,
(total_secs & 0xFFFF_FFFF) as usize,

View file

@ -88,7 +88,7 @@ fn xmain() -> ! {
let _redraw_handle = thread::spawn({
let op = Arc::clone(&op);
move || {
#[cfg(any(feature="tts", not(any(target_os = "none", target_os = "xous"))))]
#[cfg(feature="tts")]
let tt = ticktimer_server::Ticktimer::new().unwrap();
// build the core data structure here
let text_action = TextEntry {
@ -132,8 +132,6 @@ fn xmain() -> ! {
loop {
let msg = xous::receive_message(renderer_sid).unwrap();
#[cfg(not(any(target_os = "none", target_os = "xous")))]
tt.sleep_ms(100).unwrap(); // hosted mode needs delays to work
log::debug!("renderer message: {:?}", msg);
match FromPrimitive::from_usize(msg.body.id()) {
Some(RendererOp::InitiateOp) => {
@ -439,8 +437,6 @@ fn xmain() -> ! {
];
loop {
let mut msg = xous::receive_message(modals_sid).unwrap();
#[cfg(not(any(target_os = "none", target_os = "xous")))]
tt.sleep_ms(100).unwrap(); // hosted mode needs delays to work
log::debug!("message: {:?}", msg);
match FromPrimitive::from_usize(msg.body.id()) {
Some(Opcode::GetMutex) => msg_blocking_scalar_unpack!(msg, t0, t1, t2, t3, {

View file

@ -17,14 +17,12 @@ use xous::{msg_scalar_unpack, send_message, Message, CID};
use graphics_server::*;
use graphics_server::api::GlyphStyle;
use locales::t;
use gam::modal::*;
use gam::{GamObjectList, GamObjectType};
use chrono::prelude::*;
use std::collections::HashMap;
use std::sync::{Arc, Mutex};
use std::sync::atomic::{AtomicBool, Ordering};
use std::io::Read;
#[cfg_attr(
not(any(target_os = "none", target_os = "xous")),
@ -41,10 +39,6 @@ pub(crate) enum StatusOpcode {
BattStats,
/// indicates time for periodic update of the status bar
Pump,
/// Pulls up the time setting UI
UxSetTime,
/// Pulls up the time setting UI
UxSetTimeZone,
/// Initiates a reboot
Reboot,
@ -328,19 +322,25 @@ fn xmain() -> ! {
com.req_batt_stats()
.expect("Can't get battery stats from COM");
// spawn a time UX manager thread
let time_sid = xous::create_server().unwrap();
let time_cid = xous::connect(time_sid).unwrap();
time::start_time_ux(time_sid);
// this is used by the main loop to get the localtime to show on the status bar
let mut localtime = llio::LocalTime::new();
// used to hide time when the PDDB is not mounted
let pddb_poller = pddb::PddbMountPoller::new();
// used to show notifications, e.g. can't sleep while power is engaged.
let modals = modals::Modals::new(&xns).unwrap();
log::debug!("starting main menu thread");
create_main_menu(keys.clone(), xous::connect(status_sid).unwrap(), &com);
create_main_menu(keys.clone(), xous::connect(status_sid).unwrap(), &com, time_cid);
create_app_menu(xous::connect(status_sid).unwrap());
let kbd_mgr = xous::create_server().unwrap();
let kbd_menumatic = create_kbd_menu(xous::connect(status_sid).unwrap(), kbd_mgr);
let kbd = keyboard::Keyboard::new(&xns).unwrap();
// some RTC UX structures
let modals = modals::Modals::new(&xns).unwrap();
let timeserver_cid = xous::connect(xous::SID::from_bytes(crate::time::TIME_SERVER_PUBLIC).unwrap()).unwrap();
let mut localtime = llio::LocalTime::new();
let pddb_poller = pddb::PddbMountPoller::new();
log::debug!("subscribe to wifi updates");
netmgr.wifi_state_subscribe(cb_cid, StatusOpcode::WifiStats.to_u32().unwrap()).unwrap();
let mut wifi_status: WlanStatus = WlanStatus::from_ipc(WlanStatusIpc::default());
@ -572,135 +572,6 @@ fn xmain() -> ! {
stats_phase = stats_phase.wrapping_add(1);
}
Some(StatusOpcode::UxSetTime) => msg_scalar_unpack!(msg, _, _, _, _, {
if !pddb_poller.is_mounted_nonblocking() {
modals.show_notification(t!("stats.please_mount", xous::LANG)).expect("couldn't show notification");
continue;
}
pump_run.store(false, Ordering::Relaxed); // stop status updates while we do this
let mut tz_set_handle = pddb::Pddb::new();
let mut tz_set = false;
let mut tz_offset_ms = 0i64;
let maybe_tz_set_key = tz_set_handle.get(
time::TIME_SERVER_DICT,
time::TIME_SERVER_TZ_OFFSET,
None, false, false,
None,
None::<fn()>
).ok();
if let Some(mut tz_set_key) = maybe_tz_set_key {
let mut tz_buf = [0u8; 8];
if tz_set_key.read(&mut tz_buf).unwrap_or(0) == 8 {
tz_offset_ms = i64::from_le_bytes(tz_buf);
tz_set = true;
}
}
// note that we don't do an "else" here because we also want to catch the case of
// a key exists, but nothing was written to it (length of key was 0 or inappropriate)
if !tz_set {
let tz = modals.get_text(
t!("rtc.timezone", xous::LANG),
Some(tz_ux_validator), None
).expect("couldn't get timezone").as_str()
.parse::<f32>().expect("pre-validated input failed to re-parse!");
log::info!("got tz offset {}", tz);
tz_offset_ms = (tz * 3600.0 * 1000.0) as i64;
xous::send_message(timeserver_cid,
Message::new_scalar(
crate::time::TimeOp::SetTzOffsetMs.to_usize().unwrap(),
(tz_offset_ms >> 32) as usize,
(tz_offset_ms & 0xFFFF_FFFF) as usize,
0, 0,
)
).expect("couldn't set timezone");
}
let secs: u8;
let mins: u8;
let hours: u8;
let months: u8;
let days: u8;
let years: u8;
months = modals.get_text(
t!("rtc.month", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxMonth.to_u32().unwrap())
).expect("couldn't get month").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got months {}", months);
days = modals.get_text(
t!("rtc.day", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxDay.to_u32().unwrap())
).expect("couldn't get month").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got days {}", days);
years = modals.get_text(
t!("rtc.year", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxYear.to_u32().unwrap())
).expect("couldn't get month").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got years {}", years);
hours = modals.get_text(
t!("rtc.hour", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxHour.to_u32().unwrap())
).expect("couldn't get hour").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got hours {}", hours);
mins = modals.get_text(
t!("rtc.minute", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxMinute.to_u32().unwrap())
).expect("couldn't get minutes").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got minutes {}", mins);
secs = modals.get_text(
t!("rtc.seconds", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxSeconds.to_u32().unwrap())
).expect("couldn't get seconds").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got seconds {}", secs);
log::info!("Setting time: {}/{}/{} {}:{}:{}", months, days, years, hours, mins, secs);
let new_dt = chrono::FixedOffset::east((tz_offset_ms / 1000) as i32).ymd(years as i32 + 2000, months as u32, days as u32)
.and_hms(hours as u32, mins as u32, secs as u32);
xous::send_message(timeserver_cid,
Message::new_scalar(
crate::time::TimeOp::SetUtcTimeMs.to_usize().unwrap(),
((new_dt.timestamp_millis() as u64) >> 32) as usize,
(new_dt.timestamp_millis() as u64 & 0xFFFF_FFFF) as usize,
0, 0,
)
).expect("couldn't set time");
pump_run.store(true, Ordering::Relaxed); // stop status updates while we do this
}),
Some(StatusOpcode::UxSetTimeZone) => {
if !pddb_poller.is_mounted_nonblocking() {
modals.show_notification(t!("stats.please_mount", xous::LANG)).expect("couldn't show notification");
continue;
}
pump_run.store(false, Ordering::Relaxed); // stop status updates while we do this
let tz = modals.get_text(
t!("rtc.timezone", xous::LANG),
Some(tz_ux_validator), None
).expect("couldn't get timezone").as_str()
.parse::<f32>().expect("pre-validated input failed to re-parse!");
log::info!("got tz offset {}", tz);
let tzoff_ms = (tz * 3600.0 * 1000.0) as i64;
xous::send_message(timeserver_cid,
Message::new_scalar(
crate::time::TimeOp::SetTzOffsetMs.to_usize().unwrap(),
(tzoff_ms >> 32) as usize,
(tzoff_ms & 0xFFFF_FFFF) as usize,
0, 0,
)
).expect("couldn't set timezone");
pump_run.store(true, Ordering::Relaxed); // stop status updates while we do this
},
Some(StatusOpcode::Reboot) => {
if ((llio.adc_vbus().unwrap() as f64) * 0.005033) > 1.5 {
// power plugged in, do a reboot using a warm boot method
@ -806,70 +677,3 @@ fn xmain() -> ! {
xous::terminate_process(0)
}
// RTC helper functions
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
pub(crate) enum ValidatorOp {
UxMonth,
UxDay,
UxYear,
UxHour,
UxMinute,
UxSeconds,
}
fn tz_ux_validator(input: TextEntryPayload, _opcode: u32) -> Option<ValidatorErr> {
let text_str = input.as_str();
match text_str.parse::<f32>() {
Ok(input) => if input < -12.0 || input > 14.0 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)));
},
_ => return Some(ValidatorErr::from_str(t!("rtc.integer_err", xous::LANG))),
}
None
}
fn rtc_ux_validator(input: TextEntryPayload, opcode: u32) -> Option<ValidatorErr> {
let text_str = input.as_str();
let input_int = match text_str.parse::<u32>() {
Ok(input_int) => input_int,
_ => return Some(ValidatorErr::from_str(t!("rtc.integer_err", xous::LANG))),
};
log::trace!("validating input {}, parsed as {} for opcode {}", text_str, input_int, opcode);
match FromPrimitive::from_u32(opcode) {
Some(ValidatorOp::UxMonth) => {
if input_int < 1 || input_int > 12 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
Some(ValidatorOp::UxDay) => {
if input_int < 1 || input_int > 31 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
Some(ValidatorOp::UxYear) => {
if input_int > 99 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
Some(ValidatorOp::UxHour) => {
if input_int > 23 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
Some(ValidatorOp::UxMinute) => {
if input_int > 59 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
Some(ValidatorOp::UxSeconds) => {
if input_int > 59 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
_ => {
log::error!("internal error: invalid opcode was sent to validator: {:?}", opcode);
panic!("internal error: invalid opcode was sent to validator");
}
}
None
}

View file

@ -8,7 +8,7 @@ use num_traits::*;
use crate::StatusOpcode;
#[allow(unused_variables)] // quiets a warning about unused com that is emitted in tts config. Would be nice to make this more targeted...
pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, status_conn: xous::CID, com: &com::Com) {
pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, status_conn: xous::CID, com: &com::Com, time_ux_conn: xous::CID) {
let key_conn = keys.lock().unwrap().conn();
let mut menuitems = Vec::<MenuItem>::new();
@ -76,15 +76,15 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, status_conn: xous::CID, com:
menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.set_rtc", xous::LANG)),
action_conn: Some(status_conn),
action_opcode: StatusOpcode::UxSetTime.to_u32().unwrap(),
action_conn: Some(time_ux_conn),
action_opcode: crate::time::TimeUxOp::SetTime.to_u32().unwrap(),
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
close_on_select: true,
});
menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.set_tz", xous::LANG)),
action_conn: Some(status_conn),
action_opcode: StatusOpcode::UxSetTimeZone.to_u32().unwrap(),
action_conn: Some(time_ux_conn),
action_opcode: crate::time::TimeUxOp::SetTimeZone.to_u32().unwrap(),
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
close_on_select: true,
});

View file

@ -28,6 +28,11 @@ use llio::*;
use pddb::{Pddb, PddbMountPoller};
use std::io::{Read, Write, Seek, SeekFrom};
use num_traits::*;
// imports for time ux
use locales::t;
use chrono::prelude::*;
use xous::Message;
use gam::modal::*;
/// This is a "well known name" used by `libstd` to connect to the time server
/// Even thought it is "public" nobody connects to it directly, they connect to it via `libstd`
@ -85,6 +90,13 @@ pub(crate) enum PrivTimeOp {
ResetRtc = 0,
}
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
pub(crate) enum TimeUxOp {
SetTime,
SetTimeZone,
Quit,
}
pub fn start_time_server() {
let rtc_checked = Arc::new(AtomicBool::new(false));
@ -207,8 +219,8 @@ pub fn start_time_server() {
if tz_key.read(&mut tz_buf).unwrap_or(0) == 8 {
tz_offset_ms = i64::from_le_bytes(tz_buf);
}
log::debug!("offset_key: {}", utc_offset_ms);
log::debug!("tz_key: {}", tz_offset_ms);
log::debug!("offset_key: {}", utc_offset_ms / 1000);
log::debug!("tz_key: {}", tz_offset_ms / 1000);
log::debug!("start_rtc_secs: {}", start_rtc_secs);
log::debug!("start_tt_ms: {}", start_tt_ms);
loop {
@ -418,4 +430,222 @@ fn to_bcd(binary: u8) -> u8 {
}
(msd << 4) | lsd
}
}
pub fn start_time_ux(sid: xous::SID) {
thread::spawn({
move || {
// some RTC UX structures
let xns = xous_names::XousNames::new().unwrap();
let modals = modals::Modals::new(&xns).unwrap();
let timeserver_cid = xous::connect(xous::SID::from_bytes(crate::time::TIME_SERVER_PUBLIC).unwrap()).unwrap();
let pddb_poller = pddb::PddbMountPoller::new();
loop {
let msg = xous::receive_message(sid).unwrap();
match FromPrimitive::from_usize(msg.body.id()) {
Some(TimeUxOp::SetTime) => xous::msg_scalar_unpack!(msg, _, _, _, _, {
if !pddb_poller.is_mounted_nonblocking() {
modals.show_notification(t!("stats.please_mount", xous::LANG)).expect("couldn't show notification");
continue;
}
let mut tz_set_handle = pddb::Pddb::new();
let mut tz_set = false;
let mut tz_offset_ms = 0i64;
let maybe_tz_set_key = tz_set_handle.get(
TIME_SERVER_DICT,
TIME_SERVER_TZ_OFFSET,
None, false, false,
None,
None::<fn()>
).ok();
if let Some(mut tz_set_key) = maybe_tz_set_key {
let mut tz_buf = [0u8; 8];
if tz_set_key.read(&mut tz_buf).unwrap_or(0) == 8 {
tz_offset_ms = i64::from_le_bytes(tz_buf);
tz_set = true;
}
}
// note that we don't do an "else" here because we also want to catch the case of
// a key exists, but nothing was written to it (length of key was 0 or inappropriate)
if !tz_set {
let tz = modals.get_text(
t!("rtc.timezone", xous::LANG),
Some(tz_ux_validator), None
).expect("couldn't get timezone").as_str()
.parse::<f32>().expect("pre-validated input failed to re-parse!");
log::info!("got tz offset {}", tz);
tz_offset_ms = (tz * 3600.0 * 1000.0) as i64;
xous::send_message(timeserver_cid,
Message::new_scalar(
crate::time::TimeOp::SetTzOffsetMs.to_usize().unwrap(),
(tz_offset_ms >> 32) as usize,
(tz_offset_ms & 0xFFFF_FFFF) as usize,
0, 0,
)
).expect("couldn't set timezone");
}
let secs: u8;
let mins: u8;
let hours: u8;
let months: u8;
let days: u8;
let years: u8;
months = modals.get_text(
t!("rtc.month", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxMonth.to_u32().unwrap())
).expect("couldn't get month").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got months {}", months);
days = modals.get_text(
t!("rtc.day", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxDay.to_u32().unwrap())
).expect("couldn't get month").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got days {}", days);
years = modals.get_text(
t!("rtc.year", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxYear.to_u32().unwrap())
).expect("couldn't get month").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got years {}", years);
hours = modals.get_text(
t!("rtc.hour", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxHour.to_u32().unwrap())
).expect("couldn't get hour").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got hours {}", hours);
mins = modals.get_text(
t!("rtc.minute", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxMinute.to_u32().unwrap())
).expect("couldn't get minutes").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got minutes {}", mins);
secs = modals.get_text(
t!("rtc.seconds", xous::LANG),
Some(rtc_ux_validator), Some(ValidatorOp::UxSeconds.to_u32().unwrap())
).expect("couldn't get seconds").as_str()
.parse::<u8>().expect("pre-validated input failed to re-parse!");
log::debug!("got seconds {}", secs);
log::info!("Setting time: {}/{}/{} {}:{}:{}", months, days, years, hours, mins, secs);
let new_dt = chrono::FixedOffset::east((tz_offset_ms / 1000) as i32).ymd(years as i32 + 2000, months as u32, days as u32)
.and_hms(hours as u32, mins as u32, secs as u32);
xous::send_message(timeserver_cid,
Message::new_scalar(
crate::time::TimeOp::SetUtcTimeMs.to_usize().unwrap(),
((new_dt.timestamp_millis() as u64) >> 32) as usize,
(new_dt.timestamp_millis() as u64 & 0xFFFF_FFFF) as usize,
0, 0,
)
).expect("couldn't set time");
}),
Some(TimeUxOp::SetTimeZone) => xous::msg_scalar_unpack!(msg, _, _, _, _, {
if !pddb_poller.is_mounted_nonblocking() {
modals.show_notification(t!("stats.please_mount", xous::LANG)).expect("couldn't show notification");
continue;
}
let tz = modals.get_text(
t!("rtc.timezone", xous::LANG),
Some(tz_ux_validator), None
).expect("couldn't get timezone").as_str()
.parse::<f32>().expect("pre-validated input failed to re-parse!");
log::info!("got tz offset {}", tz);
let tzoff_ms = (tz * 3600.0 * 1000.0) as i64;
xous::send_message(timeserver_cid,
Message::new_scalar(
crate::time::TimeOp::SetTzOffsetMs.to_usize().unwrap(),
(tzoff_ms >> 32) as usize,
(tzoff_ms & 0xFFFF_FFFF) as usize,
0, 0,
)
).expect("couldn't set timezone");
}),
Some(TimeUxOp::Quit) => {
xous::return_scalar(msg.sender, 0).unwrap();
break;
}
None => {
log::warn!("unhandled opcode: {:?}", msg);
}
}
}
xous::destroy_server(sid).ok();
}
});
}
// RTC Ux helper functions
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
pub(crate) enum ValidatorOp {
UxMonth,
UxDay,
UxYear,
UxHour,
UxMinute,
UxSeconds,
}
fn tz_ux_validator(input: TextEntryPayload, _opcode: u32) -> Option<ValidatorErr> {
let text_str = input.as_str();
match text_str.parse::<f32>() {
Ok(input) => if input < -12.0 || input > 14.0 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)));
},
_ => return Some(ValidatorErr::from_str(t!("rtc.integer_err", xous::LANG))),
}
None
}
fn rtc_ux_validator(input: TextEntryPayload, opcode: u32) -> Option<ValidatorErr> {
let text_str = input.as_str();
let input_int = match text_str.parse::<u32>() {
Ok(input_int) => input_int,
_ => return Some(ValidatorErr::from_str(t!("rtc.integer_err", xous::LANG))),
};
log::trace!("validating input {}, parsed as {} for opcode {}", text_str, input_int, opcode);
match FromPrimitive::from_u32(opcode) {
Some(ValidatorOp::UxMonth) => {
if input_int < 1 || input_int > 12 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
Some(ValidatorOp::UxDay) => {
if input_int < 1 || input_int > 31 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
Some(ValidatorOp::UxYear) => {
if input_int > 99 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
Some(ValidatorOp::UxHour) => {
if input_int > 23 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
Some(ValidatorOp::UxMinute) => {
if input_int > 59 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
Some(ValidatorOp::UxSeconds) => {
if input_int > 59 {
return Some(ValidatorErr::from_str(t!("rtc.range_err", xous::LANG)))
}
}
_ => {
log::error!("internal error: invalid opcode was sent to validator: {:?}", opcode);
panic!("internal error: invalid opcode was sent to validator");
}
}
None
}

View file

@ -210,10 +210,10 @@ pub(crate) fn thread_id() -> TID {
let call = crate::SysCall::CreateThread(ThreadInit {});
let fake_tid = FAKE_THREAD_COUNTER.fetch_add(1, Ordering::SeqCst);
println!(
"Thread ID not defined! Creating a fake thread. Syscall TID: {}.",
fake_tid
);
// println!(
// "Thread ID not defined! Creating a fake thread. Syscall TID: {}.",
// fake_tid
// );
// assert!(SERVER_CONNECTION
// .call_tracker
@ -236,7 +236,7 @@ pub(crate) fn thread_id() -> TID {
} else {
panic!("unable to get new TID, got response: {:?}", response)
};
println!("Created a fake thread ID: {}", new_tid);
// println!("Created a fake thread ID: {}", new_tid);
*tid.borrow_mut() = Some(new_tid);
new_tid
})