use ::error::*;
use ::handle::*;
use ::raw::*;
use std::ffi::CStr;
use std::os::raw::c_char;
use std::sync::Mutex;
lazy_static! {
static ref HAL_INITIALIZED: Mutex<bool> = Mutex::new(false);
}
pub mod handle;
pub mod accelerometer;
pub mod accumulator;
pub mod analog_gyro;
pub mod analog_input;
pub mod analog_output;
pub mod analog_trigger;
pub mod can;
pub mod compressor;
pub mod counter;
pub mod dio;
pub mod driverstation;
pub mod i2c;
pub mod interrupt;
pub mod notifier;
pub mod pdp;
pub mod ports;
pub mod power;
pub mod pwm;
pub mod relay;
pub mod halio;
pub mod serial;
pub mod solenoid;
pub mod spi;
pub type RawRuntimeType = HAL_RuntimeType;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum RuntimeType {
Native,
Mock,
}
impl From<RawRuntimeType> for RuntimeType {
fn from(raw: RawRuntimeType) -> Self {
match raw {
HAL_RuntimeType::HAL_Athena => RuntimeType::Native,
HAL_RuntimeType::HAL_Mock => RuntimeType::Mock,
}
}
}
pub fn get_system_clock_ticks_per_microsecond() -> i32 {
unsafe { HAL_GetSystemClockTicksPerMicrosecond() }
}
pub fn get_error_message(code: i32) -> String {
let char_ptr = unsafe { HAL_GetErrorMessage(code) };
unsafe { CStr::from_ptr(char_ptr).to_string_lossy().into_owned() }
}
pub fn get_fpga_version() -> HalResult<i32> {
unsafe { hal_call![ ptr HAL_GetFPGAVersion() ] }
}
pub fn get_fpga_revision() -> HalResult<i64> {
unsafe { hal_call![ ptr HAL_GetFPGARevision() ] }
}
pub fn get_runtime_type() -> RuntimeType {
unsafe { RuntimeType::from(HAL_GetRuntimeType()) }
}
pub fn get_fpga_button() -> HalResult<bool> {
unsafe { hal_call![ ptr HAL_GetFPGAButton() ].map(|n| n != 0) }
}
pub fn get_system_active() -> HalResult<bool> {
unsafe { hal_call![ ptr HAL_GetSystemActive() ].map(|n| n != 0) }
}
pub fn get_browned_out() -> HalResult<bool> {
unsafe { hal_call![ ptr HAL_GetBrownedOut() ].map(|n| n != 0) }
}
pub fn base_initialize() -> HalResult<()> {
unsafe { hal_call![ ptr HAL_BaseInitialize() ] }
}
pub fn get_port(channel: i32) -> PortHandle {
unsafe { HAL_GetPort(channel) }
}
pub fn get_port_with_module(module: i32, channel: i32) -> PortHandle {
unsafe { HAL_GetPortWithModule(module, channel) }
}
pub fn get_fpga_time() -> HalResult<u64> {
unsafe { hal_call![ ptr HAL_GetFPGATime() ] }
}
pub fn hal_initialize(mode: i32) -> i32 {
let mut initialized = HAL_INITIALIZED.lock().unwrap();
*initialized = true;
unsafe { HAL_Initialize(mode) }
}
pub fn hal_is_initialized() -> bool {
*HAL_INITIALIZED.lock().unwrap()
}
pub fn report(resource: i32, instance_number: i32, context: i32, feature: &[u8]) -> i64 {
unsafe {
HAL_Report(resource,
instance_number,
context,
feature.as_ptr() as *const c_char)
}
}