Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
refactor: make AdiEncoder return Position
Browse files Browse the repository at this point in the history
  • Loading branch information
Tropix126 committed Mar 13, 2024
1 parent 8fa3eaf commit a50919b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Before releasing:
- Renamed `Motor::get_state` to `Motor::status`.
- Status structs containing device bits now use the `bitflags!` crate. (**Breaking Change**) (#66)
- Renamed `InertialSensor::calibrating` to `InertialSensor::calibrating` (**Breaking CHange**) (#66)
- AdiEncoder now returns `Position` rather than just degrees.

### Removed

Expand Down
10 changes: 7 additions & 3 deletions packages/pros-devices/src/adi/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
use pros_core::bail_on;
use pros_sys::{ext_adi_encoder_t, PROS_ERR};

use crate::Position;

use super::{AdiDevice, AdiDeviceType, AdiError, AdiPort};

/// ADI encoder device.
Expand Down Expand Up @@ -49,10 +51,12 @@ impl AdiEncoder {
}

/// Gets the number of ticks recorded by the encoder.
pub fn position(&self) -> Result<i32, AdiError> {
Ok(bail_on!(PROS_ERR, unsafe {
pub fn position(&self) -> Result<Position, AdiError> {
let degrees = bail_on!(PROS_ERR, unsafe {
pros_sys::adi_encoder_get(self.raw)
}))
});

Ok(Position::from_degrees(degrees as f64))
}
}

Expand Down

0 comments on commit a50919b

Please sign in to comment.