-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Event System Implementation Re-implemented event system from previous PR #971 to be up to date with current codebase. * Moved profile change event to setProfile * Fixed stray semicolon in adding restart event handler. * Added semicolon to event macro to keep event handlers clean * Removed semicolons from remaining event handler registrations
- Loading branch information
1 parent
00cd79a
commit da0f83b
Showing
26 changed files
with
582 additions
and
17 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
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
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,21 @@ | ||
#ifndef _RESTARTSCREEN_H_ | ||
#define _RESTARTSCREEN_H_ | ||
|
||
#include "GPGFX_UI_widgets.h" | ||
#include "bitmaps.h" | ||
|
||
class RestartScreen : public GPScreen { | ||
public: | ||
RestartScreen() {} | ||
RestartScreen(GPGFX* renderer) { setRenderer(renderer); } | ||
virtual int8_t update(); | ||
virtual void init(); | ||
virtual void shutdown(); | ||
|
||
void setBootMode(uint32_t mode); | ||
protected: | ||
virtual void drawScreen(); | ||
uint32_t bootMode; | ||
}; | ||
|
||
#endif |
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,44 @@ | ||
#ifndef _EVENTMANAGER_H_ | ||
#define _EVENTMANAGER_H_ | ||
|
||
#include <map> | ||
#include <vector> | ||
#include <string> | ||
#include <deque> | ||
#include <array> | ||
#include <functional> | ||
#include <cctype> | ||
#include "config.pb.h" | ||
#include "enums.pb.h" | ||
|
||
#include "GPEvent.h" | ||
#include "GPGamepadEvent.h" | ||
#include "GPEncoderEvent.h" | ||
#include "GPProfileEvent.h" | ||
#include "GPRestartEvent.h" | ||
#include "GPUSBHostEvent.h" | ||
|
||
#define EVENTMGR EventManager::getInstance() | ||
|
||
class EventManager { | ||
public: | ||
typedef std::function<void(GPEvent* event)> EventFunction; | ||
typedef std::pair<GPEventType, std::vector<EventFunction>> EventEntry; | ||
|
||
EventManager(EventManager const&) = delete; | ||
void operator=(EventManager const&) = delete; | ||
static EventManager& getInstance() // Thread-safe storage ensures cross-thread talk | ||
{ | ||
static EventManager instance; | ||
return instance; | ||
} | ||
|
||
void registerEventHandler(GPEventType eventType, EventFunction handler); | ||
void triggerEvent(GPEvent* event); | ||
private: | ||
EventManager(){} | ||
|
||
std::vector<std::pair<GPEventType, std::vector<EventFunction>>> eventList; | ||
}; | ||
|
||
#endif |
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,21 @@ | ||
#ifndef _GPENCODEREVENT_H_ | ||
#define _GPENCODEREVENT_H_ | ||
|
||
class GPEncoderChangeEvent : public GPEvent { | ||
public: | ||
GPEncoderChangeEvent() {} | ||
GPEncoderChangeEvent(uint8_t id, int8_t dir) { | ||
this->encoder = id; | ||
this->direction = dir; | ||
} | ||
~GPEncoderChangeEvent() {} | ||
|
||
uint8_t encoder = 0; | ||
int8_t direction = 0; | ||
|
||
GPEventType eventType() { return this->_eventType; } | ||
private: | ||
GPEventType _eventType = GP_EVENT_ENCODER_CHANGE; | ||
}; | ||
|
||
#endif |
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,16 @@ | ||
#ifndef _GPEVENT_H_ | ||
#define _GPEVENT_H_ | ||
|
||
#define GPEVENT_CALLBACK(x) ([this](GPEvent* event){x;}) | ||
|
||
class GPEvent { | ||
public: | ||
GPEvent() {} | ||
~GPEvent() {} | ||
|
||
virtual GPEventType eventType() { return this->_eventType; } | ||
private: | ||
GPEventType _eventType = GP_EVENT_BASE; | ||
}; | ||
|
||
#endif |
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,130 @@ | ||
#ifndef _GPGAMEPADEVENT_H_ | ||
#define _GPGAMEPADEVENT_H_ | ||
|
||
#include "gamepad.h" | ||
|
||
class GPGamepadEvent : public GPEvent { | ||
public: | ||
GPGamepadEvent() {} | ||
GPGamepadEvent(GamepadState currState) { this->state = currState; } | ||
GPGamepadEvent(uint8_t dpad, uint16_t buttons, uint16_t aux) { | ||
this->state.dpad = dpad; | ||
this->state.buttons = buttons; | ||
this->state.aux = aux; | ||
} | ||
GPGamepadEvent(uint16_t lx, uint16_t ly, uint16_t rx, uint16_t ry, uint8_t lt, uint8_t rt) { | ||
this->state.lx = lx; | ||
this->state.ly = ly; | ||
this->state.rx = rx; | ||
this->state.ry = ry; | ||
this->state.lt = lt; | ||
this->state.rt = rt; | ||
} | ||
GPGamepadEvent(uint8_t dpad, uint16_t buttons, uint16_t aux, uint16_t lx, uint16_t ly, uint16_t rx, uint16_t ry, uint8_t lt, uint8_t rt) { | ||
this->state.dpad = dpad; | ||
this->state.buttons = buttons; | ||
this->state.aux = aux; | ||
this->state.lx = lx; | ||
this->state.ly = ly; | ||
this->state.rx = rx; | ||
this->state.ry = ry; | ||
this->state.lt = lt; | ||
this->state.rt = rt; | ||
} | ||
~GPGamepadEvent() {} | ||
|
||
GamepadState state; | ||
private: | ||
}; | ||
|
||
class GPButtonEvent : public GPGamepadEvent { | ||
public: | ||
GPButtonEvent() {} | ||
GPButtonEvent(GamepadState currState) : GPGamepadEvent(currState) {} | ||
GPButtonEvent(uint8_t dpad, uint16_t buttons, uint16_t aux) : GPGamepadEvent(dpad, buttons, aux) {} | ||
~GPButtonEvent() {} | ||
private: | ||
}; | ||
|
||
class GPButtonUpEvent : public GPButtonEvent { | ||
public: | ||
GPButtonUpEvent() {} | ||
GPButtonUpEvent(GamepadState currState) : GPButtonEvent(currState) {} | ||
GPButtonUpEvent(uint8_t dpad, uint16_t buttons, uint16_t aux) : GPButtonEvent(dpad, buttons, aux) {} | ||
~GPButtonUpEvent() {} | ||
|
||
GPEventType eventType() { return this->_eventType; } | ||
private: | ||
GPEventType _eventType = GP_EVENT_BUTTON_UP; | ||
}; | ||
|
||
class GPButtonDownEvent : public GPButtonEvent { | ||
public: | ||
GPButtonDownEvent() {} | ||
GPButtonDownEvent(GamepadState currState) : GPButtonEvent(currState) {} | ||
GPButtonDownEvent(uint8_t dpad, uint16_t buttons, uint16_t aux) : GPButtonEvent(dpad, buttons, aux) {} | ||
~GPButtonDownEvent() {} | ||
|
||
GPEventType eventType() { return this->_eventType; } | ||
private: | ||
GPEventType _eventType = GP_EVENT_BUTTON_DOWN; | ||
}; | ||
|
||
class GPButtonProcessedUpEvent : public GPButtonEvent { | ||
public: | ||
GPButtonProcessedUpEvent() {} | ||
GPButtonProcessedUpEvent(GamepadState currState) : GPButtonEvent(currState) {} | ||
GPButtonProcessedUpEvent(uint8_t dpad, uint16_t buttons, uint16_t aux) : GPButtonEvent(dpad, buttons, aux) {} | ||
~GPButtonProcessedUpEvent() {} | ||
|
||
GPEventType eventType() { return this->_eventType; } | ||
private: | ||
GPEventType _eventType = GP_EVENT_BUTTON_PROCESSED_UP; | ||
}; | ||
|
||
class GPButtonProcessedDownEvent : public GPButtonEvent { | ||
public: | ||
GPButtonProcessedDownEvent() {} | ||
GPButtonProcessedDownEvent(GamepadState currState) : GPButtonEvent(currState) {} | ||
GPButtonProcessedDownEvent(uint8_t dpad, uint16_t buttons, uint16_t aux) : GPButtonEvent(dpad, buttons, aux) {} | ||
~GPButtonProcessedDownEvent() {} | ||
|
||
GPEventType eventType() { return this->_eventType; } | ||
private: | ||
GPEventType _eventType = GP_EVENT_BUTTON_PROCESSED_DOWN; | ||
}; | ||
|
||
class GPAnalogEvent : public GPGamepadEvent { | ||
public: | ||
GPAnalogEvent() {} | ||
GPAnalogEvent(GamepadState currState) : GPGamepadEvent(currState) {} | ||
GPAnalogEvent(uint16_t lx, uint16_t ly, uint16_t rx, uint16_t ry, uint8_t lt, uint8_t rt) : GPGamepadEvent(lx, ly, rx, ry, lt, rt) {} | ||
~GPAnalogEvent() {} | ||
private: | ||
}; | ||
|
||
class GPAnalogMoveEvent : public GPAnalogEvent { | ||
public: | ||
GPAnalogMoveEvent() {} | ||
GPAnalogMoveEvent(GamepadState currState) : GPAnalogEvent(currState) {} | ||
GPAnalogMoveEvent(uint16_t lx, uint16_t ly, uint16_t rx, uint16_t ry, uint8_t lt, uint8_t rt) : GPAnalogEvent(lx, ly, rx, ry, lt, rt) {} | ||
~GPAnalogMoveEvent() {} | ||
|
||
GPEventType eventType() { return this->_eventType; } | ||
private: | ||
GPEventType _eventType = GP_EVENT_ANALOG_MOVE; | ||
}; | ||
|
||
class GPAnalogProcessedMoveEvent : public GPAnalogEvent { | ||
public: | ||
GPAnalogProcessedMoveEvent() {} | ||
GPAnalogProcessedMoveEvent(GamepadState currState) : GPAnalogEvent(currState) {} | ||
GPAnalogProcessedMoveEvent(uint16_t lx, uint16_t ly, uint16_t rx, uint16_t ry, uint8_t lt, uint8_t rt) : GPAnalogEvent(lx, ly, rx, ry, lt, rt) {} | ||
~GPAnalogProcessedMoveEvent() {} | ||
|
||
GPEventType eventType() { return this->_eventType; } | ||
private: | ||
GPEventType _eventType = GP_EVENT_ANALOG_PROCESSED_MOVE; | ||
}; | ||
|
||
#endif |
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,21 @@ | ||
#ifndef _GPPROFILEEVENT_H_ | ||
#define _GPPROFILEEVENT_H_ | ||
|
||
class GPProfileChangeEvent : public GPEvent { | ||
public: | ||
GPProfileChangeEvent() {} | ||
GPProfileChangeEvent(uint8_t prev, uint8_t curr) { | ||
this->previousValue = prev; | ||
this->currentValue = curr; | ||
} | ||
~GPProfileChangeEvent() {} | ||
|
||
GPEventType eventType() { return this->_eventType; } | ||
|
||
uint8_t previousValue; | ||
uint8_t currentValue; | ||
private: | ||
GPEventType _eventType = GP_EVENT_PROFILE_CHANGE; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.