arduino / node_modulino_firmware

Mozilla Public License 2.0
1 stars 0 forks source link

Make API for Encoder more clear #11

Closed alranel closed 7 months ago

alranel commented 7 months ago

As of now, the API for the Modulino Encoder work like this:

void loop() {
   int pos = encoder.get();
   bool isPressed = encoder.pressed();
}

There are two problems here:

  1. get() and pressed() are inconsistent terms, as get() is too generic while it only returns one of the two properties of the encoder which have the same importance.
  2. pressed() does not work unless get() is called before it, but this is counter-intuitive. In many real-world situations, users interested just in the button press will forget to add get() first.

Proposal: have an explicit update() method (as suggested for other modules as well) and then have two pure accessors to retrieve data.

void loop() {
   encoder.update();
   int pos = encoder.pos();
   bool isPressed = encoder.pressed();
}