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

refactor: Controller API #87

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Tropix126
Copy link
Member

@Tropix126 Tropix126 commented Feb 5, 2024

Describe the changes this PR makes. Why should it be merged?

  • Moves Controller into peripherals to enforce singleton access.
  • Refactors buttons and joysticks into their own structs with unique getters.
  • Adds support for getting connection status and battery level from the controller.
  • Adds support for controlling the internal vibration motor through rumble pattern strings.

Additional Context

  • Breaking change
  • TODO: docs
  • Need to look into implementing a writer for the controller's display.
  • Unsure if Buttons and Joysticks need to exist now other than as a fancy namespace struct.

use snafu::Snafu;

use crate::error::{bail_on, map_errno};

pub const CONTROLLER_MAX_LINE_LENGTH: usize = 14;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should go in pros-sys because it determines constraints on a function from that module. Also if controller display gets implemented in sim it'd be good to have that constant available because the simulator already uses other constants from pros-sys like errno values.

@doinkythederp
Copy link
Member

I think it's a little worrying how this makes it harder to read controller inputs without much obvious increase in safety. For example if you want to periodically rumble the controller from another thread but still read its inputs from opcontrol you'll need a mutex to share the controller, even though those two actions (reading joysticks and playing the haptic feedback) could happen in parallel.

@Gavin-Niederman
Copy link
Member

I think it is worth considering renaming the master controller to main or some similar word.

@doinkythederp
Copy link
Member

I think it is worth considering renaming the master controller to main or some similar word.

Primary and partner might work because that's what VEXcode uses.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants