Fix strum buttons, isolate guitar & drum buttons.

This commit is contained in:
Neale Pickett 2024-01-01 22:04:56 -07:00
parent 84652514ee
commit c40e7ff970
1 changed files with 14 additions and 12 deletions

View File

@ -2,16 +2,15 @@
#include <Arduino.h>
#include <PluggableUSB.h>
#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