parent
3e059d0fb1
commit
8bcb905028
44
MockBand.ino
44
MockBand.ino
|
@ -6,7 +6,6 @@
|
|||
|
||||
#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
|
||||
|
@ -26,18 +25,20 @@
|
|||
#define SILENCE_SAMPLES (SAMPLES_PER_MS * SILENCE_INTERVAL_MS)
|
||||
|
||||
#if USB_VID != 0x1bad
|
||||
#error USB_VID must be set to 0x1bad
|
||||
#error USB_VID must be set to 0x1bad: see INSTALL.md
|
||||
#endif
|
||||
|
||||
#if USB_PID == 0x0004
|
||||
#define GUITAR
|
||||
#elif USB_PID == 0x0005
|
||||
#define DRUM
|
||||
#define DRUM // Wii RB1
|
||||
#elif USB_PID == 0x3110
|
||||
#define DRUM // Wii RB2
|
||||
#else
|
||||
#error USB_PID must be set to 4 (Guitar) or 5 (Drum)
|
||||
#error USB_PID not recognized: see INSTALL.md
|
||||
#endif
|
||||
|
||||
InstrumentButtonState buttonState;
|
||||
InstrumentButtonState buttonState = {0};
|
||||
|
||||
void setup() {
|
||||
pinMode(STRUM_DOWN, INPUT_PULLUP);
|
||||
|
@ -53,21 +54,15 @@ void setup() {
|
|||
pinMode(SOLO_YELLOW, INPUT_PULLUP);
|
||||
pinMode(SOLO_BLUE, INPUT_PULLUP);
|
||||
pinMode(SOLO_ORANGE, INPUT_PULLUP);
|
||||
pinMode(ANALOG_WAMMY, INPUT);
|
||||
pinMode(BUTTON_PLUS, INPUT_PULLUP);
|
||||
pinMode(BUTTON_MINUS, INPUT_PULLUP);
|
||||
pinMode(ANALOG_WAMMY, INPUT);
|
||||
pinMode(ANALOG_DPAD, INPUT);
|
||||
|
||||
// Initialize HID
|
||||
static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor));
|
||||
HID().AppendDescriptor(&node);
|
||||
|
||||
buttonState.axis[0] = 0;
|
||||
buttonState.axis[1] = 0;
|
||||
buttonState.axis[2] = 0;
|
||||
buttonState.axis[3] = 0;
|
||||
for (int i = 0; i < 12; i++) {
|
||||
buttonState.reserved1[i] = 0x0;
|
||||
}
|
||||
buttonState.finalConstant = 0x0200020002000200;
|
||||
}
|
||||
|
||||
|
@ -101,7 +96,9 @@ void loop() {
|
|||
uint16_t silence[npins] = {0};
|
||||
|
||||
while (1) {
|
||||
#ifdef WAMMY
|
||||
unsigned long now = millis();
|
||||
#endif
|
||||
uint16_t edge = 0;
|
||||
|
||||
samples++;
|
||||
|
@ -117,10 +114,17 @@ void loop() {
|
|||
buttons ^= edge;
|
||||
|
||||
// We've sampled everything. Is it time to do calculations and USB?
|
||||
#ifdef WAMMY
|
||||
if (!edge && (next > now)) {
|
||||
continue;
|
||||
}
|
||||
next = now + UPDATE_INTERVAL_MS;
|
||||
buttonState.axis[2] = analogRead(ANALOG_WAMMY) / 4; // Wammy bar
|
||||
#else
|
||||
if (!edge) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// Calculate and send an HID update
|
||||
|
@ -144,6 +148,12 @@ void loop() {
|
|||
bitWrite(buttonState.buttons, 11, buttons & (0b01011 << 10)); // Cymbals modifier
|
||||
buttonState.axis[3] = bitRead(buttons, 12)?255:0; // High hat
|
||||
|
||||
// rbdrum2midi wants these set
|
||||
buttonState.velocity[0] = bitRead(buttonState.buttons, 3)?127:0; // Y
|
||||
buttonState.velocity[1] = bitRead(buttonState.buttons, 2)?127:0; // R
|
||||
buttonState.velocity[2] = bitRead(buttonState.buttons, 1)?127:0; // G
|
||||
buttonState.velocity[3] = bitRead(buttonState.buttons, 0)?127:0; // B
|
||||
|
||||
// Use the cymbals for up and down, since I don't have a D-pad
|
||||
if bitRead(buttons, 13) {
|
||||
buttonState.hatAndConstant = 0; // up
|
||||
|
@ -154,14 +164,10 @@ void loop() {
|
|||
}
|
||||
#endif
|
||||
|
||||
// D-pad would go here if I ever implemented that:
|
||||
// nothing seems to actualy need it.
|
||||
|
||||
#ifdef WAMMY
|
||||
buttonState.axis[2] = analogRead(ANALOG_WAMMY) / 4; // Wammy bar
|
||||
#ifdef DPAD
|
||||
#error DPAD isn't implemented yet
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
// Log sample rate to the first X axis
|
||||
buttonState.axis[0] = samples & 0xff;
|
||||
|
|
13
blue.hh
13
blue.hh
|
@ -1,13 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
const int STRUM_DOWN = 8;
|
||||
const int STRUM_UP = 9;
|
||||
const int TILT_SWITCH = 2;
|
||||
const int BUTTON_GREEN = 3;
|
||||
const int BUTTON_RED = 4;
|
||||
const int BUTTON_YELLOW = 5;
|
||||
const int BUTTON_BLUE = 6;
|
||||
const int BUTTON_ORANGE = 7;
|
||||
const int BUTTON_PLUS = 13;
|
||||
const int BUTTON_MINUS = 12;
|
||||
const int ANALOG_WAMMY = 19;
|
|
@ -73,6 +73,8 @@ typedef struct {
|
|||
uint16_t buttons; // 2
|
||||
uint8_t hatAndConstant; // 1
|
||||
uint8_t axis[4]; // 4
|
||||
uint8_t reserved1[12]; // 12
|
||||
uint8_t reserved1[4]; // Not sure what this is
|
||||
uint8_t velocity[4]; // Y, R, G, B
|
||||
uint8_t reserved2[4]; // Not sure what this is, either
|
||||
uint64_t finalConstant; // 8
|
||||
} InstrumentButtonState;
|
||||
|
|
|
@ -33,7 +33,9 @@ const int SOLO_YELLOW = 18;
|
|||
const int SOLO_BLUE = 15;
|
||||
const int SOLO_ORANGE = 14;
|
||||
|
||||
const int ANALOG_WAMMY = 9;
|
||||
|
||||
const int BUTTON_PLUS = 10;
|
||||
const int BUTTON_MINUS = 16;
|
||||
|
||||
const int ANALOG_WAMMY = 9;
|
||||
const int ANALOG_DPAD = 21;
|
Loading…
Reference in New Issue