Add USB auto-trigger detection to HID Injector on host connection - increase module array to 50

This commit is contained in:
Claude
2026-09-26 00:09:36 +00:00
parent 43b28ea2e7
commit b76f016bcd
2 changed files with 25 additions and 1 deletions

View File

@@ -154,6 +154,7 @@ void Shell::back() {
void Shell::loop() {
M5Cardputer.update();
checkUsbAutoTrigger();
if (M5Cardputer.Keyboard.isChange() && M5Cardputer.Keyboard.isPressed()) {
auto st = M5Cardputer.Keyboard.keysState();
@@ -181,3 +182,25 @@ void Shell::loop() {
mods[active]->draw();
}
}
void Shell::checkUsbAutoTrigger() {
static uint32_t lastCheck = 0;
static bool wasPlugged = false;
if (millis() - lastCheck < 500) return;
lastCheck = millis();
bool isPlugged = false;
#if __has_include("tusb.h")
isPlugged = tud_mounted();
#endif
if (isPlugged && !wasPlugged) {
for (int i = 0; i < nmods; i++) {
if (strcmp(mods[i]->name(), "HID Inject") == 0) {
enter(i);
return;
}
}
}
wasPlugged = isPlugged;
}

View File

@@ -8,7 +8,7 @@ public:
void begin();
void loop();
private:
static constexpr int MAX = 12;
static constexpr int MAX = 50;
Module* mods[MAX]; int nmods = 0;
int sel = 0; // menu cursor
int active = -1; // -1 == in menu
@@ -17,4 +17,5 @@ private:
void drawMenu(bool force = false);
void enter(int i);
void back();
void checkUsbAutoTrigger();
};