From a94218da018c63598460a68a573c66bd0a9f4d4d Mon Sep 17 00:00:00 2001 From: CrazyRedMachine Date: Fri, 14 Aug 2020 13:27:53 +0200 Subject: [PATCH] new mixed mode --- ModeSwitch/C/src/modeswitch.cpp | 10 +++++----- ModeSwitch/ahk/src/modeswitch.ahk | 4 ++-- README.md | 6 +++++- popnController/POPNHID.cpp | 11 ++++++++--- popnController/POPNHID.h | 11 +++++++++-- popnController/popnController.ino | 25 ++++++++++++++++--------- 6 files changed, 45 insertions(+), 22 deletions(-) diff --git a/ModeSwitch/C/src/modeswitch.cpp b/ModeSwitch/C/src/modeswitch.cpp index f03caad..ee04ff5 100644 --- a/ModeSwitch/C/src/modeswitch.cpp +++ b/ModeSwitch/C/src/modeswitch.cpp @@ -1,6 +1,3 @@ -/* TO BE COMPILED WITH MINGW */ -/* Visual C++ compilation didn't work for me on the BemaniPC (invalid win32 application) */ -#define WINVER 0x0500 #include #include @@ -68,7 +65,7 @@ int main(int argc, char* argv[]) } mode = atoi(argv[1]); - if ( mode < 0 || mode > 3 ) + if ( mode < 0 || mode > 4 ) { printf("Invalid mode value %d\r\n", mode); return 2; @@ -103,7 +100,10 @@ int main(int argc, char* argv[]) printf("(mixed)\r\n"); break; case 3: - printf("(invert)\r\n"); + printf("(combined)\r\n"); + break; + case 4: + printf("(combined invert)\r\n"); } } else diff --git a/ModeSwitch/ahk/src/modeswitch.ahk b/ModeSwitch/ahk/src/modeswitch.ahk index af1017d..118bcf0 100644 --- a/ModeSwitch/ahk/src/modeswitch.ahk +++ b/ModeSwitch/ahk/src/modeswitch.ahk @@ -15,7 +15,7 @@ if 0 < 1 ; The left side of a non-expression if-statement is always the name of param := %A_Index% mode := %param% + 16 -if (mode > 19) or (mode < 16){ +if (mode > 21) or (mode < 16){ MsgBox, Incorrect value %mode% ExitApp } @@ -92,4 +92,4 @@ return BytesActuallyWritten HID_Close(handle){ DllCall("CloseHandle", Ptr, handle) ; Close the file. -} \ No newline at end of file +} diff --git a/README.md b/README.md index 78efa9b..e49e9da 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ This way the firmware is fully compatible with anything that works on an officia ## Light modes -There are 4 different modes : +There are 5 different modes : ### Reactive mode @@ -72,6 +72,10 @@ This is the original IO board mode where only messages from the game can control ### Mixed mode (default mode) +This mode behaves like HID mode as soon as messages are received. If 3 seconds elapse without any received message, the firmware switches to reactive behavior (and will switch back to HID as soon as new HID messages are received). + +### Combined mode + This combines the HID messages with button presses for instant lighting (you don't have to wait for the game to register the input and send a message back to light the lamp, and as a bonus it also allows you to play with the lights while the cabinet is booting ;) ). ### Invert mode diff --git a/popnController/POPNHID.cpp b/popnController/POPNHID.cpp index 5b855fc..06ac5bb 100644 --- a/popnController/POPNHID.cpp +++ b/popnController/POPNHID.cpp @@ -286,6 +286,7 @@ static const byte PROGMEM _hidReportPOPN[] = { if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE) { if (request == HID_SET_REPORT) { if(setup.wValueH == HID_REPORT_TYPE_OUTPUT && setup.wLength == 5){ + lastHidUpdate = millis(); USB_RecvControl(led_data, 5); return true; } @@ -309,9 +310,13 @@ static const byte PROGMEM _hidReportPOPN[] = { uint8_t POPNHID_::getLightMode(){ return lightMode; } - + + unsigned long POPNHID_::getLastHidUpdate(){ + return lastHidUpdate; + } + void POPNHID_::setLightMode(uint8_t mode){ - if ((mode > 3) || (mode < 0)) { + if ((mode > 4) || (mode < 0)) { lightMode = 2; return; } @@ -355,4 +360,4 @@ static const byte PROGMEM _hidReportPOPN[] = { data[1] = (uint8_t) (buttonsState & 0xFF); data[2] = (uint8_t) (buttonsState >> 8) & 0xFF; return USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, 3); - } + } diff --git a/popnController/POPNHID.h b/popnController/POPNHID.h index e9f8bea..29a2443 100644 --- a/popnController/POPNHID.h +++ b/popnController/POPNHID.h @@ -53,9 +53,16 @@ class POPNHID_ : public PluggableUSBModule { uint8_t getLightMode(); void setLightMode(uint8_t mode); + /** + * getter for lastHidUpdate protected field. + */ + unsigned long getLastHidUpdate(); + protected: - /* current lightMode (0 = reactive, 1 = HID only, 2 = mixed (HID+button presses), 3 = mixed invert) */ + /* current lightMode (0 = reactive, 1 = HID only, 2 = mixed (HID+reactive auto-switch), 3 = combined (HID+button presses), 4 = combined invert) */ uint8_t lightMode = 2; + /* timestamp of last received HID report for lightMode 3 */ + unsigned long lastHidUpdate = 0; /* byte array to receive HID reports from the PC */ byte led_data[5]; @@ -69,4 +76,4 @@ class POPNHID_ : public PluggableUSBModule { uint8_t getShortName(char *name); }; -extern POPNHID_ POPNHID; +extern POPNHID_ POPNHID; diff --git a/popnController/popnController.ino b/popnController/popnController.ino index bf1a1cd..ee7308c 100644 --- a/popnController/popnController.ino +++ b/popnController/popnController.ino @@ -129,7 +129,15 @@ void loop() { } /* LAMPS */ - switch (POPNHID.getLightMode()) + uint8_t mode = POPNHID.getLightMode(); + /* mixed mode will behave sometimes like HID, sometimes like reactive */ + if (mode == 2){ + if ((millis()-POPNHID.getLastHidUpdate()) > 3000) + mode = 0; + else + mode = 1; + } + switch (mode) { /* Reactive mode, locally determined lamp data */ case 0: @@ -142,14 +150,16 @@ void loop() { case 1: POPNHID.updateLeds(0, false); break; - /* Mixed inverse mode, received HID data and button state are combined then inverted */ - case 3: + /* Combined inverse mode, received HID data and button state are combined then inverted */ + case 4: POPNHID.updateLeds(buttonsState & 0x1ff, true); break; - /* Mixed mode, received HID data and button state are combined */ - default: + /* Combined mode, received HID data and button state are combined */ + case 3: POPNHID.updateLeds(buttonsState & 0x1ff, false); break; + default: + break; } #if defined(ARDUINO_ARCH_SAM) @@ -184,7 +194,7 @@ void loop() { if ( (buttonsState & 2) && (modeChanged == false)) { modeChanged = true; uint8_t mode = POPNHID.getLightMode()+1; - if (mode > 3) mode = 0; + if (mode > 4) mode = 0; POPNHID.setLightMode(mode); #if defined(ARDUINO_ARCH_AVR) EEPROM.put(0, mode); @@ -319,6 +329,3 @@ if (pillar_lit) neon_lights(neons); } #endif - - -