diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ddcf8c4..298b7224 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ Before releasing: ### Fixed - `pros_sys` bindings to the Motors C API now takes the correct port type (`i8`) as of PROS 4 (**Breaking Change**) (#66). +- Fixed the unintended `unsafe` context present in the `sync_robot` and `async_robot` family of macros (**Breaking Change**) (#107). ### Changed @@ -50,6 +51,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 diff --git a/packages/pros-async/src/lib.rs b/packages/pros-async/src/lib.rs index 6d1beb30..004a082f 100644 --- a/packages/pros-async/src/lib.rs +++ b/packages/pros-async/src/lib.rs @@ -185,8 +185,9 @@ macro_rules! async_robot { #[no_mangle] extern "C" fn initialize() { + let robot = Default::default(); unsafe { - ROBOT = Some(Default::default()); + ROBOT = Some(robot); } } }; @@ -195,8 +196,9 @@ macro_rules! async_robot { #[no_mangle] extern "C" fn initialize() { + let robot = $init; unsafe { - ROBOT = Some($init); + ROBOT = Some(robot); } } }; diff --git a/packages/pros-devices/src/adi/encoder.rs b/packages/pros-devices/src/adi/encoder.rs index ee0ae8f9..da46c0d9 100644 --- a/packages/pros-devices/src/adi/encoder.rs +++ b/packages/pros-devices/src/adi/encoder.rs @@ -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. @@ -49,10 +50,10 @@ impl AdiEncoder { } /// Gets the number of ticks recorded by the encoder. - pub fn position(&self) -> Result { - Ok(bail_on!(PROS_ERR, unsafe { - pros_sys::adi_encoder_get(self.raw) - })) + 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)) } } diff --git a/packages/pros-sync/src/lib.rs b/packages/pros-sync/src/lib.rs index 6f7df18a..6c252308 100644 --- a/packages/pros-sync/src/lib.rs +++ b/packages/pros-sync/src/lib.rs @@ -123,8 +123,9 @@ macro_rules! sync_robot { #[no_mangle] extern "C" fn initialize() { + let robot = Default::default(); unsafe { - ROBOT = Some(Default::default()); + ROBOT = Some(robot); } } }; @@ -133,8 +134,9 @@ macro_rules! sync_robot { #[no_mangle] extern "C" fn initialize() { + let robot = $init; unsafe { - ROBOT = Some($init); + ROBOT = Some(robot); } } };