Skip to content

Commit

Permalink
Add most missing system features (#69)
Browse files Browse the repository at this point in the history
* Added remaining datetime related functions

* Added more misc features

* Added missing peripheral features

* Removed unnecessary cast
  • Loading branch information
FloppyDisck authored Oct 29, 2023
1 parent c944ce6 commit fd7b612
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use {

use crankstart_sys::ctypes::c_int;
pub use crankstart_sys::PDButtons;
use crankstart_sys::{PDDateTime, PDLanguage, PDPeripherals};

static mut SYSTEM: System = System(ptr::null_mut());

Expand Down Expand Up @@ -46,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<bool, Error> {
let docked: bool = pd_func_caller!((*self.0).isCrankDocked)? != 0;
Ok(docked)
Expand Down Expand Up @@ -117,15 +130,53 @@ impl System {
Ok(pd_func_caller!((*self.0).getCurrentTimeMilliseconds)? as usize)
}

pub fn get_timezone_offset(&self) -> Result<i32, Error> {
pd_func_caller!((*self.0).getTimezoneOffset)
}

pub fn convert_epoch_to_datetime(&self, epoch: u32) -> Result<PDDateTime, Error> {
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<usize, Error> {
Ok(pd_func_caller!((*self.0).convertDateTimeToEpoch, datetime)? as usize)
}

pub fn should_display_24_hour_time(&self) -> Result<bool, Error> {
Ok(pd_func_caller!((*self.0).shouldDisplay24HourTime)? != 0)
}

pub fn reset_elapsed_time(&self) -> Result<(), Error> {
pd_func_caller!((*self.0).resetElapsedTime)
}

pub fn get_elapsed_time(&self) -> Result<f32, Error> {
Ok(pd_func_caller!((*self.0).getElapsedTime)?)
pd_func_caller!((*self.0).getElapsedTime)
}

pub fn get_flipped(&self) -> Result<bool, Error> {
Ok(pd_func_caller!((*self.0).getFlipped)? != 0)
}

pub fn get_reduced_flashing(&self) -> Result<bool, Error> {
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<f32, Error> {
pd_func_caller!((*self.0).getBatteryPercentage)
}

pub fn get_battery_voltage(&self) -> Result<f32, Error> {
pd_func_caller!((*self.0).getBatteryVoltage)
}

pub fn get_language(&self) -> Result<PDLanguage, Error> {
pd_func_caller!((*self.0).getLanguage)
}
}

0 comments on commit fd7b612

Please sign in to comment.