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

Commit

Permalink
Merge pull request #106 from Tropix126/refactor/adi-encoder-position
Browse files Browse the repository at this point in the history
refactor: make `AdiEncoder` return `Position`
  • Loading branch information
Gavin-Niederman authored Mar 13, 2024
2 parents 21f45c4 + 5f36c18 commit b51dc26
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 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 (**Breaking Change**) (#106).

### Removed

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

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

/// ADI encoder device.
/// Requires two adi ports.
Expand Down Expand Up @@ -49,10 +50,10 @@ impl AdiEncoder {
}

/// Gets the number of ticks recorded by the encoder.
pub fn position(&self) -> Result<i32, AdiError> {
Ok(bail_on!(PROS_ERR, unsafe {
pros_sys::adi_encoder_get(self.raw)
}))
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 b51dc26

Please sign in to comment.