Skip to content

CreateSpark - #124

Merged
timtogan merged 6 commits into
masterfrom
createSpark
Feb 7, 2026
Merged

CreateSpark#124
timtogan merged 6 commits into
masterfrom
createSpark

Conversation

@timtogan

@timtogan timtogan commented Feb 5, 2026

Copy link
Copy Markdown
Member

This add a createSpark() method. It returns a SparkBase initialized to a SparkMax/Flex depending on the motorConfig passed in.

@timtogan
timtogan requested a review from a team as a code owner February 5, 2026 19:09
Copilot AI review requested due to automatic review settings February 5, 2026 19:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 a createSpark() factory method that provides a unified interface for creating either SparkMax or SparkFlex motor controllers based on the MotorConfig parameter. This simplifies client code by allowing dynamic selection of the appropriate Spark controller type without needing to explicitly call createSparkMax() or createSparkFlex().

Changes:

  • Added two overloaded createSpark() methods that dispatch to the appropriate createSparkMax() or createSparkFlex() method based on the motorConfig.controllerType
  • The first overload uses default Spark configuration, while the second accepts a custom SparkBaseConfig

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

case SPARK_FLEX:
return createSparkFlex(id, motorConfig, config);
default:
return null;

Copilot AI Feb 5, 2026

Copy link

Choose a reason for hiding this comment

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

The default case returns null, which could lead to NullPointerExceptions if an unexpected controllerType is passed. While this pattern is consistent with other methods in this class (e.g., getConfigAccessor at line 157-158, createConfig at line 161-171, getControllerType at line 180), consider whether it would be safer to throw an IllegalArgumentException with a descriptive message explaining that the controllerType is unsupported. This would make debugging easier and fail faster if an invalid configuration is used.

Suggested change
return null;
throw new IllegalArgumentException(
"Unsupported controllerType in MotorControllerFactory.createSpark: "
+ motorConfig.controllerType);

Copilot uses AI. Check for mistakes.
timtogan and others added 2 commits February 5, 2026 11:19
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@timtogan

timtogan commented Feb 6, 2026

Copy link
Copy Markdown
Member Author

@CoolSpy3 could you review pls

@timtogan
timtogan requested a review from CoolSpy3 February 6, 2026 02:21

@CoolSpy3 CoolSpy3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two small notes.

Comment thread src/test/java/org/carlmontrobotics/lib199/MotorControllerFactoryTest.java Outdated
@timtogan

timtogan commented Feb 6, 2026

Copy link
Copy Markdown
Member Author

@CoolSpy3 Done 👍

@timtogan
timtogan requested a review from CoolSpy3 February 6, 2026 18:05

@CoolSpy3 CoolSpy3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Great; thanks! This looks good ✅ Just fix the javadoc errors. (I think the problem might be that the ...s are causing Javadoc to look for varargs declarations that don't exist, but idk for sure.)

@CoolSpy3 CoolSpy3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nvm. Sorry, GitHub was showing me the not-most-recent commit :P

@timtogan
timtogan merged commit 40b1d4c into master Feb 7, 2026
3 checks passed
@timtogan
timtogan deleted the createSpark branch February 7, 2026 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants