From d11a767776da0b26e932478e2fbeff7ef6b4f567 Mon Sep 17 00:00:00 2001 From: Matthias Hertel Date: Mon, 8 May 2023 09:22:53 +0200 Subject: [PATCH] Prepare version 2.1.0 --- CHANGELOG.md | 17 ++++++++++++----- README.md | 24 +++++++++--------------- library.properties | 2 +- src/OneButton.h | 6 ++++-- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b453cb..0e1f922 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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) @@ -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**). @@ -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 diff --git a/README.md b/README.md index 7f60d12..5a619a0 100644 --- a/README.md +++ b/README.md @@ -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 + 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 @@ -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 @@ -45,7 +43,6 @@ OneButton btn = OneButton( ); ``` - ### Initialize a Button to VCC ```CPP @@ -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 @@ -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. @@ -100,10 +95,9 @@ 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. @@ -111,8 +105,7 @@ and it will give it back to the lambda. 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 @@ -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 | | ----------------------- | ---------- | ------------------------------------------------------------- | @@ -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 @@ -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: diff --git a/library.properties b/library.properties index 595b45a..6bcef60 100644 --- a/library.properties +++ b/library.properties @@ -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. diff --git a/src/OneButton.h b/src/OneButton.h index 17b4866..25d645e 100644 --- a/src/OneButton.h +++ b/src/OneButton.h @@ -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 -----