diff --git a/src/core/shell.cpp b/src/core/shell.cpp index 80ee917..d4ad7f2 100644 --- a/src/core/shell.cpp +++ b/src/core/shell.cpp @@ -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; +} diff --git a/src/core/shell.h b/src/core/shell.h index 5facb71..d5e99eb 100644 --- a/src/core/shell.h +++ b/src/core/shell.h @@ -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(); };