From c40e7ff970035d92b08f7a37773772a99f1fe13e Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Mon, 1 Jan 2024 22:04:56 -0700 Subject: [PATCH] Fix strum buttons, isolate guitar & drum buttons. --- MockBand.ino | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/MockBand.ino b/MockBand.ino index 74125a1..927ff12 100644 --- a/MockBand.ino +++ b/MockBand.ino @@ -2,16 +2,15 @@ #include #include -#define DEBUG +//#define DEBUG #include "hid.hh" // Modified HID library: doesn't prefix each packet with ID #include "instrument.hh" - //#include "blue.hh" // Ginnie's blue guitar #include "standard.hh" // Standard pins // If defined, we will check the wammy bar input -#define WAMMY +//#define WAMMY // Maximum time between wammy bar updates. #define UPDATE_INTERVAL_MS 20 @@ -126,28 +125,31 @@ void loop() { buttonState.buttons = (buttons & 0b1100111111); // +-..!OYRGB #ifdef GUITAR buttonState.buttons |= (buttons >> 10) & 0b11111; // Solo keys + bitWrite(buttonState.buttons, 6, buttons & (0b11111 << 10)); // Solo modifier #else // DRUMS buttonState.buttons |= (buttons >> 10) & 0b01011; // Cymbals -#endif - bitWrite(buttonState.buttons, 6, buttons & (0b11111 << 10)); // Solo modifier bitWrite(buttonState.buttons, 10, buttons & (0b01111 << 0)); // Drum pad modifier bitWrite(buttonState.buttons, 11, buttons & (0b01011 << 10)); // Cymbals modifier + buttonState.axis[3] = bitRead(buttons, 12)?255:0; // High hat +#endif // D-pad would go here if I ever implemented that: // nothing seems to actualy need it. // // I don't understand why any rational engineer would have specified this algorithm. - buttonState.hatAndConstant = (0x08 - ^ (bitRead(buttons, 6) << 4) // strum up - // right << 3 - ^ (bitRead(buttons, 7) << 2) // strum down - // left << 1 - ); + if (bitRead(buttons, 6)) { + buttonState.hatAndConstant = 0x00; // up + } else if bitRead(buttons, 7) { // + buttonState.hatAndConstant = 0x04; // down + } else { + buttonState.hatAndConstant = 0x08; // nothing + } + // left: 0x06 + // right: 0x02 #ifdef WAMMY buttonState.axis[2] = analogRead(ANALOG_WAMMY) / 4; // Wammy bar #endif - buttonState.axis[3] = bitRead(buttons, 12)?255:0; // High hat #ifdef DEBUG