From 22e217a85f70ebb7efeb10b2c87ddbb220739f01 Mon Sep 17 00:00:00 2001 From: Guy Garcia Date: Sun, 1 Oct 2023 14:57:17 -0400 Subject: [PATCH 1/4] Added remaining datetime related functions --- src/system.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/system.rs b/src/system.rs index 4ded03a..7aac819 100644 --- a/src/system.rs +++ b/src/system.rs @@ -5,6 +5,7 @@ use { use crankstart_sys::ctypes::c_int; pub use crankstart_sys::PDButtons; +use crankstart_sys::PDDateTime; static mut SYSTEM: System = System(ptr::null_mut()); @@ -117,6 +118,24 @@ impl System { Ok(pd_func_caller!((*self.0).getCurrentTimeMilliseconds)? as usize) } + pub fn get_timezone_offset(&self) -> Result { + pd_func_caller!((*self.0).getTimezoneOffset) + } + + pub fn convert_epoch_to_datetime(&self, epoch: u32) -> Result { + let mut datetime = PDDateTime::default(); + pd_func_caller!((*self.0).convertEpochToDateTime, epoch, &mut datetime)?; + Ok(datetime) + } + + pub fn convert_datetime_to_epoch(&self, datetime: &mut PDDateTime) -> Result { + Ok(pd_func_caller!((*self.0).convertDateTimeToEpoch, datetime)? as usize) + } + + pub fn should_display_24_hour_time(&self) -> Result { + Ok(pd_func_caller!((*self.0).shouldDisplay24HourTime)? != 0) + } + pub fn reset_elapsed_time(&self) -> Result<(), Error> { pd_func_caller!((*self.0).resetElapsedTime) } From 1a57dca72acbcb6bde1d5aa483aa5ed75e3479c0 Mon Sep 17 00:00:00 2001 From: Guy Garcia Date: Sun, 1 Oct 2023 15:04:51 -0400 Subject: [PATCH 2/4] Added more misc features --- src/system.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/system.rs b/src/system.rs index 7aac819..9093e84 100644 --- a/src/system.rs +++ b/src/system.rs @@ -144,7 +144,23 @@ impl System { Ok(pd_func_caller!((*self.0).getElapsedTime)? as f32) } + pub fn get_flipped(&self) -> Result { + Ok(pd_func_caller!((*self.0).getFlipped)? != 0) + } + + pub fn get_reduced_flashing(&self) -> Result { + Ok(pd_func_caller!((*self.0).getReduceFlashing)? != 0) + } + pub fn draw_fps(&self, x: i32, y: i32) -> Result<(), Error> { pd_func_caller!((*self.0).drawFPS, x, y) } + + pub fn get_battery_percentage(&self) -> Result { + pd_func_caller!((*self.0).getBatteryPercentage) + } + + pub fn get_battery_voltage(&self) -> Result { + pd_func_caller!((*self.0).getBatteryVoltage) + } } From d37d8f309b3201604c296da82e976ddaec8ae9b5 Mon Sep 17 00:00:00 2001 From: Guy Garcia Date: Sun, 1 Oct 2023 15:09:41 -0400 Subject: [PATCH 3/4] Added missing peripheral features --- src/system.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/system.rs b/src/system.rs index 9093e84..256b3c4 100644 --- a/src/system.rs +++ b/src/system.rs @@ -5,7 +5,7 @@ use { use crankstart_sys::ctypes::c_int; pub use crankstart_sys::PDButtons; -use crankstart_sys::PDDateTime; +use crankstart_sys::{PDDateTime, PDLanguage, PDPeripherals}; static mut SYSTEM: System = System(ptr::null_mut()); @@ -47,6 +47,18 @@ impl System { Ok((current, pushed, released)) } + pub fn set_peripherals_enabled(&self, peripherals: PDPeripherals) -> Result<(), Error> { + pd_func_caller!((*self.0).setPeripheralsEnabled, peripherals) + } + + pub fn get_accelerometer(&self) -> Result<(f32, f32, f32), Error> { + let mut outx = 0.0; + let mut outy = 0.0; + let mut outz = 0.0; + pd_func_caller!((*self.0).getAccelerometer, &mut outx, &mut outy, &mut outz)?; + Ok((outx, outy, outz)) + } + pub fn is_crank_docked(&self) -> Result { let docked: bool = pd_func_caller!((*self.0).isCrankDocked)? != 0; Ok(docked) @@ -163,4 +175,8 @@ impl System { pub fn get_battery_voltage(&self) -> Result { pd_func_caller!((*self.0).getBatteryVoltage) } + + pub fn get_language(&self) -> Result { + pd_func_caller!((*self.0).getLanguage) + } } From 7f9946a3017e664e735ddcde89bdbe16fb14eb8e Mon Sep 17 00:00:00 2001 From: Guy Garcia Date: Sun, 1 Oct 2023 15:10:17 -0400 Subject: [PATCH 4/4] Removed unnecessary cast --- src/system.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system.rs b/src/system.rs index 256b3c4..5c952ca 100644 --- a/src/system.rs +++ b/src/system.rs @@ -153,7 +153,7 @@ impl System { } pub fn get_elapsed_time(&self) -> Result { - Ok(pd_func_caller!((*self.0).getElapsedTime)? as f32) + pd_func_caller!((*self.0).getElapsedTime) } pub fn get_flipped(&self) -> Result {