Working, updating occasionally
This commit is contained in:
parent
b0a2a94923
commit
deec112aee
|
@ -9,6 +9,7 @@
|
||||||
#include "standard.h" // Standard pins
|
#include "standard.h" // Standard pins
|
||||||
|
|
||||||
InstrumentButtonState buttonState;
|
InstrumentButtonState buttonState;
|
||||||
|
InstrumentButtonState lastState;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(STRUM_DOWN, INPUT_PULLUP);
|
pinMode(STRUM_DOWN, INPUT_PULLUP);
|
||||||
|
@ -47,39 +48,59 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
static unsigned long next = 0;
|
static uint16_t buttons = 0;
|
||||||
unsigned long now = millis();
|
static uint16_t last_buttons = 0;
|
||||||
|
|
||||||
// Send a state update right away;
|
buttons = (0
|
||||||
if (now >= next) {
|
| (digitalRead(BUTTON_BLUE) << 0)
|
||||||
buttonState.axis[2] = analogRead(ANALOG_WAMMY) / 4;
|
| (digitalRead(BUTTON_GREEN) << 1)
|
||||||
HID().SendReport(0, (uint8_t *)&buttonState, 27);
|
| (digitalRead(BUTTON_RED) << 2)
|
||||||
|
| (digitalRead(BUTTON_YELLOW) << 3)
|
||||||
buttonState.buttons = 0; // reset
|
| (digitalRead(BUTTON_ORANGE) << 4)
|
||||||
buttonState.hatAndConstant = 0x08; // reset
|
| (digitalRead(TILT_SWITCH) << 5)
|
||||||
next = now + 10; // wait 10ms before sending another status update
|
| (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;
|
||||||
}
|
}
|
||||||
|
last_buttons = buttons;
|
||||||
|
|
||||||
// Poll buttons
|
// open switch will read 1, so invert everything
|
||||||
if (!digitalRead(BUTTON_BLUE) || !digitalRead(SOLO_BLUE)) bitSet(buttonState.buttons, 0);
|
buttons = ~buttons;
|
||||||
if (!digitalRead(BUTTON_GREEN) || !digitalRead(SOLO_GREEN)) bitSet(buttonState.buttons, 1);
|
|
||||||
if (!digitalRead(BUTTON_RED) || !digitalRead(SOLO_RED)) bitSet(buttonState.buttons, 2);
|
buttonState.buttons = (buttons & 0b1100111111); // All directly-mappable bits
|
||||||
if (!digitalRead(BUTTON_YELLOW) || !digitalRead(SOLO_YELLOW)) bitSet(buttonState.buttons, 3);
|
buttonState.buttons |= ((buttons >> 10) & 0b11111); // Solo keys
|
||||||
if (!digitalRead(BUTTON_ORANGE) || !digitalRead(SOLO_ORANGE)) bitSet(buttonState.buttons, 4);
|
bitWrite(buttonState.buttons, 6, (buttons >> 10) & 0b11111); // Solo bit
|
||||||
if (!digitalRead(TILT_SWITCH)) bitSet(buttonState.buttons, 5);
|
|
||||||
if (!digitalRead(SOLO_BLUE) || !digitalRead(SOLO_GREEN) || !digitalRead(SOLO_RED) || !digitalRead(SOLO_YELLOW) || !digitalRead(SOLO_ORANGE)) bitSet(buttonState.buttons, 6);
|
|
||||||
if (!digitalRead(BUTTON_MINUS)) bitSet(buttonState.buttons, 8);
|
|
||||||
if (!digitalRead(BUTTON_PLUS)) bitSet(buttonState.buttons, 9);
|
|
||||||
|
|
||||||
// Poll direction
|
|
||||||
// I don't understand why any rational engineer would have done this.
|
// I don't understand why any rational engineer would have done this.
|
||||||
if (!digitalRead(STRUM_UP)) {
|
if (bitRead(buttons, 6)) {
|
||||||
buttonState.hatAndConstant = 0x00; // up
|
buttonState.hatAndConstant = 0x00; // up
|
||||||
} else if (false) {
|
} else if (false) {
|
||||||
buttonState.hatAndConstant = 0x02; // right
|
buttonState.hatAndConstant = 0x02; // right
|
||||||
} else if (!digitalRead(STRUM_DOWN)) {
|
} else if (bitRead(buttons, 7)) {
|
||||||
buttonState.hatAndConstant = 0x04; // down
|
buttonState.hatAndConstant = 0x04; // down
|
||||||
} else if (false) {
|
} else if (false) {
|
||||||
buttonState.hatAndConstant = 0x06; // left
|
buttonState.hatAndConstant = 0x06; // left
|
||||||
|
} else {
|
||||||
|
buttonState.hatAndConstant = 0x08; // nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// don't report more frequently than 1kHz
|
||||||
|
// this doubles as debouncing logic
|
||||||
|
delay(10);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue