-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable click handling if we fast tap mode btn and turn encoder
- Loading branch information
Showing
5 changed files
with
51 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include "SafeEncButton.h" | ||
|
||
// Needed to resolve this | ||
// https://github.com/GyverLibs/EncButton/issues/58 | ||
template<uint8_t Pin> | ||
class SmartButton : public ButtonT<Pin> { | ||
public: | ||
void tick() { | ||
ButtonT<Pin>::tick(); | ||
if (m_ignoreTillPressing && ButtonT<Pin>::press()) { | ||
m_ignoreTillPressing = false; | ||
m_timeout = millis(); | ||
ButtonT<Pin>::clear(); | ||
} | ||
|
||
// we need some some before wrapped button return click() == true, after press() == false | ||
if (!m_ignoreTillPressing && m_ignore && static_cast<uint16_t>(millis()) - m_timeout > EB_DEB_TIME) { | ||
m_ignore = false; | ||
ButtonT<Pin>::clear(); | ||
} | ||
} | ||
|
||
void ignoreTillPressing() { | ||
m_ignoreTillPressing = true; | ||
m_ignore = true; | ||
} | ||
|
||
bool click() { return !m_ignore && ButtonT<Pin>::click(); } | ||
bool hold() { return !m_ignore && ButtonT<Pin>::hold(); } | ||
|
||
private: | ||
bool m_ignoreTillPressing = false; | ||
bool m_ignore = false; | ||
uint16_t m_timeout; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters