Missing public accessor to pin. #53

Closed
opened 2019-09-20 23:05:18 +03:00 by matkor · 8 comments
matkor commented 2019-09-20 23:05:18 +03:00 (Migrated from github.com)

Please add public accessor to this->pin like:

    uint8_t get_pin(){
      return this->pin;
    }

TIA

Please add public accessor to this->pin like: ``` uint8_t get_pin(){ return this->pin; } ``` TIA
thomasfredericks commented 2019-09-24 05:18:35 +03:00 (Migrated from github.com)

I will have to think about this. A more abstract class has often been requested allowing debouncing of more than just a single hardware pin. So I will not implement this right now, but later. I need to make a base class that is extended to hardware pins.

I will have to think about this. A more abstract class has often been requested allowing debouncing of more than just a single hardware pin. So I will not implement this right now, but later. I need to make a base class that is extended to hardware pins.
matkor commented 2019-09-24 11:36:49 +03:00 (Migrated from github.com)

Cool.

For now I can live with:

class BounceExt: public Bounce
{
  public:
    BounceExt(uint8_t pin, uint16_t interval_millis ) :
      Bounce(pin, interval_millis) {};
    uint8_t get_pin() {
      return pin;
    }
};

It allows save byte of RAM each time Bounce is member of class, when pin must be later used in class.

Cool. For now I can live with: ``` c++ class BounceExt: public Bounce { public: BounceExt(uint8_t pin, uint16_t interval_millis ) : Bounce(pin, interval_millis) {}; uint8_t get_pin() { return pin; } }; ``` It allows save byte of RAM each time Bounce is member of class, when pin must be later used in class.
septillion-git commented 2019-09-29 15:13:46 +03:00 (Migrated from github.com)

Why does that save RAM? Because in most situations you can have a const in your code which you pass to Bounce2 aka it takes no space in RAM.

Why does that save RAM? Because in most situations you can have a const in your code which you pass to Bounce2 aka it takes no space in RAM.
matkor commented 2019-09-30 15:03:10 +03:00 (Migrated from github.com)

(...) in most situations you can have a const in your code which you pass to Bounce2 aka it takes no space in RAM.

Bounce objects store pin number as their attribute, so most likely byte of RAM is used regardless how init value was passed.

Why does that save RAM?

I do not have to duplicate pin number data like:

class PushButton{
    Bounce debouncer;
    uint8_t pin;   // duplicate value as in debouncer.pin

> (...) in most situations you can have a const in your code which you pass to Bounce2 aka it takes no space in RAM. Bounce objects store pin number as their attribute, so most likely byte of RAM is used regardless how init value was passed. > Why does that save RAM? I do not have to duplicate pin number data like: ``` c++ class PushButton{ Bounce debouncer; uint8_t pin; // duplicate value as in debouncer.pin ```
jamesmyatt commented 2020-07-22 01:07:52 +03:00 (Migrated from github.com)

@matkor, why do you store the debouncer and pin separately?

@matkor, why do you store the debouncer and pin separately?
matkor commented 2020-07-22 17:18:47 +03:00 (Migrated from github.com)

@matkor, why do you store the debouncer and pin separately?

I do not.
I just need access pin having only Bounce instance.

> @matkor, why do you store the debouncer and pin separately? I do not. I just need access pin having only Bounce instance.
thomasfredericks commented 2020-08-08 00:58:56 +03:00 (Migrated from github.com)

I merged a new version of the library where I split the hardware layer from the debouncing algorithm. It should now be easier to make custom classes.

@matkor We could now add a getPin function to the Bounce class.

I merged a new version of the library where I split the hardware layer from the debouncing algorithm. It should now be easier to make custom classes. @matkor We could now add a getPin function to the Bounce class.
thomasfredericks commented 2021-06-28 23:46:18 +03:00 (Migrated from github.com)

Was added to v2.58

Was added to v2.58
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Max/thomasfredericks_Bounce2#53