Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro Rewrite #922

Merged
merged 32 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a446414
[ImgBot] Optimize images
ImgBotApp Feb 5, 2024
df2e3ec
Merge pull request #8 from arntsonl/imgbot
arntsonl Feb 8, 2024
baa61e6
Merge branch 'OpenStickCommunity:main' into main
arntsonl Feb 8, 2024
9ddf6cd
Merge branch 'main' of https://github.com/arntsonl/GP2040-CE
arntsonl Feb 17, 2024
19b367e
Merge branch 'main' of https://github.com/arntsonl/GP2040-CE
arntsonl Mar 24, 2024
3687e2f
Merge branch 'main' of https://github.com/arntsonl/GP2040-CE
arntsonl Mar 24, 2024
087de36
Updating macros to almost working
arntsonl Mar 27, 2024
89908ac
Macros is now working as intended
arntsonl Mar 27, 2024
eff6b74
Fixed odd limit on default values
arntsonl Mar 27, 2024
b99299e
Quick clean-up to move available and setup() pin settings
arntsonl Mar 27, 2024
36b52c0
Update to the macro button + gamepad trigger so you cannot select the…
arntsonl Mar 28, 2024
a72d54b
Rewriting some display code
arntsonl Mar 29, 2024
0b1db74
Fix for button masks set to an invalid pin
arntsonl Mar 29, 2024
bfc1196
Fix for const
arntsonl Mar 29, 2024
cbd8801
Things were happening out of order, display wouldn't show.
arntsonl Mar 31, 2024
32d4b4a
Indentation fixes
arntsonl Mar 31, 2024
e26a158
Merge pull request #12 from arntsonl/display_test
arntsonl Mar 31, 2024
fbe4cbb
Merge branch '20240323_macro_rewrite' into macro_remerge
arntsonl Mar 31, 2024
71e5b82
Fix merge
arntsonl Mar 31, 2024
bfe58e6
Merge pull request #13 from arntsonl/macro_remerge
arntsonl Mar 31, 2024
0755e2a
Added migration from 0.7.7 macros, added macro to profile re-init (pr…
arntsonl Mar 31, 2024
ae32bbe
Merge branch '20240323_macro_rewrite' into macro_merge
arntsonl Mar 31, 2024
6ba1259
Merge pull request #14 from arntsonl/macro_merge
arntsonl Mar 31, 2024
b3d3d8c
Macro Enabled bool added to our button layout screen. Macro enabled f…
arntsonl Mar 31, 2024
69065a3
Merge branch 'OpenStickCommunity:main' into 20240323_macro_rewrite
arntsonl Mar 31, 2024
9c62c05
Update and invisible screen bug fix. The issue was bool _configMode w…
arntsonl Mar 31, 2024
5813ee7
Merge branch '20240323_macro_rewrite' of https://github.com/arntsonl/…
arntsonl Mar 31, 2024
8677fb2
Two small fixes, now GPGFX_UI getconfigmode mimics the display::getco…
arntsonl Mar 31, 2024
4baa440
Fix for profile #
arntsonl Mar 31, 2024
1603cfa
Moved input history to a static const 2-D array. This will hopefully …
arntsonl Mar 31, 2024
c0c7899
Missed this in the config util update
arntsonl Apr 1, 2024
987adfc
"Press" is now press instead of hold
arntsonl Apr 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions headers/addons/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class DisplayAddon : public GPAddon
virtual void process();
virtual std::string name() { return DisplayName; }
private:
bool updateDisplayScreen();
void drawStatusBar(Gamepad*);
void initMenu(char**);
bool pressedUp();
Expand All @@ -202,14 +203,9 @@ class DisplayAddon : public GPAddon
uint32_t prevMillis;
std::string statusBar;
Gamepad* gamepad;
Gamepad* pGamepad;
bool configMode;

GPGFX* gpDisplay;
GPScreen* gpScreen;

std::map<DisplayMode, GPScreen*> loadedScreens;

DisplayMode currDisplayMode;
bool turnOffWhenSuspended;
};
Expand Down
30 changes: 16 additions & 14 deletions headers/addons/input_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,25 @@ class InputMacro : public GPAddon {
virtual void setup(); // Analog Setup
virtual void process() {}; // Analog Process
virtual void preprocess();
virtual void reinit();
virtual std::string name() { return InputMacroName; }
private:
int macroPosition = -1;
bool isMacroRunning = false;
bool isMacroTriggerHeld = false;

uint64_t macroStartTime = 0;
uint64_t macroTriggerDebounceStartTime = 0;

int macroInputPosition = 0;
bool macroInputPressed = false;
uint32_t macroInputHoldTime = INPUT_HOLD_US;
bool prevMacroInputPressed = false;
bool boardLedEnabled = false;

MacroOptions inputMacroOptions;
void checkMacroPress();
void checkMacroAction();
void runCurrentMacro();
void reset();
bool isMacroRunning;
bool isMacroTriggerHeld;
int macroPosition;
uint32_t macroButtonMask;
uint32_t macroPinMasks[6];
uint64_t macroStartTime;
int pressedMacro;
int macroInputPosition;
uint32_t macroInputHoldTime;
bool prevMacroInputPressed;
bool boardLedEnabled;
MacroOptions * inputMacroOptions;
};

