Looks like I forgot to add my changes?
Mockband / build (push) Failing after 11s Details

This commit is contained in:
Neale Pickett 2024-01-10 08:46:38 -07:00
parent 8ccbaaa4b7
commit ed8d884054
1 changed files with 28 additions and 24 deletions

View File

@ -2,11 +2,11 @@
#include <Arduino.h> #include <Arduino.h>
#include <PluggableUSB.h> #include <PluggableUSB.h>
//#define DEBUG #define DEBUG
#include "hid.hh" // Modified HID library: doesn't prefix each packet with ID #include "hid.hh" // Modified HID library: doesn't prefix each packet with ID
#include "instrument.hh" #include "instrument.hh"
#include "standard.hh" // Standard pins #include "piezos.hh"
// If defined, we will check the wammy bar input // If defined, we will check the wammy bar input
//#define WAMMY //#define WAMMY
@ -41,23 +41,17 @@
InstrumentButtonState buttonState = {0}; InstrumentButtonState buttonState = {0};
void setup() { void setup() {
pinMode(STRUM_DOWN, INPUT_PULLUP); pinMode(BUTTON_GREEN, INPUT);
pinMode(STRUM_UP, INPUT_PULLUP); pinMode(BUTTON_RED, INPUT);
pinMode(TILT_SWITCH, INPUT_PULLUP); pinMode(BUTTON_YELLOW, INPUT);
pinMode(BUTTON_GREEN, INPUT_PULLUP); pinMode(BUTTON_BLUE, INPUT);
pinMode(BUTTON_RED, INPUT_PULLUP);
pinMode(BUTTON_YELLOW, INPUT_PULLUP);
pinMode(BUTTON_BLUE, INPUT_PULLUP);
pinMode(BUTTON_ORANGE, INPUT_PULLUP); pinMode(BUTTON_ORANGE, INPUT_PULLUP);
pinMode(SOLO_GREEN, INPUT_PULLUP); pinMode(SOLO_GREEN, INPUT);
pinMode(SOLO_RED, INPUT_PULLUP); pinMode(SOLO_RED, INPUT);
pinMode(SOLO_YELLOW, INPUT_PULLUP); pinMode(SOLO_YELLOW, INPUT);
pinMode(SOLO_BLUE, INPUT_PULLUP); pinMode(SOLO_BLUE, INPUT);
pinMode(SOLO_ORANGE, INPUT_PULLUP);
pinMode(BUTTON_PLUS, INPUT_PULLUP); pinMode(BUTTON_PLUS, INPUT_PULLUP);
pinMode(BUTTON_MINUS, INPUT_PULLUP); pinMode(BUTTON_MINUS, INPUT_PULLUP);
pinMode(ANALOG_WAMMY, INPUT);
pinMode(ANALOG_DPAD, INPUT);
// Initialize HID // Initialize HID
static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor)); static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor));
@ -86,10 +80,13 @@ uint8_t pins[] = {
}; };
#define npins (sizeof(pins) / sizeof(*pins)) #define npins (sizeof(pins) / sizeof(*pins))
#define NOISE_THRESHOLD 40 // Minimum analog value to treat as a hit
// The 3.3v Pro Micro is on the slow side. // The 3.3v Pro Micro is on the slow side.
// Our strategy is to poll button state as quickly as possible, // Our strategy is to poll button state as quickly as possible,
// and hope we don't miss anything while we're doing USB stuff. // and hope we don't miss anything while we're doing USB stuff.
void loop() { void loop() {
uint16_t inputs[16] = {0};
uint16_t buttons = 0; uint16_t buttons = 0;
uint16_t samples = 0; uint16_t samples = 0;
unsigned long next = 0; unsigned long next = 0;
@ -99,13 +96,20 @@ void loop() {
uint16_t edge = 0; uint16_t edge = 0;
samples++; samples++;
inputs[0] = analogRead(INPUT_BLUE);
inputs[1] = analogRead(INPUT_GREEN);
inputs[2] = analogRead(INPUT_RED);
inputs[3] = analogRead(INPUT_YELLOW);
for (uint8_t i = 0; i < npins; i++) { for (uint8_t i = 0; i < 4; i++) {
if (silence[i]) { if (silence[i]) {
silence[i]--; silence[i]--;
} else if (bitRead(buttons, i) != !digitalRead(pins[i])) { } else {
edge |= bit(i); bool trigger = inputs[i] > NOISE_THRESHOLD;
silence[i] = SILENCE_SAMPLES; if (trigger != bitRead(buttons, i)) {
edge |= bit(i);
silence[i] = SILENCE_SAMPLES;
}
} }
} }
buttons ^= edge; buttons ^= edge;
@ -147,10 +151,10 @@ void loop() {
buttonState.axis[3] = bitRead(buttons, 12)?255:0; // High hat buttonState.axis[3] = bitRead(buttons, 12)?255:0; // High hat
// rbdrum2midi wants these set // rbdrum2midi wants these set
buttonState.velocity[0] = bitRead(buttonState.buttons, 3)?127:0; // Y buttonState.velocity[0] = inputs[3]/4; // Y
buttonState.velocity[1] = bitRead(buttonState.buttons, 2)?127:0; // R buttonState.velocity[1] = inputs[2]/4; // R
buttonState.velocity[2] = bitRead(buttonState.buttons, 1)?127:0; // G buttonState.velocity[2] = inputs[1]/2; // G
buttonState.velocity[3] = bitRead(buttonState.buttons, 0)?127:0; // B buttonState.velocity[3] = inputs[0]/4; // B
// Say the D-pad is centered // Say the D-pad is centered
buttonState.hatAndConstant = 8; buttonState.hatAndConstant = 8;