From a50919b22aae410572a5097d0c4ef9938e8bc7f1 Mon Sep 17 00:00:00 2001 From: Tropical <42101043+Tropix126@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:15:28 -0500 Subject: [PATCH 1/3] refactor: make `AdiEncoder` return `Position` --- CHANGELOG.md | 1 + packages/pros-devices/src/adi/encoder.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8942371..9a64a91d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/pros-devices/src/adi/encoder.rs b/packages/pros-devices/src/adi/encoder.rs index ee0ae8f9..27aa0824 100644 --- a/packages/pros-devices/src/adi/encoder.rs +++ b/packages/pros-devices/src/adi/encoder.rs @@ -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. @@ -49,10 +51,12 @@ impl AdiEncoder { } /// Gets the number of ticks recorded by the encoder. - pub fn position(&self) -> Result { - Ok(bail_on!(PROS_ERR, unsafe { + pub fn position(&self) -> Result { + let degrees = bail_on!(PROS_ERR, unsafe { pros_sys::adi_encoder_get(self.raw) - })) + }); + + Ok(Position::from_degrees(degrees as f64)) } } From 7e7f4f1b97717b793de2ba973f9150b0b669114c Mon Sep 17 00:00:00 2001 From: Tropical <42101043+Tropix126@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:17:05 -0500 Subject: [PATCH 2/3] docs: more complete changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a64a91d..8c8eb379 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,7 +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. +- AdiEncoder now returns `Position` rather than just degrees (**Breaking Change**) (#106). ### Removed From 5f36c186ad9c4c2dd62cfa1c333cf50fbb170fdf Mon Sep 17 00:00:00 2001 From: Tropical <42101043+Tropix126@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:17:41 -0500 Subject: [PATCH 3/3] chore: fmt :trollface: --- packages/pros-devices/src/adi/encoder.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/pros-devices/src/adi/encoder.rs b/packages/pros-devices/src/adi/encoder.rs index 27aa0824..da46c0d9 100644 --- a/packages/pros-devices/src/adi/encoder.rs +++ b/packages/pros-devices/src/adi/encoder.rs @@ -3,9 +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}; +use crate::Position; /// ADI encoder device. /// Requires two adi ports. @@ -52,9 +51,7 @@ impl AdiEncoder { /// Gets the number of ticks recorded by the encoder. pub fn position(&self) -> Result { - let degrees = bail_on!(PROS_ERR, unsafe { - pros_sys::adi_encoder_get(self.raw) - }); + let degrees = bail_on!(PROS_ERR, unsafe { pros_sys::adi_encoder_get(self.raw) }); Ok(Position::from_degrees(degrees as f64)) }