This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from Tropix126/feat/adi-addrled-solenoid
fix: Configure ADI devices, `AdiAnalogOut` -> `AdiPwmOut`
- Loading branch information
Showing
9 changed files
with
144 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! ADI Pulse-width modulation (PWM). | ||
use pros_sys::PROS_ERR; | ||
|
||
use super::{AdiDevice, AdiDeviceType, AdiError, AdiPort}; | ||
use crate::error::bail_on; | ||
|
||
/// Generic PWM output ADI device. | ||
#[derive(Debug, Eq, PartialEq)] | ||
pub struct AdiPwmOut { | ||
port: AdiPort, | ||
} | ||
|
||
impl AdiPwmOut { | ||
/// Create a pwm output from an [`AdiPort`]. | ||
pub fn new(port: AdiPort) -> Result<Self, AdiError> { | ||
bail_on!(PROS_ERR, unsafe { | ||
pros_sys::ext_adi_port_set_config( | ||
port.internal_expander_index(), | ||
port.index(), | ||
pros_sys::E_ADI_ANALOG_OUT, | ||
) | ||
}); | ||
|
||
Ok(Self { port }) | ||
} | ||
|
||
/// Sets the PWM output width. | ||
/// | ||
/// This value is sent over 16ms periods with pulse widths ranging from roughly | ||
/// 0.94mS to 2.03mS. | ||
pub fn set_output(&mut self, value: u8) -> Result<(), AdiError> { | ||
bail_on!(PROS_ERR, unsafe { | ||
pros_sys::ext_adi_port_set_value( | ||
self.port.internal_expander_index(), | ||
self.port.index(), | ||
value as i32, | ||
) | ||
}); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl AdiDevice for AdiPwmOut { | ||
type PortIndexOutput = u8; | ||
|
||
fn port_index(&self) -> Self::PortIndexOutput { | ||
self.port.index() | ||
} | ||
|
||
fn expander_port_index(&self) -> Option<u8> { | ||
self.port.expander_index() | ||
} | ||
|
||
fn device_type(&self) -> AdiDeviceType { | ||
AdiDeviceType::PwmOut | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters