Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add most missing system features #69

Merged
merged 5 commits into from
Oct 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}