Add USB auto-trigger detection to HID Injector on host connection - increase module array to 50
This commit is contained in:
@@ -154,6 +154,7 @@ void Shell::back() {
|
|||||||
|
|
||||||
void Shell::loop() {
|
void Shell::loop() {
|
||||||
M5Cardputer.update();
|
M5Cardputer.update();
|
||||||
|
checkUsbAutoTrigger();
|
||||||
|
|
||||||
if (M5Cardputer.Keyboard.isChange() && M5Cardputer.Keyboard.isPressed()) {
|
if (M5Cardputer.Keyboard.isChange() && M5Cardputer.Keyboard.isPressed()) {
|
||||||
auto st = M5Cardputer.Keyboard.keysState();
|
auto st = M5Cardputer.Keyboard.keysState();
|
||||||
@@ -181,3 +182,25 @@ void Shell::loop() {
|
|||||||
mods[active]->draw();
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ public:
|
|||||||
void begin();
|
void begin();
|
||||||
void loop();
|
void loop();
|
||||||
private:
|
private:
|
||||||
static constexpr int MAX = 12;
|
static constexpr int MAX = 50;
|
||||||
Module* mods[MAX]; int nmods = 0;
|
Module* mods[MAX]; int nmods = 0;
|
||||||
int sel = 0; // menu cursor
|
int sel = 0; // menu cursor
|
||||||
int active = -1; // -1 == in menu
|
int active = -1; // -1 == in menu
|
||||||
@@ -17,4 +17,5 @@ private:
|
|||||||
void drawMenu(bool force = false);
|
void drawMenu(bool force = false);
|
||||||
void enter(int i);
|
void enter(int i);
|
||||||
void back();
|
void back();
|
||||||
|
void checkUsbAutoTrigger();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user