Skip to content

Rearrange and normalize private members#18

Merged
MaffooClock merged 1 commit into
MaffooClock:mainfrom
cleishm:private-member-cleanup
Oct 13, 2025
Merged

Rearrange and normalize private members#18
MaffooClock merged 1 commit into
MaffooClock:mainfrom
cleishm:private-member-cleanup

Conversation

@cleishm

@cleishm cleishm commented Oct 13, 2025

Copy link
Copy Markdown
Contributor

Normalize the declaration, initialization, and documentation of private members.

  • Remove doc on private members (it was mostly missing, empty or obvious)
  • Add const declarations where appropriate
  • Use encoderSteps (with >=/<=) instead of encoderTripPoint (with </>) to avoid type narrowing (uint8_t -> int8_t) caused by subtraction.
  • Use types over #def's for constants to also avoid narrowing warnings.
  • Move timerCallback to source rather than header, as it does not need to be exposed (and could potentially lead to multiple implementations).

Resolves #16

@cleishm

cleishm commented Oct 13, 2025

Copy link
Copy Markdown
Contributor Author

It would be an API breaking change, but I'd also strongly encourage:

  • Moving RE_DEFAULT_PIN, RE_DEFAULT_STEPS, and RE_LOOP_INTERVAL to class static constants (rather than global).
  • Moving EncoderType to a class scope enum (rather than global).
  • Moving RotaryEncoder::loop() into private scope.

this->encoderPinB = encoderPinB;
this->encoderPinButton = encoderPinButton;
this->encoderPinVcc = encoderPinVcc;
this->encoderTripPoint = encoderSteps - 1;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There was a subtle error here - an underflow when encoderSteps is 0, which would set encoderTripPoint to 255. This is fixed by avoiding the subtraction and by setting encoderSteps to default when 0.

Normalize the declaration, initialization, and documentation of private
members.

- Remove doc on private members (it was mostly missing, empty or obvious)
- Add const declarations where appropriate
- Use `encoderSteps` (with `>=`/`<=`) instead of `encoderTripPoint`
  (with `<`/`>`) to avoid type narrowing (`uint8_t` -> `int8_t`) caused by
  subtraction.
- Use types over #def's for constants to also avoid narrowing warnings.
- Move `timerCallback` to source rather than header, as it does not need
  to be exposed (and could potentially lead to multiple implementations).
@cleishm cleishm force-pushed the private-member-cleanup branch from cd34c3e to 8e65a57 Compare October 13, 2025 18:57
@MaffooClock MaffooClock merged commit 96cc758 into MaffooClock:main Oct 13, 2025
2 checks passed
@cleishm cleishm deleted the private-member-cleanup branch October 13, 2025 19:00
@cleishm cleishm mentioned this pull request Oct 13, 2025
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.

Class cleanup/optimization

2 participants