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

Commit

Permalink
Revert "fast forward"
Browse files Browse the repository at this point in the history
This reverts commit 250c228.
  • Loading branch information
Tropix126 committed Mar 3, 2024
1 parent 250c228 commit 2697da9
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 504 deletions.
20 changes: 2 additions & 18 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ Before releasing:

### Added

- `object_size` method on `DistanceSensor` for getting a guess at an object's relative size.

### Fixed

### Changed

### Removed

## [0.7.0]

### Added

- `SmartPort` struct for device access. (#34)
- `SmartDevice` trait for common functionality across smart port devices. (#34)
- Methods to get a device's port number as well as determine if the device is plugged in or not. (#34)
Expand All @@ -48,30 +36,27 @@ Before releasing:
- All ADI device bindings (#55)
- `LocalKey` now has `Cell`/`RefCell`-specific methods for setting and taking values. (#42)
- `Peripherals` and `DynamicPeripherals` structs to ensure that you have only registered one device on a given smart or ADI port. (#53)
- `object_size` method on `DistanceSensor` for getting a guess at an object's relative size.

### Fixed

- Fixed competition state-related getters in the `pros::competition` module. (#38)
- Fixed error handling in IMU sensor bindings. (#37)
- Fixed errors in doctests and examples throughout the crate. (#37)
- Fixed Missing ERRNO and ADI config variants in pros-sys (#55)
- Fixed incorrect error handling with `InertialSensor::status`. (#65)
- `Controller::status` now handles errors by returning `Result<ControllerStatus, ControllerError>`. (**Breaking Change**) (#74)

### Changed

- Overhauled the `competition` module with more straightforward getters for competition state. (#38) (**Breaking Change**)
- LLEMU-related macros have been prefixed with `llemu_` (e.g. `llemu_println`). (**Breaking Change**) (#30)
- Added `Debug`, `Copy`, and `Clone` derives for common structs (#37)
- Renamed `InertialSensor::is_calibrating` to `InertialSensor::calibrating`. (**Breaking Change**) (#65)
- Battery API functions now return `Result<_, BatteryError>`. (**Breaking Change**) (#62)
- Renamed `battery::get_capacity` to `battery::capacity`, `battery::get_current` -> `battery::current`, `battery::get_temperature` -> `battery::temperature`, `battery::get_voltage` -> `battery::voltage`. (**Breaking Change**) (#62)

### Removed

- Removed several broken bindings in `pros_sys` relating to competition state. (#38) (**Breaking Change**)
- `LocalKey` no longer implements `set` for non-`Cell`/`RefCell` stored values. (**Breaking change**) (#42)
- Removed the now-redundant `InertialStatus::error` function. (**Breaking Change**) (#65)

## [0.6.0] - 2024-01-14

Expand Down Expand Up @@ -132,8 +117,7 @@ Before releasing:

### Removed

[unreleased]: https://github.com/pros-rs/pros-rs/compare/v0.7.0...HEAD
[unreleased]: https://github.com/pros-rs/pros-rs/compare/v0.6.0...HEAD
[0.4.0]: https://github.com/pros-rs/pros-rs/releases/tag/v0.4.0
[0.5.0]: https://github.com/pros-rs/pros-rs/compare/v0.4.0...v0.5.0
[0.6.0]: https://github.com/pros-rs/pros-rs/compare/v0.5.0...v0.6.0
[0.7.0]: https://github.com/pros-rs/pros-rs/compare/v0.6.0...v0.7.0
2 changes: 1 addition & 1 deletion packages/pros-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pros-sys"
version = "0.6.0"
version = "0.5.0"
edition = "2021"
description = "EFI for the PROS rust bindings"
keywords = ["PROS", "Robotics", "bindings"]
Expand Down
7 changes: 3 additions & 4 deletions packages/pros-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod rotation;
pub mod rtos;
pub mod vision;

use core::ffi::{c_char, c_int, c_void};
use core::ffi::c_char;

pub use adi::*;
pub use colors::*;
Expand All @@ -48,12 +48,11 @@ pub const CLOCKS_PER_SEC: u32 = 1000;

extern "C" {
#[cfg(not(target_arch = "wasm32"))]
pub fn memalign(alignment: usize, size: usize) -> *mut c_void;
pub fn memalign(alignment: usize, size: usize) -> *mut core::ffi::c_void;
#[cfg(not(target_arch = "wasm32"))]
pub fn free(ptr: *mut c_void);
pub fn free(ptr: *mut core::ffi::c_void);
pub fn __errno() -> *mut i32;
pub fn clock() -> i32;
pub fn puts(s: *const c_char) -> i32;
pub fn exit(code: i32) -> !;
pub fn write(fd: c_int, buf: *const c_void, count: usize) -> isize;
}
5 changes: 3 additions & 2 deletions packages/pros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pros"
version = "0.7.0"
version = "0.7.0-pre.1"
edition = "2021"
description = "Rust bindings for PROS"
keywords = ["PROS", "Robotics", "bindings"]
Expand All @@ -20,7 +20,7 @@ rust-version = "1.75.0"
[dependencies]
lazy_static = { version = "1.4.0", features = ["spin_no_std"] }
spin = "0.9.8"
pros-sys = { version = "0.6", path = "../pros-sys", features = ["xapi"] }
pros-sys = { version = "0.5", path = "../pros-sys", features = ["xapi"] }
snafu = { version = "0.8.0", default-features = false, features = [
"rust_1_61",
"unstable-core-error",
Expand All @@ -31,6 +31,7 @@ slab = { version = "0.4.9", default-features = false }
hashbrown = { version = "0.14.1", default-features = true }
async-task = { version = "4.5.0", default-features = false }
waker-fn = "1.1.1"
libc-print = "0.1.22"

[target.'cfg(target_arch = "wasm32")'.dependencies]
dlmalloc = { version = "0.2.4", features = ["global"] }
169 changes: 55 additions & 114 deletions packages/pros/src/devices/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,169 +135,110 @@ impl Controller {
}

/// Gets the current state of the controller in its entirety.
pub fn state(&self) -> Result<ControllerState, ControllerError> {
Ok(ControllerState {
pub fn state(&self) -> ControllerState {
ControllerState {
joysticks: unsafe {
Joysticks {
left: Joystick {
x: bail_on!(
PROS_ERR,
pros_sys::controller_get_analog(
self.id(),
pros_sys::E_CONTROLLER_ANALOG_LEFT_X,
)
x: pros_sys::controller_get_analog(
self.id(),
pros_sys::E_CONTROLLER_ANALOG_LEFT_X,
) as f32
/ 127.0,
y: bail_on!(
PROS_ERR,
pros_sys::controller_get_analog(
self.id(),
pros_sys::E_CONTROLLER_ANALOG_LEFT_Y,
)
y: pros_sys::controller_get_analog(
self.id(),
pros_sys::E_CONTROLLER_ANALOG_LEFT_Y,
) as f32
/ 127.0,
},
right: Joystick {
x: bail_on!(
PROS_ERR,
pros_sys::controller_get_analog(
self.id(),
pros_sys::E_CONTROLLER_ANALOG_RIGHT_X,
)
x: pros_sys::controller_get_analog(
self.id(),
pros_sys::E_CONTROLLER_ANALOG_RIGHT_X,
) as f32
/ 127.0,
y: bail_on!(
PROS_ERR,
pros_sys::controller_get_analog(
self.id(),
pros_sys::E_CONTROLLER_ANALOG_RIGHT_Y,
)
y: pros_sys::controller_get_analog(
self.id(),
pros_sys::E_CONTROLLER_ANALOG_RIGHT_Y,
) as f32
/ 127.0,
},
}
},
buttons: unsafe {
Buttons {
a: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_A,
)
a: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_A,
) == 1,
b: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_B,
)
b: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_B,
) == 1,
x: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_X,
)
x: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_X,
) == 1,
y: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_Y,
)
y: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_Y,
) == 1,
up: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_UP,
)
up: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_UP,
) == 1,
down: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_DOWN,
)
down: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_DOWN,
) == 1,
left: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_LEFT,
)
left: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_LEFT,
) == 1,
right: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_RIGHT,
)
right: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_RIGHT,
) == 1,
left_trigger_1: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_L1,
)
left_trigger_1: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_L1,
) == 1,
left_trigger_2: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_L2,
)
left_trigger_2: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_L2,
) == 1,
right_trigger_1: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_R1,
)
right_trigger_1: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_R1,
) == 1,
right_trigger_2: bail_on!(
PROS_ERR,
pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_R2,
)
right_trigger_2: pros_sys::controller_get_digital(
self.id(),
pros_sys::E_CONTROLLER_DIGITAL_R2,
) == 1,
}
},
})
}
}

/// Gets the state of a specific button on the controller.
pub fn button(&self, button: ControllerButton) -> Result<bool, ControllerError> {
Ok(bail_on!(PROS_ERR, unsafe {
pros_sys::controller_get_digital(self.id(), button as pros_sys::controller_digital_e_t)
}) == 1)
pub fn button(&self, button: ControllerButton) -> bool {
unsafe { pros_sys::controller_get_digital(self.id(), button as u32) == 1 }
}

/// Gets the state of a specific joystick axis on the controller.
pub fn joystick_axis(&self, axis: JoystickAxis) -> Result<f32, ControllerError> {
Ok(bail_on!(PROS_ERR, unsafe {
pros_sys::controller_get_analog(self.id(), axis as pros_sys::controller_analog_e_t)
}) as f32
/ 127.0)
pub fn joystick_axis(&self, axis: JoystickAxis) -> f32 {
unsafe { pros_sys::controller_get_analog(self.id(), axis as u32) as f32 / 127.0 }
}
}

#[derive(Debug, Snafu)]
pub enum ControllerError {
#[snafu(display(
"A controller ID other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER was given."
))]
InvalidControllerId,

#[snafu(display("Another resource is already using the controller"))]
ConcurrentAccess,
}

map_errno! {
ControllerError {
EACCES => Self::ConcurrentAccess,
EINVAL => Self::InvalidControllerId,
}
}
Loading

0 comments on commit 2697da9

Please sign in to comment.