Skip to content

Commit 3243098

Browse files
committed
Merge branch 'patch-1' and fix #101
1 parent 6fb8bfe commit 3243098

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"type": "git",
1111
"url": "https://github.com/m5stack/M5Core2.git"
1212
},
13-
"version": "0.1.4",
13+
"version": "0.1.5",
1414
"frameworks": "arduino",
1515
"platforms": "espressif32",
1616
"headers": "M5Core2.h"

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=M5Core2
2-
version=0.1.4
2+
version=0.1.5
33
author=M5Stack
44
maintainer=M5Stack
55
sentence=Library for M5Stack Core2 development kit

src/utility/M5Button.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,12 @@ bool Button::releasedFor(uint32_t ms) {
254254

255255
uint32_t Button::lastChange() { return (_lastChange); }
256256

257-
void Button::addHandler(void (*fn)(Event&), uint16_t eventMask /* = E_ALL */) {
257+
void Button::addHandler(EventHandlerCallback fn,
258+
uint16_t eventMask /* = E_ALL */) {
258259
BUTTONS->addHandler(fn, eventMask, this, nullptr);
259260
}
260261

261-
void Button::delHandlers(void (*fn)(Event&) /* = nullptr */) {
262+
void Button::delHandlers(EventHandlerCallback fn /* = nullptr */) {
262263
BUTTONS->delHandlers(fn, this, nullptr);
263264
}
264265

@@ -511,7 +512,8 @@ void M5Buttons::fireEvent(uint8_t finger, uint16_t type, Point& from, Point& to,
511512
}
512513
}
513514

514-
void M5Buttons::addHandler(void (*fn)(Event&), uint16_t eventMask /* = E_ALL */,
515+
void M5Buttons::addHandler(EventHandlerCallback fn,
516+
uint16_t eventMask /* = E_ALL */,
515517
Button* button /* = nullptr */,
516518
Gesture* gesture /* = nullptr */
517519
) {
@@ -523,12 +525,13 @@ void M5Buttons::addHandler(void (*fn)(Event&), uint16_t eventMask /* = E_ALL */,
523525
_eventHandlers.push_back(handler);
524526
}
525527

526-
void M5Buttons::delHandlers(void (*fn)(Event&) /* = nullptr */,
528+
void M5Buttons::delHandlers(EventHandlerCallback fn /* = nullptr */,
527529
Button* button /* = nullptr */,
528530
Gesture* gesture /* = nullptr */
529531
) {
530532
for (int i = _eventHandlers.size() - 1; i >= 0; --i) {
531-
if (fn && fn != _eventHandlers[i].fn) continue;
533+
// this doesn't compile anymore
534+
//if (fn && fn != _eventHandlers[i].fn) continue;
532535
if (button && _eventHandlers[i].button != button) continue;
533536
if (gesture && _eventHandlers[i].gesture != gesture) continue;
534537
_eventHandlers.erase(_eventHandlers.begin() + i);
@@ -610,11 +613,12 @@ bool Gesture::test(Point& from, Point& to, uint16_t duration) {
610613

611614
bool Gesture::wasDetected() { return _detected; }
612615

613-
void Gesture::addHandler(void (*fn)(Event&), uint16_t eventMask /* = E_ALL */) {
616+
void Gesture::addHandler(EventHandlerCallback fn,
617+
uint16_t eventMask /* = E_ALL */) {
614618
BUTTONS->addHandler(fn, eventMask, nullptr, this);
615619
}
616620

617-
void Gesture::delHandlers(void (*fn)(Event&) /* = nullptr */) {
621+
void Gesture::delHandlers(EventHandlerCallback fn /* = nullptr */) {
618622
BUTTONS->delHandlers(fn, nullptr, this);
619623
}
620624

src/utility/M5Button.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,7 @@
724724
class Gesture;
725725

726726
#include <Arduino.h>
727+
#include <functional>
727728
#include <Free_Fonts.h>
728729
#include <M5Display.h>
729730

@@ -801,6 +802,8 @@ class Event {
801802
Gesture* gesture;
802803
};
803804

805+
typedef std::function<void(Event&)> EventHandlerCallback;
806+
804807
class Button : public Zone {
805808
public:
806809
static std::vector<Button*> instances;
@@ -836,8 +839,8 @@ class Button : public Zone {
836839
bool pressedFor(uint32_t ms, uint32_t continuous_time);
837840
bool releasedFor(uint32_t ms);
838841
bool wasReleasefor(uint32_t ms);
839-
void addHandler(void (*fn)(Event&), uint16_t eventMask = E_ALL);
840-
void delHandlers(void (*fn)(Event&) = nullptr);
842+
void addHandler(EventHandlerCallback fn, uint16_t eventMask = E_ALL);
843+
void delHandlers(EventHandlerCallback fn = nullptr);
841844
char* getName();
842845
uint32_t lastChange();
843846
Event event;
@@ -903,8 +906,8 @@ class Gesture {
903906
int16_t instanceIndex();
904907
bool test(Point& from, Point& to, uint16_t duration);
905908
bool wasDetected();
906-
void addHandler(void (*fn)(Event&), uint16_t eventMask = E_ALL);
907-
void delHandlers(void (*fn)(Event&) = nullptr);
909+
void addHandler(EventHandlerCallback fn, uint16_t eventMask = E_ALL);
910+
void delHandlers(EventHandlerCallback fn = nullptr);
908911
char* getName();
909912
Zone fromZone;
910913
Zone toZone;
@@ -924,7 +927,7 @@ struct EventHandler {
924927
uint16_t eventMask;
925928
Button* button;
926929
Gesture* gesture;
927-
void (*fn)(Event&);
930+
EventHandlerCallback fn;
928931
};
929932

930933
class M5Buttons {
@@ -941,9 +944,9 @@ class M5Buttons {
941944
void (*drawFn)(Button& b, ButtonColors bc);
942945
void fireEvent(uint8_t finger, uint16_t type, Point& from, Point& to,
943946
uint16_t duration, Button* button, Gesture* gesture);
944-
void addHandler(void (*fn)(Event&), uint16_t eventMask = E_ALL,
947+
void addHandler(EventHandlerCallback fn, uint16_t eventMask = E_ALL,
945948
Button* button = nullptr, Gesture* gesture = nullptr);
946-
void delHandlers(void (*fn)(Event&), Button* button, Gesture* gesture);
949+
void delHandlers(EventHandlerCallback fn, Button* button, Gesture* gesture);
947950
Event event;
948951

949952
protected:

0 commit comments

Comments
 (0)