diff --git a/pros-sys/src/misc.rs b/pros-sys/src/misc.rs index 6b01cadd..49ad8aaf 100644 --- a/pros-sys/src/misc.rs +++ b/pros-sys/src/misc.rs @@ -2,11 +2,14 @@ use core::ffi::*; pub const NUM_V5_PORTS: usize = 21; // v5 comp -pub const COMPETITION_DISABLED: i32 = 0b001; -pub const COMPETITION_AUTONOMOUS: i32 = 0b010; -pub const COMPETITION_CONNECTED: i32 = 0b100; +pub const COMPETITION_AUTONOMOUS: u8 = 1 << 0; +pub const COMPETITION_DISABLED: u8 = 1 << 1; +pub const COMPETITION_CONNECTED: u8 = 1 << 2; extern "C" { pub fn competition_get_status() -> u8; + pub fn competition_is_autonomous() -> bool; + pub fn competition_is_connected() -> bool; + pub fn competition_is_disabled() -> bool; } // controller pub const E_CONTROLLER_MASTER: c_uint = 0; diff --git a/pros/src/battery.rs b/pros/src/battery.rs new file mode 100644 index 00000000..7291a928 --- /dev/null +++ b/pros/src/battery.rs @@ -0,0 +1,19 @@ +/// Get the robot's battery capacity. +pub fn get_capacity() -> f64 { + unsafe { pros_sys::misc::battery_get_capacity() } +} + +/// Get the electric current of the robot's battery. +pub fn get_current() -> i32 { + unsafe { pros_sys::misc::battery_get_current() } +} + +/// Get the current temperature of the robot's battery. +pub fn get_temperature() -> f64 { + unsafe { pros_sys::misc::battery_get_temperature() } +} + +/// Get the robot's battery voltage. +pub fn get_voltage() -> i32 { + unsafe { pros_sys::misc::battery_get_voltage() } +} diff --git a/pros/src/competition.rs b/pros/src/competition.rs new file mode 100644 index 00000000..47d16afe --- /dev/null +++ b/pros/src/competition.rs @@ -0,0 +1,36 @@ +/// The current status of the robot, allowing checks to be made +/// for autonomous, disabled, and connected states. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct CompetitionStatus(pub u8); + +impl CompetitionStatus { + pub const fn autonomous(&self) -> bool { + self.0 & pros_sys::misc::COMPETITION_AUTONOMOUS != 0 + } + pub const fn disabled(&self) -> bool { + self.0 & pros_sys::misc::COMPETITION_DISABLED != 0 + } + pub const fn connected(&self) -> bool { + self.0 & pros_sys::misc::COMPETITION_CONNECTED != 0 + } +} + +/// Get the current status of the robot. +pub fn get_status() -> CompetitionStatus { + CompetitionStatus(unsafe { pros_sys::misc::competition_get_status() }) +} + +/// Check if the robot is in autonomous mode. +pub fn is_autonomous() -> bool { + unsafe { pros_sys::misc::competition_is_autonomous() } +} + +/// Check if the robot is disabled. +pub fn is_disabled() -> bool { + unsafe { pros_sys::misc::competition_is_disabled() } +} + +/// Check if the robot is connected to a VEX field or competition switch. +pub fn is_connected() -> bool { + unsafe { pros_sys::misc::competition_is_connected() } +} diff --git a/pros/src/lib.rs b/pros/src/lib.rs index b911c5a8..b7e4ceaf 100644 --- a/pros/src/lib.rs +++ b/pros/src/lib.rs @@ -22,8 +22,11 @@ mod wasm_env; #[macro_use] pub mod lcd; pub mod adi; +pub mod battery; +pub mod competition; pub mod link; pub mod lvgl; +pub mod usd; pub use async_trait::async_trait; diff --git a/pros/src/usd.rs b/pros/src/usd.rs new file mode 100644 index 00000000..1167e45f --- /dev/null +++ b/pros/src/usd.rs @@ -0,0 +1,4 @@ +/// Checks if an SD card is installed. +pub fn usd_installed() -> bool { + unsafe { pros_sys::misc::usd_is_installed() == 1 } +}