Hardware abstraction should be by composition rather than inheritance #70

Open
opened 2020-08-26 16:27:09 +03:00 by jamesmyatt · 6 comments
jamesmyatt commented 2020-08-26 16:27:09 +03:00 (Migrated from github.com)

Especially since there is a Button class now, the hardware abstraction should be done by composition rather than inheritance. For example, it's not possible to define a Button instance that uses something other than digitalRead to read the state. What do you think?

https://en.wikipedia.org/wiki/Composition_over_inheritance

Especially since there is a Button class now, the hardware abstraction should be done by composition rather than inheritance. For example, it's not possible to define a Button instance that uses something other than digitalRead to read the state. What do you think? https://en.wikipedia.org/wiki/Composition_over_inheritance
thomasfredericks commented 2020-08-27 04:11:58 +03:00 (Migrated from github.com)

Hum, interesting. But how would this be implemented?

Hum, interesting. But how would this be implemented?
KenwoodFox commented 2021-12-21 22:06:27 +03:00 (Migrated from github.com)

I also want to find a way to do this, id like to be able to define a button instance with an input that is not digitalRead, maybe add in an override?

I also want to find a way to do this, id like to be able to define a button instance with an input that is not digitalRead, maybe add in an override?
thomasfredericks commented 2021-12-22 17:51:16 +03:00 (Migrated from github.com)

@KenwoodFox this can already be implemented. See the source for class Bounce in Bounce2.h.

You can set your custom override for digitalRead :
virtual bool readCurrentState() { return digitalRead(pin); }

@KenwoodFox this can already be implemented. See the source for `class Bounce` in `Bounce2.h`. You can set your custom override for digitalRead : `virtual bool readCurrentState() { return digitalRead(pin); }`
KenwoodFox commented 2021-12-24 06:08:39 +03:00 (Migrated from github.com)

@KenwoodFox this can already be implemented. See the source for class Bounce in Bounce2.h.

You can set your custom override for digitalRead : virtual bool readCurrentState() { return digitalRead(pin); }

This is pretty awesome! thanks so much.

> @KenwoodFox this can already be implemented. See the source for `class Bounce` in `Bounce2.h`. > > You can set your custom override for digitalRead : `virtual bool readCurrentState() { return digitalRead(pin); }` This is pretty awesome! thanks so much.
KenwoodFox commented 2021-12-28 00:42:29 +03:00 (Migrated from github.com)

@KenwoodFox this can already be implemented. See the source for class Bounce in Bounce2.h.

You can set your custom override for digitalRead : virtual bool readCurrentState() { return digitalRead(pin); }

Sorry to ask, but where would you implement this? Should this be done for every button instance you create or do i need to make my own button class using inheriting from bounce?

> @KenwoodFox this can already be implemented. See the source for `class Bounce` in `Bounce2.h`. > > You can set your custom override for digitalRead : `virtual bool readCurrentState() { return digitalRead(pin); }` Sorry to ask, but where would you implement this? Should this be done for every button instance you create or do i need to make my own button class using inheriting from bounce?
Thynix commented 2022-02-28 15:43:02 +03:00 (Migrated from github.com)

It isn't a complete replacement because it doesn't have complex debouncing techniques, but the Debouncer library allows passing in the value to use.

It isn't a complete replacement because it doesn't have complex debouncing techniques, but the [`Debouncer`](https://github.com/apechinsky/arduino-libs/blob/master/Debouncer/examples/basic/sketch.ino) library allows passing in the value to use.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Max/thomasfredericks_Bounce2#70