Skip to content

Commit

Permalink
Changed way of disabling features, to allow specific per-project
Browse files Browse the repository at this point in the history
settings, without having to change the EButton.h file
  • Loading branch information
jonnieZG committed Jul 26, 2019
1 parent 6c84117 commit 4351f4d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 14 deletions.
33 changes: 29 additions & 4 deletions EButton.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* EButton v1.1.0 - Customizable button-driver class with a small footprint, supporting debouncing, and various events.
* EButton v1.2.0 - Customizable button-driver class with a small footprint, supporting debouncing, and various events.
*
* Its already small footprint can be additionally minimized by disabling unneeded features using #define switches.
*
Expand Down Expand Up @@ -29,9 +29,9 @@
* allowing you to read details about the event, like a number of clicks, time of the first click, etc.
*
*
* Version: 1.1.0
* Version: 1.2.0
* License: MIT
* Created on: 2017-02-23
* Created on: 2017-02-27
* Author: JonnieZG
*/

Expand All @@ -41,14 +41,39 @@
#include "Arduino.h"

// --------------------------- Optional Feature Switches ---------------------------
// You can disable any of the features you don't need, to minimize memory footprint
// You can disable the features you don't need, to minimize memory footprint
// Just include some of the following defines before including EButton.h and
// don't forget to clean the project after making changes to these options!

//#define EBUTTON_SUPPORT_TRANSITION_DISABLED
//#define EBUTTON_SUPPORT_EACH_CLICK_DISABLED
//#define EBUTTON_SUPPORT_DONE_CLICKING_DISABLED
//#define EBUTTON_SUPPORT_SINGLE_AND_DOUBLE_CLICKS_DISABLED
//#define EBUTTON_SUPPORT_LONG_PRESS_START_DISABLED
//#define EBUTTON_SUPPORT_LONG_PRESS_DURING_DISABLED


#ifndef EBUTTON_SUPPORT_TRANSITION_DISABLED
#define EBUTTON_SUPPORT_TRANSITION
#endif
#ifndef EBUTTON_SUPPORT_EACH_CLICK_DISABLED
#define EBUTTON_SUPPORT_EACH_CLICK
#endif
#ifndef EBUTTON_SUPPORT_DONE_CLICKING_DISABLED
#define EBUTTON_SUPPORT_DONE_CLICKING
#endif
#ifndef EBUTTON_SUPPORT_SINGLE_AND_DOUBLE_CLICKS_DISABLED
#define EBUTTON_SUPPORT_SINGLE_AND_DOUBLE_CLICKS
#endif
#ifndef EBUTTON_SUPPORT_LONG_PRESS_START_DISABLED
#define EBUTTON_SUPPORT_LONG_PRESS_START
#endif
#ifndef EBUTTON_SUPPORT_LONG_PRESS_DURING_DISABLED
#define EBUTTON_SUPPORT_LONG_PRESS_DURING
#endif
#ifndef EBUTTON_SUPPORT_LONG_PRESS_END_DISABLED
#define EBUTTON_SUPPORT_LONG_PRESS_END
#endif

// -------- Default Timings in milliseconds (can be modified using setters) --------
#define EBUTTON_DEFAULT_DEBOUNCE 50
Expand Down
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,19 @@ All handler methods are optional, and initially set to `NULL`.
> recursive calls to the `tick()` method from within a handler method - which should be avoided, because it will most likely end in
> tears!
## Minimizing Memory Footprint
## Minimizing Memory Footprint - Disabling Unneeded Features
If the memory becomes an issue in your project, you can easily decrease the driver's footprint by disabling support for unneeded events.
That way you can make significant savings in your memory-critical projects.

To disable a feature, just comment out its corresponding `#define` entry in the driver's header file:
To disable a feature, just add its corresponding `#define` entry before importing the driver's header file for the very first time,
and don't forget to clean the project after making such a change:
```C++
#define EBUTTON_SUPPORT_TRANSITION
#define EBUTTON_SUPPORT_EACH_CLICK
#define EBUTTON_SUPPORT_DONE_CLICKING
#define EBUTTON_SUPPORT_SINGLE_AND_DOUBLE_CLICKS
#define EBUTTON_SUPPORT_LONG_PRESS_START
#define EBUTTON_SUPPORT_LONG_PRESS_DURING
#define EBUTTON_SUPPORT_LONG_PRESS_ENG
#define EBUTTON_SUPPORT_TRANSITION_DISABLED
#define EBUTTON_SUPPORT_EACH_CLICK_DISABLED
#define EBUTTON_SUPPORT_DONE_CLICKING_DISABLED
#define EBUTTON_SUPPORT_SINGLE_AND_DOUBLE_CLICKS_DISABLED
#define EBUTTON_SUPPORT_LONG_PRESS_START_DISABLED
#define EBUTTON_SUPPORT_LONG_PRESS_DURING_DISABLED
```
> **NOTE:** If you disable `EBUTTON_SUPPORT_SINGLE_AND_DOUBLE_CLICKS`, then you can use the `DONE_CLICKING` event to process
> single, double, and any other number of clicks. Just use `getClicks()` to get the final clicks count. You can then also disable
Expand Down Expand Up @@ -351,3 +351,4 @@ void loop() {
* `1.0.0 (2017-02-18)`: Original release
* `1.1.0 (2017-02-23)`: Discrete enabling/disabling START, DURING and END support for LONG_PRESS
* `1.2.0 (2019-07-26)`: Changed way of disabling features, to allow specific per-project settings, without having to change the EButton.h file
10 changes: 10 additions & 0 deletions examples/AllEvents/AllEvents.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
#include "Arduino.h"

// ------- Specify required features before including the EButton.h --------
#define EBUTTON_SUPPORT_TRANSITION
#define EBUTTON_SUPPORT_EACH_CLICK
#define EBUTTON_SUPPORT_DONE_CLICKING
#define EBUTTON_SUPPORT_SINGLE_AND_DOUBLE_CLICKS
#define EBUTTON_SUPPORT_LONG_PRESS_START
#define EBUTTON_SUPPORT_LONG_PRESS_DURING
#define EBUTTON_SUPPORT_LONG_PRESS_END

#include "EButton.h"

EButton button(2);
Expand Down
4 changes: 4 additions & 0 deletions examples/BasicClicks/BasicClicks.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "Arduino.h"

// ------- Specify required features before including the EButton.h --------
#define EBUTTON_SUPPORT_SINGLE_AND_DOUBLE_CLICKS

#include "EButton.h"

EButton button(2);
Expand Down
4 changes: 4 additions & 0 deletions examples/BriskyFingers/BriskyFingers.ino
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "Arduino.h"

// ------- Specify required features before including the EButton.h --------
#define EBUTTON_SUPPORT_DONE_CLICKING

#include "EButton.h"

EButton button(2);
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=EButton
version=1.1.0
version=1.2.0
author=Arsen Torbarina <jonniezg@gmail.com>
maintainer=Arsen Torbarina <jonniezg@gmail.com>
sentence=A compact, simple-to-use, reliable and powerful event-driven button library, with proper debouncing and fine grained event structure.
Expand Down

0 comments on commit 4351f4d

Please sign in to comment.