Skip to content

Commit

Permalink
ready for 2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
LennartHennigs committed Dec 13, 2022
1 parent 591e37e commit 56eb14e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

## Unreleased

-

## [2.2.0] - 2022-12-13

- Refactored the main `loop()`
- Cleaned up the long press handling
- Rewrote click detection
- Defaults (x>3)-clicks to triple
- Removed compiler switches – as they made the code unreadable and they did not save a lot of space
- Cleaned up the long press handling
- Removed compiler switches – they made the code unreadable and they only saved a few bytes
- Added `byte getLongClickCount()` function
- Updated the [LongpressHandler](https://github.com/LennartHennigs/Button2/blob/master/examples/LongpressHandler/LongpressHandler.ino) example
- Defaults (x>3)-clicks to triple
- Fixed bug with button ID

**Note:** Unreleased changes are checked in but not part of an official release (available through the Arduino IDE or PlatfomIO) yet. This allows you to test WiP features and give feedback to them.

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017-2022 Lennart Hennigs
Copyright (c) 2017-2022 Lennart Hennigs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Button2",
"version": "2.1.0",
"version": "2.2.0",
"keywords": "button",
"description": "Arduino/ESP Library to simplify working with buttons. It allows you to use callback functions to track single, double, triple and long clicks. Alternatively, it provides function to use in your main loop(). The library also takes care of debouncing. Using this lib will reduce and simplify your source code significantly.",
"homepage": "https://github.com/LennartHennigs/Button2",
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=Button2
version=2.1.0
version=2.2.0
author=Lennart Hennigs
maintainer=Lennart Hennigs <[email protected]>
sentence=Arduino/ESP library to simplify working with buttons.
Expand Down
13 changes: 10 additions & 3 deletions src/Button2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ int Button2::_nextID = 0;

Button2::Button2() {
pin = UNDEFINED_PIN;
id = _nextID++;
_setID();
}

/////////////////////////////////////////////////////////////////
// contructor

Button2::Button2(byte attachTo, byte buttonMode /* = INPUT_PULLUP */, boolean activeLow /* = true */) {
begin(attachTo, buttonMode, activeLow);
_setID();
}

/////////////////////////////////////////////////////////////////

void Button2::begin(byte attachTo, byte buttonMode /* = INPUT_PULLUP */, boolean activeLow /* = true */) {
pin = attachTo;
id = _nextID++;
longclick_counter = 0;
longclick_retriggerable = false;
_pressedState = activeLow ? LOW : HIGH;
Expand Down Expand Up @@ -334,6 +334,13 @@ void Button2::_handlePress(long now) {

/////////////////////////////////////////////////////////////////

void Button2::_setID() {
id = _nextID;
_nextID++;
}

/////////////////////////////////////////////////////////////////

void Button2::_handleRelease(long now) {
// is it released right now?
if (prev_state == _pressedState) {
Expand Down Expand Up @@ -384,7 +391,7 @@ void Button2::_checkForLongClick(long now) {

/////////////////////////////////////////////////////////////////

byte Button2::getLongClickCount() {
byte Button2::getLongClickCount() const {
return longclick_counter;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Button2.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Button2 {
void _validKeypress();
void _checkForLongClick(long now);
void _reportClicks();
void _setID();

public:
Button2();
Expand Down Expand Up @@ -137,7 +138,7 @@ class Button2 {
void waitForLong(bool keepState = false);

byte getNumberOfClicks() const;
byte getLongClickCount();
byte getLongClickCount() const;

clickType getType() const;
String clickToString(clickType type) const;
Expand Down

0 comments on commit 56eb14e

Please sign in to comment.