Skip to content

Add onChange() method to V3 Trigger - #9359

Open
katzuv wants to merge 1 commit into
wpilibsuite:mainfrom
katzuv:add-v3-trigger-onChange
Open

Add onChange() method to V3 Trigger#9359
katzuv wants to merge 1 commit into
wpilibsuite:mainfrom
katzuv:add-v3-trigger-onChange

Conversation

@katzuv

@katzuv katzuv commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI lite review requested due to automatic review settings August 28, 2026 23:19
@katzuv
katzuv requested a review from a team as a code owner August 28, 2026 23:19
@github-actions github-actions Bot added the component: commands v3 WPILib Commands library version 3 label Aug 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds an onChange() convenience binding to the commandsv3 Trigger API, aligning it with existing trigger binding patterns (e.g., onTrue()/onFalse()) and providing a shorthand for scheduling a command on either edge.

Changes:

  • Added Trigger#onChange(Command) to schedule a command on both rising and falling edges.
  • Added Javadoc for the new onChange() method.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +118 to +123
/**
* Starts the command when the condition changes.
*
* @param command the command to start
* @return this trigger, so calls can be chained
*/
Comment on lines +124 to +129
public Trigger onChange(Command command) {
requireNonNullParam(command, "command", "onChange");
addBinding(BindingType.SCHEDULE_ON_RISING_EDGE, command);
addBinding(BindingType.SCHEDULE_ON_FALLING_EDGE, command);
return this;
}

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f5fa46b3a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +126 to +127
addBinding(BindingType.SCHEDULE_ON_RISING_EDGE, command);
addBinding(BindingType.SCHEDULE_ON_FALLING_EDGE, command);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Skip the initial sample in onChange

Because m_previousSignal is null until the trigger is first polled, poll() classifies the initial sample as either a rising or falling edge. Registering the command for both edge types therefore guarantees that onChange() schedules it on the first Scheduler.run() even when the supplier has never changed, contrary to the method contract and the existing V2 onChange() behavior. This needs a dedicated binding or baseline handling that ignores the initial sample.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: commands v3 WPILib Commands library version 3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants