2023-04-22 16:15:03 -06:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <Arduino.h>
|
2023-12-31 16:19:10 -07:00
|
|
|
#include <PluggableUSB.h>
|
2023-04-22 16:15:03 -06:00
|
|
|
|
2023-12-31 16:19:10 -07:00
|
|
|
#include "hid.h" // Modified HID library: doesn't prefix each packet with ID
|
|
|
|
#include "instrument.h"
|
2023-04-22 16:15:03 -06:00
|
|
|
|
2023-12-31 16:19:10 -07:00
|
|
|
//#include "blue.h" // Ginnie's blue guitar
|
|
|
|
#include "standard.h" // Standard pins
|
2023-04-22 16:15:03 -06:00
|
|
|
|
|
|
|
InstrumentButtonState buttonState;
|
2023-12-31 16:44:08 -07:00
|
|
|
InstrumentButtonState lastState;
|
2023-04-22 16:15:03 -06:00
|
|
|
|
|
|
|
void setup() {
|
2023-05-15 18:49:22 -06:00
|
|
|
pinMode(STRUM_DOWN, INPUT_PULLUP);
|
|
|
|
pinMode(STRUM_UP, INPUT_PULLUP);
|
|
|
|
pinMode(TILT_SWITCH, INPUT_PULLUP);
|
|
|
|
pinMode(BUTTON_GREEN, INPUT_PULLUP);
|
|
|
|
pinMode(BUTTON_RED, INPUT_PULLUP);
|
|
|
|
pinMode(BUTTON_YELLOW, INPUT_PULLUP);
|
|
|
|
pinMode(BUTTON_BLUE, INPUT_PULLUP);
|
|
|
|
pinMode(BUTTON_ORANGE, INPUT_PULLUP);
|
2023-12-31 16:19:10 -07:00
|
|
|
pinMode(SOLO_GREEN, INPUT_PULLUP);
|
|
|
|
pinMode(SOLO_RED, INPUT_PULLUP);
|
|
|
|
pinMode(SOLO_YELLOW, INPUT_PULLUP);
|
|
|
|
pinMode(SOLO_BLUE, INPUT_PULLUP);
|
|
|
|
pinMode(SOLO_ORANGE, INPUT_PULLUP);
|
|
|
|
pinMode(ANALOG_WAMMY, INPUT);
|
2023-05-15 18:49:22 -06:00
|
|
|
pinMode(BUTTON_PLUS, INPUT_PULLUP);
|
|
|
|
pinMode(BUTTON_MINUS, INPUT_PULLUP);
|
2023-12-31 16:19:10 -07:00
|
|
|
|
|
|
|
// Initialize HID
|
|
|
|
static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor));
|
|
|
|
HID().AppendDescriptor(&node);
|
|
|
|
|
2023-04-22 16:15:03 -06:00
|
|
|
buttonState.buttons = 0x0000;
|
|
|
|
buttonState.hatAndConstant = 0x08;
|
2023-05-15 18:49:22 -06:00
|
|
|
buttonState.axis[0] = 0;
|
|
|
|
buttonState.axis[1] = 0;
|
|
|
|
buttonState.axis[2] = 0;
|
|
|
|
buttonState.axis[3] = 0;
|
2023-12-31 16:19:10 -07:00
|
|
|
for (int i = 0; i < 12; i++) {
|
2023-04-22 16:15:03 -06:00
|
|
|
buttonState.reserved1[i] = 0x0;
|
|
|
|
}
|
|
|
|
buttonState.finalConstant = 0x0200020002000200;
|
2023-12-31 16:19:10 -07:00
|
|
|
buttonState.buttons = 0;
|
|
|
|
buttonState.hatAndConstant = 0x08; // This apparently means "nothing pressed"
|
2023-04-22 16:15:03 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
2023-12-31 16:44:08 -07:00
|
|
|
static uint16_t buttons = 0;
|
|
|
|
static uint16_t last_buttons = 0;
|
2023-12-31 16:19:10 -07:00
|
|
|
|
2023-12-31 16:44:08 -07:00
|
|
|
buttons = (0
|
|
|
|
| (digitalRead(BUTTON_BLUE) << 0)
|
|
|
|
| (digitalRead(BUTTON_GREEN) << 1)
|
|
|
|
| (digitalRead(BUTTON_RED) << 2)
|
|
|
|
| (digitalRead(BUTTON_YELLOW) << 3)
|
|
|
|
| (digitalRead(BUTTON_ORANGE) << 4)
|
|
|
|
| (digitalRead(TILT_SWITCH) << 5)
|
|
|
|
| (digitalRead(STRUM_UP) << 6) // Not in USB packet
|
|
|
|
| (digitalRead(STRUM_DOWN) << 7) // Not in USB packet
|
|
|
|
| (digitalRead(BUTTON_MINUS) << 8)
|
|
|
|
| (digitalRead(BUTTON_PLUS) << 9)
|
|
|
|
| (digitalRead(SOLO_BLUE) << 10) // Not in USB packet
|
|
|
|
| (digitalRead(SOLO_GREEN) << 11) // Not in USB packet
|
|
|
|
| (digitalRead(SOLO_RED) << 12) // Not in USB packet
|
|
|
|
| (digitalRead(SOLO_YELLOW) << 13) // Not in USB packet
|
|
|
|
| (digitalRead(SOLO_ORANGE) << 14) // Not in USB packet
|
|
|
|
);
|
|
|
|
|
|
|
|
if (buttons == last_buttons) {
|
|
|
|
return;
|
2023-04-22 16:15:03 -06:00
|
|
|
}
|
2023-12-31 16:44:08 -07:00
|
|
|
last_buttons = buttons;
|
|
|
|
|
|
|
|
// open switch will read 1, so invert everything
|
|
|
|
buttons = ~buttons;
|
2023-05-15 18:49:22 -06:00
|
|
|
|
2023-12-31 16:44:08 -07:00
|
|
|
buttonState.buttons = (buttons & 0b1100111111); // All directly-mappable bits
|
|
|
|
buttonState.buttons |= ((buttons >> 10) & 0b11111); // Solo keys
|
|
|
|
bitWrite(buttonState.buttons, 6, (buttons >> 10) & 0b11111); // Solo bit
|
2023-12-31 16:19:10 -07:00
|
|
|
|
|
|
|
// I don't understand why any rational engineer would have done this.
|
2023-12-31 16:44:08 -07:00
|
|
|
if (bitRead(buttons, 6)) {
|
2023-12-31 16:19:10 -07:00
|
|
|
buttonState.hatAndConstant = 0x00; // up
|
|
|
|
} else if (false) {
|
|
|
|
buttonState.hatAndConstant = 0x02; // right
|
2023-12-31 16:44:08 -07:00
|
|
|
} else if (bitRead(buttons, 7)) {
|
2023-12-31 16:19:10 -07:00
|
|
|
buttonState.hatAndConstant = 0x04; // down
|
|
|
|
} else if (false) {
|
|
|
|
buttonState.hatAndConstant = 0x06; // left
|
2023-12-31 16:44:08 -07:00
|
|
|
} else {
|
|
|
|
buttonState.hatAndConstant = 0x08; // nothing
|
2023-12-31 16:19:10 -07:00
|
|
|
}
|
2023-12-31 16:44:08 -07:00
|
|
|
|
|
|
|
// I'm not implementing this for the time being
|
|
|
|
//buttonState.axis[2] = analogRead(ANALOG_WAMMY) / 4;
|
|
|
|
|
|
|
|
// Send an update
|
|
|
|
HID().SendReport(0, (uint8_t *)&buttonState, 27);
|
|
|
|
|
2023-12-31 16:44:34 -07:00
|
|
|
// don't report more frequently than 100Hz
|
2023-12-31 16:44:08 -07:00
|
|
|
// this doubles as debouncing logic
|
|
|
|
delay(10);
|
2023-04-22 16:15:03 -06:00
|
|
|
}
|