-
Notifications
You must be signed in to change notification settings - Fork 8
Move constants and types into class scope #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cleishm
wants to merge
2
commits into
MaffooClock:main
Choose a base branch
from
cleishm:api-cleanup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This enum feels awkward. Given it's a breaking change, would you consider changing the API to specify floating/pullup separately for the encoder and the switch? Then you wouldn't need the enum either - a bool would suffice (unless you wanted to add support for a reversed logic level?).
E.g.
or perhaps:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, you could avoid methods entirely and provide direction on pull-ups as constructor args. This would avoid surprising errors where someone attempts to call these after calling
begin().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok - I'm not sure I actually like passing them in constructor arguments. It gets unwieldy. Here's the commit for that: 07538dd
One could go further and replace the constructor arguments with a parameters struct. For c++17 and above, this would also work with named initialization in some cases, which is somewhat elegant - except that the user must still declare the arguments in-order for the initializer to work. Commit for that is here: 3ec2214
Not sure I like either of those especially, so perhaps methods-that-must-be-called-before-begin is the way to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it's been a while since I wrote this library, chunks of it are a bit fuzzy in my memory, and I haven't taken the time to deeply refresh myself since you started pouring all your effort into it.
But I can say this much: I chose to use an Enum rather than multiple
.set...()or.enable()/.disable()methods purely because it looked "prettier" to me (and I thought it would make it easy to use). You're obviously more skilled in C++ than me and see a opportunities to optimize, so I certainly appreciate that.After thinking through this a bit, I would agree with this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the issue is that there are mixing concerns - the encoder and the button are two separate devices (albeit in one physical package). Ditto with the VCC pin: I personally would've made that a concern for the user to take care of externally to the library.
But it's all personal preference and there is no standard for any of this (that I'm aware of). And it's your library, so you get to choose :)
I've pushed a commit to this PR that provides individual methods.