Skip to content

Commit

Permalink
Prepare version 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mathertel committed May 8, 2023
1 parent b95e13a commit d11a767
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
17 changes: 12 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@

All notable changes to this project will be documented in this file starting 2021.

## [2.0.6] - 2023-05-08
## [2.1.0] - 2023-05-08

This release is a minor update as there is new internal functionality and
some functions have been renamed.

The former functions `setDebounceTicks`, `setClickTicks` and `setPressTicks` are marked deprecated.
The term `Ticks` in these functions where confusing. Replace them with the ...Ms function calls.
There is no functional change on them.

* CPP Checks added in Github actions. Thanks to @mkinney
* Debouncing input levels implemented in a central place. Thanks to @IhorNehrutsa
Expand All @@ -11,6 +18,8 @@ All notable changes to this project will be documented in this file starting 202
* Fixing examples for ESP8266 and ESP32.
* GitHub Action extended to compile for ESP8266 and ESP32

Many thanks to the improvements included by (**@IhorNehrutsa**)

## [2.0.4] - 2022-01-22

* checked for ESP32 (SimpleOneButton, InterruptOneButton, BlinkMachine)
Expand All @@ -26,7 +35,7 @@ and included example PIN definitions for ESP32
* Compiler warning removed
* Documentation

## [2.0.0] - 2021-01-22
## [2.0.0] - 2021-01-22

* CHANGELOG created.
* Many thanks to the improvements included from #27 (**@aslobodyanuk**), #59 (**@ShaggyDog18**) and #73 (**@geeksville**).
Expand Down Expand Up @@ -55,13 +64,11 @@ The function **isIdle()** was added to allow detect a current interaction.

The library now supports to detect multiple (>2) clicks in a row using **attachMultiClick()** .


* The internal _state is using enum instead of plain numbers to make the library more readable.
* functions that had been marked deprecated are now removed. (attachPress->attachLongPressXXX)
* added const to constant parameters to enable meaningful compiler warnings.
* added code for de-bouncing double clicks from pull 27.
* added isIdle() function to find out that the internal state is `init`.

* added isIdle() function to find out that the internal state is `init`.

### Examples

Expand Down
24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ This enables you to reuse the same button for multiple functions and lowers the
This is also a sample for implementing simple finite-state machines by using the simple pattern above.

You can find more details on this library at
http://www.mathertel.de/Arduino/OneButtonLibrary.aspx
<http://www.mathertel.de/Arduino/OneButtonLibrary.aspx>

The change log of this library can be found in [CHANGELOG](CHANGELOG.md).


## Getting Started

Clone this repository into `Arduino/Libraries` or use the built-in Arduino IDE Library manager to install
Expand All @@ -26,7 +25,6 @@ a copy of this library. You can find more detail about installing libraries

Each physical button requires its own `OneButton` instance. You can initialize them like this:


### Initialize a Button to GND

```CPP
Expand All @@ -45,7 +43,6 @@ OneButton btn = OneButton(
);
```


### Initialize a Button to VCC

```CPP
Expand All @@ -65,7 +62,6 @@ OneButton btn = OneButton(
);
```


### Attach State Events

Once you have your button initialized, you can handle events by attaching them to the button
Expand All @@ -86,8 +82,7 @@ btn.attachDoubleClick([]() {
});
```


### Don't forget to `tick()`!
### Don't forget to `tick()`

In order for `OneButton` to work correctly, you must call `tick()` on __each button instance__
within your main `loop()`. If you're not getting any button events, this is probably why.
Expand All @@ -100,19 +95,17 @@ void loop() {
}
```


### Usage with lambdas that capture context

You **can't pass** a lambda-**with-context** to an argument which expects a **function pointer**. To work that around,
You __can't pass__ a lambda-__with-context__ to an argument which expects a __function pointer__. To work that around,
use `paramtererizedCallbackFunction`. We pass the context (so the pointer to the object we want to access) to the library
and it will give it back to the lambda.

```CPP
okBtn.attachClick([](void *ctx){Serial.println(*(((BtnHandler*)(ctx))) -> state}}), this);
```
See also discussion in [Issue #112 ](https://github.com/mathertel/OneButton/issues/112).
See also discussion in [Issue #112](https://github.com/mathertel/OneButton/issues/112).
## State Events
Expand All @@ -127,15 +120,15 @@ Here's a full list of events handled by this library:
| `attachDuringLongPress` | Fires periodically as long as the button is held down. |
| `attachLongPressStop` | Fires when the button is released after a long hold. |
### Event Timing
Valid events occur when `tick()` is called after a specified number of milliseconds. You can use
the following functions to change the timing.
**Note:** Attaching a double click will increase the delay for detecting a single click. If a double
__Note:__ Attaching a double click will increase the delay for detecting a single click. If a double
click event is not attached, the library will assume a valid single click after one click duration,
otherwise it must wait for the double click timeout to pass.
This is because a single click callback must not to be triggered in case of a double click event.
| Function | Default | Description |
| ----------------------- | ---------- | ------------------------------------------------------------- |
Expand All @@ -146,6 +139,9 @@ otherwise it must wait for the double click timeout to pass.
You may change these default values but be aware that when you specify too short times
it is hard to click twice or you will create a press instead of a click.
The former functions `setDebounceTicks`, `setClickTicks` and `setPressTicks` are marked deprecated.
The term `Ticks` in these functions where confusing. Replace them with the ...Ms function calls.
There is no functional change on them.
### Additional Functions
Expand All @@ -156,13 +152,11 @@ it is hard to click twice or you will create a press instead of a click.
| `bool isLongPressed()` | Detect whether or not the button is currently inside a long press. |
| `int getPressedTicks()` | Get the current number of milliseconds that the button has been held down for. |
### `tick()` and `reset()`
You can specify a logic level when calling `tick(bool)`, which will skip reading the pin and use
that level instead. If you wish to reset the internal state of your buttons, call `reset()`.
## Troubleshooting
If your buttons aren't acting they way they should, check these items:
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=OneButton
version=2.0.5
version=2.1.0
author=Matthias Hertel
maintainer=Matthias Hertel, https://www.mathertel.de
sentence=Arduino library for improving the usage of a singe input button.
Expand Down
6 changes: 4 additions & 2 deletions src/OneButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ class OneButton
/**
* set # millisec after single click is assumed.
*/
void setClickTicks(const unsigned int ms); // obsolete
[[deprecated("Use setClickMs() instead.")]]
void setClickTicks(const unsigned int ms); // deprecated
void setClickMs(const unsigned int ms) { setClickTicks(ms); };

/**
* set # millisec after press is assumed.
*/
void setPressTicks(const unsigned int ms); // obsolete
[[deprecated("Use setPressMs() instead.")]]
void setPressTicks(const unsigned int ms); // deprecated
void setPressMs(const unsigned int ms) { setPressTicks(ms); };

// ----- Attach events functions -----
Expand Down

0 comments on commit d11a767

Please sign in to comment.