use super::sensor_util;
use std::f64::NAN;
use wpilib_sys::usage::{instances, resource_types};
use wpilib_sys::*;
#[derive(Debug)]
pub struct PowerDistributionPanel {
handle: HAL_PDPHandle,
}
impl PowerDistributionPanel {
#[allow(clippy::new_ret_no_self)]
pub fn new() -> HalResult<PowerDistributionPanel> {
Self::new_with_module(0)
}
pub fn new_with_module(module: i32) -> HalResult<PowerDistributionPanel> {
let handle = hal_call!(HAL_InitializePDP(module))?;
report_usage(resource_types::PDP, module as instances::Type);
Ok(PowerDistributionPanel { handle })
}
pub fn voltage(&self) -> HalMaybe<f64> {
maybe_hal_call!(HAL_GetPDPVoltage(self.handle))
}
pub fn temperature(&self) -> HalMaybe<f64> {
maybe_hal_call!(HAL_GetPDPTemperature(self.handle))
}
pub fn current(&self, channel: i32) -> HalMaybe<f64> {
if !sensor_util::check_pdp_channel(channel) {
return HalMaybe::new(NAN, Some(HalError(0)));
}
maybe_hal_call!(HAL_GetPDPChannelCurrent(self.handle, channel))
}
pub fn total_current(&self) -> HalMaybe<f64> {
maybe_hal_call!(HAL_GetPDPTotalCurrent(self.handle))
}
pub fn total_power(&self) -> HalMaybe<f64> {
maybe_hal_call!(HAL_GetPDPTotalPower(self.handle))
}
pub fn total_energy(&self) -> HalMaybe<f64> {
maybe_hal_call!(HAL_GetPDPTotalEnergy(self.handle))
}
pub fn reset_total_energy(&self) -> HalResult<()> {
hal_call!(HAL_ResetPDPTotalEnergy(self.handle))
}
pub fn clear_sticky_faults(&self) -> HalResult<()> {
hal_call!(HAL_ClearPDPStickyFaults(self.handle))
}
}