From b06e8d2a81349e31a3bda9515b5c6aa3a5cff378 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 16 May 2021 02:26:24 +0800 Subject: [PATCH] fix issue with datetime on hosted mode on windows just monkey-patch over the call in hosted mode... --- Cargo.lock | 1 + services/gam/Cargo.toml | 4 ++++ services/gam/src/status.rs | 30 ++++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 37e356450..930cba46d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -524,6 +524,7 @@ version = "0.1.0" dependencies = [ "bitflags", "blitstr-ref", + "chrono", "com", "content-plugin-api", "graphics-server", diff --git a/services/gam/Cargo.toml b/services/gam/Cargo.toml index 93af84092..f0924ab9d 100644 --- a/services/gam/Cargo.toml +++ b/services/gam/Cargo.toml @@ -30,6 +30,10 @@ rkyv = {version = "0.4.3", default-features = false, features = ["const_generics [target.'cfg(not(any(windows,unix)))'.dependencies] utralib = {path = "../../utralib"} +# short circuit the datetime call on hosted mode +[target.'cfg(any(windows,unix))'.dependencies] +chrono = "0.4" + [features] debugprint = [] slowstatus = [] # used for braille mode, so console isn't overwhelmed with status diff --git a/services/gam/src/status.rs b/services/gam/src/status.rs index 753862708..2509e1c3b 100644 --- a/services/gam/src/status.rs +++ b/services/gam/src/status.rs @@ -33,7 +33,7 @@ fn battstats_cb(stats: BattStats) { } pub fn dt_callback(dt: rtc::DateTime) { - //log::trace!("dt_callback received with {:?}", dt); + //log::info!("dt_callback received with {:?}", dt); if let Some(cb_to_main_conn) = unsafe{CB_TO_MAIN_CONN} { let buf = xous_ipc::Buffer::into_buf(dt).or(Err(xous::Error::InternalError)).unwrap(); buf.send(cb_to_main_conn, StatusOpcode::DateTime.to_u32().unwrap()).unwrap(); @@ -158,7 +158,33 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi dt_pump_modulus += 1; if dt_pump_modulus > 15 { dt_pump_modulus = 0; + #[cfg(target_os = "none")] rtc.request_datetime().expect("|status: can't request datetime from RTC"); + #[cfg(not(target_os = "none"))] + { + log::trace!("hosted request of date time - short circuiting server call"); + use chrono::prelude::*; + use rtc::Weekday; + let now = Local::now(); + let wday: Weekday = match now.weekday() { + chrono::Weekday::Mon => Weekday::Monday, + chrono::Weekday::Tue => Weekday::Tuesday, + chrono::Weekday::Wed => Weekday::Wednesday, + chrono::Weekday::Thu => Weekday::Thursday, + chrono::Weekday::Fri => Weekday::Friday, + chrono::Weekday::Sat => Weekday::Saturday, + chrono::Weekday::Sun => Weekday::Sunday, + }; + datetime = Some(rtc::DateTime { + seconds: now.second() as u8, + minutes: now.minute() as u8, + hours: now.hour() as u8, + months: now.month() as u8, + days: now.day() as u8, + years: (now.year() - 2000) as u8, + weekday: wday, + }); + } } last_seconds = now_seconds; uptime_tv.clear_str(); @@ -192,7 +218,7 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi } } Some(StatusOpcode::DateTime) => { - //log::trace!("got DateTime update"); + //log::info!("got DateTime update"); let buffer = unsafe { xous_ipc::Buffer::from_memory_message(msg.body.memory_message().unwrap()) }; let dt = buffer.to_original::().unwrap(); datetime = Some(dt);