-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from J-A-A-M/buttons_impr
Покращення роботи кнопок
- Loading branch information
Showing
4 changed files
with
131 additions
and
74 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,66 @@ | ||
#include "JaamButton.h" | ||
#include <OneButton.h> | ||
|
||
|
||
int button1Pin = -1; | ||
int button2Pin = -1; | ||
OneButton button1; | ||
OneButton button2; | ||
|
||
JaamButton::JaamButton() { | ||
} | ||
|
||
void JaamButton::tick() { | ||
if (isButton1Enabled()) button1.tick(); | ||
if (isButton2Enabled()) button2.tick(); | ||
} | ||
|
||
void JaamButton::setButton1Pin(int pin) { | ||
button1Pin = pin; | ||
if (isButton1Enabled()) { | ||
button1.setup(button1Pin); | ||
} | ||
} | ||
|
||
void JaamButton::setButton2Pin(int pin) { | ||
button2Pin = pin; | ||
if (isButton1Enabled()) { | ||
button2.setup(button2Pin); | ||
} | ||
} | ||
|
||
void JaamButton::setButton1ClickListener(void (*listener)(void)) { | ||
if (isButton1Enabled()) { | ||
button1.attachClick(listener); | ||
} | ||
} | ||
|
||
void JaamButton::setButton2ClickListener(void (*listener)(void)) { | ||
if (isButton2Enabled()) { | ||
button2.attachClick(listener); | ||
} | ||
} | ||
|
||
void JaamButton::setButton1LongClickListener(void (*listener)(void)) { | ||
if (isButton1Enabled()) { | ||
button1.attachLongPressStart(listener); | ||
} | ||
} | ||
|
||
void JaamButton::setButton2LongClickListener(void (*listener)(void)) { | ||
if (isButton2Enabled()) { | ||
button2.attachLongPressStart(listener); | ||
} | ||
} | ||
|
||
bool JaamButton::isButton1Enabled() { | ||
return button1Pin >= 0; | ||
} | ||
|
||
bool JaamButton::isButton2Enabled() { | ||
return button2Pin >= 0; | ||
} | ||
|
||
bool JaamButton::isAnyButtonEnabled() { | ||
return isButton1Enabled() || isButton2Enabled(); | ||
} |
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,14 @@ | ||
class JaamButton { | ||
public: | ||
JaamButton(); | ||
void tick(); | ||
void setButton1Pin(int pin); | ||
void setButton2Pin(int pin); | ||
void setButton1ClickListener(void (*listener)(void)); | ||
void setButton2ClickListener(void (*listener)(void)); | ||
void setButton1LongClickListener(void (*listener)(void)); | ||
void setButton2LongClickListener(void (*listener)(void)); | ||
bool isButton1Enabled(); | ||
bool isButton2Enabled(); | ||
bool isAnyButtonEnabled(); | ||
}; |
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