diff options
Diffstat (limited to 'src/devices/clock_device.rs')
-rw-r--r-- | src/devices/clock_device.rs | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/src/devices/clock_device.rs b/src/devices/clock_device.rs index 494e0c7..7cc877e 100644 --- a/src/devices/clock_device.rs +++ b/src/devices/clock_device.rs @@ -1,20 +1,9 @@ use bedrock_core::*; +use chrono::prelude::*; use std::time::{Duration, Instant}; -macro_rules! now { () => { - time::OffsetDateTime::now_local() - .unwrap_or_else(|_| time::OffsetDateTime::now_utc()) -}; } - -fn current_year() -> u8 { now!().year().saturating_sub(2000) as u8 } -fn current_month() -> u8 { now!().month() as u8 - 1 } -fn current_day() -> u8 { now!().day() as u8 - 1 } -fn current_hour() -> u8 { now!().hour() } -fn current_minute() -> u8 { now!().minute() } -fn current_second() -> u8 { now!().second() } - macro_rules! fn_read_timer { ($fn_name:ident($read:ident, $end:ident)) => { pub fn $fn_name(&mut self) { @@ -123,12 +112,12 @@ impl ClockDevice { impl Device for ClockDevice { fn read(&mut self, port: u8) -> u8 { match port { - 0x0 => current_year(), - 0x1 => current_month(), - 0x2 => current_day(), - 0x3 => current_hour(), - 0x4 => current_minute(), - 0x5 => current_second(), + 0x0 => Local::now().year().saturating_sub(2000) as u8, + 0x1 => Local::now().month().saturating_sub(1) as u8, + 0x2 => Local::now().day().saturating_sub(1) as u8, + 0x3 => Local::now().hour() as u8, + 0x4 => Local::now().minute() as u8, + 0x5 => Local::now().second() as u8, 0x6 => { self.read_uptime(); read_h!(self.uptime_read) }, 0x7 => read_l!(self.uptime_read), 0x8 => { self.read_t1(); read_h!(self.t1_read) }, |