#endif // _InputMacro_H_
6 changes: 0 additions & 6 deletions headers/display/GPGFX_UI.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ class GPGFX_UI {
public:
GPGFX_UI();
GPGFX_UI(GPGFX* renderer) { setRenderer(renderer); }

void setRenderer(GPGFX* renderer) { _renderer = renderer; }
GPGFX* getRenderer() { return _renderer; }

Gamepad* getGamepad();
Gamepad* getProcessedGamepad();

DisplayOptions getDisplayOptions();

bool getConfigMode();

uint16_t map(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max);
private:
GPGFX* _renderer;
Expand Down
3 changes: 1 addition & 2 deletions headers/display/ui/elements/GPButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
class GPButton : public GPWidget {
public:
void draw();
GPButton* setSizeX(uint16_t sizeX) { this->_sizeX = sizeX; return this; }
GPButton* setSizeY(uint16_t sizeY) { this->_sizeY = sizeY; return this; }
GPButton* setSize(uint16_t sizeX, uint16_t sizeY) { this->_sizeX = sizeX; this->_sizeY = sizeY; return this; }
GPButton* setInputMask(int16_t inputMask) { this->_inputMask = inputMask; return this; }
GPButton* setInputDirection(bool inputDirection) { this->_inputDirection = inputDirection; return this; }
GPButton* setInputType(GPElement inputType) { this->_inputType = inputType; return this; }
Expand Down
23 changes: 8 additions & 15 deletions headers/display/ui/elements/GPScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,23 @@

#include <vector>
#include <cstring>
#include <memory>
#include "GPWidget.h"

class GPScreen : public GPWidget {
public:
void draw();
std::string header = "";
std::string footer = "";
virtual int8_t update();
virtual int8_t update() = 0;
void clear();

template<typename _GPWidget, typename... _GPArgs>
_GPWidget* addElement(_GPArgs&&... args) {
using GPW = std::unique_ptr<_GPWidget>;
GPW new_element = std::make_unique<_GPWidget>(std::forward<_GPArgs>(args)...);
GPWidget* raw_ptr = new_element.get();
displayList.emplace_back(std::move(new_element));
return static_cast<_GPWidget*>(raw_ptr);
}
virtual void init() = 0;
protected:
virtual void drawScreen() = 0;

GPWidget* addElement(GPWidget* element) {
displayList.push_back(element);
element->setID(displayList.size()-1);
return element;
}
private:
std::vector<std::unique_ptr<GPWidget>> displayList;
std::vector<GPWidget*> displayList;
};

#endif
3 changes: 1 addition & 2 deletions headers/display/ui/elements/GPShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
class GPShape : public GPWidget {
public:
void draw();
GPShape* setSizeX(uint16_t sizeX) { this->_sizeX = sizeX; return this; }
GPShape* setSizeY(uint16_t sizeY) { this->_sizeY = sizeY; return this; }
GPShape* setSize(uint16_t sizeX, uint16_t sizeY) { this->_sizeX = sizeX; this->_sizeY = sizeY; return this; }
GPShape* setAngle(double angle) { this->_angle = angle; return this; }
GPShape* setAngleEnd(double angleEnd) { this->_angleEnd = angleEnd; return this; }
GPShape* setClosed(bool closed) { this->_closed = closed; return this; }
Expand Down
3 changes: 1 addition & 2 deletions headers/display/ui/elements/GPSprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
class GPSprite : public GPWidget {
public:
void draw();
GPSprite* setSizeX(uint16_t sizeX) { this->_sizeX = sizeX; return this; }
GPSprite* setSizeY(uint16_t sizeY) { this->_sizeY = sizeY; return this; }
GPSprite* setSize(uint16_t sizeX, uint16_t sizeY) { this->_sizeX = sizeX; this->_sizeY = sizeY; return this; }
private:
uint16_t _sizeX = 0;
uint16_t _sizeY = 0;
Expand Down
191 changes: 98 additions & 93 deletions headers/display/ui/screens/ButtonLayoutScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,103 @@
#define INPUT_HISTORY_MAX_INPUTS 22
#define INPUT_HISTORY_MAX_MODES 11

// Static to ensure memory is never doubled
static const char * displayNames[INPUT_HISTORY_MAX_MODES][INPUT_HISTORY_MAX_INPUTS] = {
{ // HID / DINPUT
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
CHAR_CROSS, CHAR_CIRCLE, CHAR_SQUARE, CHAR_TRIANGLE,
"L1", "R1", "L2", "R2",
"SL", "ST", "L3", "R3", "PS", "A2"
},
{ // Switch
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"B", "A", "Y", "X",
"L", "R", "ZL", "ZR",
"-", "+", "LS", "RS", CHAR_HOME_S, CHAR_CAP_S
},
{ // XInput
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "X", "Y",
"LB", "RB", "LT", "RT",
CHAR_VIEW_X, CHAR_MENU_X, "LS", "RS", CHAR_HOME_X, "A2"
},
{ // Keyboard / HID-KB
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"B1", "B2", "B3", "B4",
"L1", "R1", "L2", "R2",
"S1", "S2", "L3", "R3", "A1", "A2"
},
{ // PS4
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
CHAR_CROSS, CHAR_CIRCLE, CHAR_SQUARE, CHAR_TRIANGLE,
"L1", "R1", "L2", "R2",
CHAR_SHARE_P, "OP", "L3", "R3", CHAR_HOME_P, CHAR_TPAD_P
},
{ // GEN/MD Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "X", "Y",
"", "Z", "", "C",
"M", "S", "", "", "", ""
},
{ // Neo Geo Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"B", "D", "A", "C",
"", "", "", "",
"SE", "ST", "", "", "", ""
},
{ // PC Engine/TG16 Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"I", "II", "", "",
"", "", "", "",
"SE", "RUN", "", "", "", ""
},
{ // Egret II Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "C", "D",
"", "E", "", "F",
"CRD", "ST", "", "", "MN", ""
},
{ // Astro City Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "D", "E",
"", "C", "", "F",
"CRD", "ST", "", "", "", ""
},
{ // Original Xbox
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "X", "Y",
"BL", "WH", "L", "R",
"BK", "ST", "LS", "RS", "", ""
}
};

class ButtonLayoutScreen : public GPScreen {
public:
ButtonLayoutScreen() {}
ButtonLayoutScreen(GPGFX* renderer) { setRenderer(renderer); }
int8_t update();
virtual int8_t update();
virtual void init();
protected:
void drawScreen();
virtual void drawScreen();
private:
// new layout methods
GPLever* drawLever(uint16_t startX, uint16_t startY, uint16_t sizeX, uint16_t sizeY, uint16_t strokeColor, uint16_t fillColor, uint16_t inputType);
GPButton* drawButton(uint16_t startX, uint16_t startY, uint16_t sizeX, uint16_t sizeY, uint16_t strokeColor, uint16_t fillColor, int16_t inputMask = -1);
GPSprite* drawSprite(uint16_t startX, uint16_t startY, uint16_t sizeX, uint16_t sizeY);
GPShape* drawShape(uint16_t startX, uint16_t startY, uint16_t sizeX, uint16_t sizeY, uint16_t strokeColor, uint16_t fillColor);
GPWidget* drawElement(GPButtonLayout element);
GPLever* addLever(uint16_t startX, uint16_t startY, uint16_t sizeX, uint16_t sizeY, uint16_t strokeColor, uint16_t fillColor, uint16_t inputType);
GPButton* addButton(uint16_t startX, uint16_t startY, uint16_t sizeX, uint16_t sizeY, uint16_t strokeColor, uint16_t fillColor, int16_t inputMask = -1);
GPSprite* addSprite(uint16_t startX, uint16_t startY, uint16_t sizeX, uint16_t sizeY);
GPShape* addShape(uint16_t startX, uint16_t startY, uint16_t sizeX, uint16_t sizeY, uint16_t strokeColor, uint16_t fillColor);
GPWidget* pushElement(GPButtonLayout element);
void generateHeader();

const std::map<uint16_t, uint16_t> displayModeLookup = {
{INPUT_MODE_HID, 0},
Expand All @@ -72,26 +155,28 @@ class ButtonLayoutScreen : public GPScreen {
{INPUT_MODE_XBOXORIGINAL, 10},
};

Gamepad* gamepad;
InputMode inputMode;
std::string statusBar;
std::string footer;

bool isInputHistoryEnabled = false;
uint16_t inputHistoryX = 0;
uint16_t inputHistoryY = 0;
int16_t inputHistoryLength = 0;
size_t inputHistoryLength = 0;
std::string historyString;
std::deque<std::string> inputHistory;
std::array<bool, INPUT_HISTORY_MAX_INPUTS> lastInput;

bool profileModeDisplay;
uint8_t profileDelay = 2;
int profileDelayStart = 0;
bool displayProfileBanner = true;

bool hasInitialized = false;

uint16_t prevButtonState = 0;
uint8_t prevLayoutLeft = 0;
uint8_t prevLayoutRight = 0;
uint8_t prevProfileNumber = 0;

void showProfileBanner();
bool macroEnabled;

uint16_t map(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max);
void processInputHistory();
Expand All @@ -103,86 +188,6 @@ class ButtonLayoutScreen : public GPScreen {
bool pressedUpRight();
bool pressedDownLeft();
bool pressedDownRight();

const std::string displayNames[INPUT_HISTORY_MAX_MODES][INPUT_HISTORY_MAX_INPUTS] = {
{ // HID / DINPUT
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
CHAR_CROSS, CHAR_CIRCLE, CHAR_SQUARE, CHAR_TRIANGLE,
"L1", "R1", "L2", "R2",
"SL", "ST", "L3", "R3", "PS", "A2"
},
{ // Switch
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"B", "A", "Y", "X",
"L", "R", "ZL", "ZR",
"-", "+", "LS", "RS", CHAR_HOME_S, CHAR_CAP_S
},
{ // XInput
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "X", "Y",
"LB", "RB", "LT", "RT",
CHAR_VIEW_X, CHAR_MENU_X, "LS", "RS", CHAR_HOME_X, "A2"
},
{ // Keyboard / HID-KB
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"B1", "B2", "B3", "B4",
"L1", "R1", "L2", "R2",
"S1", "S2", "L3", "R3", "A1", "A2"
},
{ // PS4
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
CHAR_CROSS, CHAR_CIRCLE, CHAR_SQUARE, CHAR_TRIANGLE,
"L1", "R1", "L2", "R2",
CHAR_SHARE_P, "OP", "L3", "R3", CHAR_HOME_P, CHAR_TPAD_P
},
{ // GEN/MD Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "X", "Y",
"", "Z", "", "C",
"M", "S", "", "", "", ""
},
{ // Neo Geo Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"B", "D", "A", "C",
"", "", "", "",
"SE", "ST", "", "", "", ""
},
{ // PC Engine/TG16 Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"I", "II", "", "",
"", "", "", "",
"SE", "RUN", "", "", "", ""
},
{ // Egret II Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "C", "D",
"", "E", "", "F",
"CRD", "ST", "", "", "MN", ""
},
{ // Astro City Mini
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "D", "E",
"", "C", "", "F",
"CRD", "ST", "", "", "", ""
},
{ // Original Xbox
CHAR_UP, CHAR_DOWN, CHAR_LEFT, CHAR_RIGHT,
CHAR_UL, CHAR_UR, CHAR_DL, CHAR_DR,
"A", "B", "X", "Y",
"BL", "WH", "L", "R",
"BK", "ST", "LS", "RS", "", ""
}
};
};

#endif
Loading