diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ca4a7c6..ba30391a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,12 +31,14 @@ Before releasing: - Added support for getting motor fault flags (e.g. over-temperature, over-current, H-bridge faults). - Added support for internal motor PID tuning. Feature gated behind `dangerous_motor_tuning`, as this can cause hardware damage and is not recommended. - Added various constants for convenience around `Motor` and `Gearset`. +- Added `Controller` API to the `pros::prelude` module. (#108) - `relative_size` method on `DistanceSensor` for getting a guess at an object's relative size. (#73) ### 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 @@ -53,6 +55,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); } } }; diff --git a/packages/pros/src/lib.rs b/packages/pros/src/lib.rs index e14accd7..9f10b46f 100644 --- a/packages/pros/src/lib.rs +++ b/packages/pros/src/lib.rs @@ -97,6 +97,7 @@ pub mod prelude { AdiDevice, AdiPort, }, color::Rgb, + controller::Controller, peripherals::{DynamicPeripherals, Peripherals}, position::Position, screen::{Circle, Line, Rect, Screen, Text, TextFormat, TextPosition, TouchState},