Feels good, but switches bounce
This commit is contained in:
parent
0960b0e2f7
commit
d5b1addddc
|
@ -33,8 +33,6 @@ void setup() {
|
||||||
static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor));
|
static HIDSubDescriptor node(_hidReportDescriptor, sizeof(_hidReportDescriptor));
|
||||||
HID().AppendDescriptor(&node);
|
HID().AppendDescriptor(&node);
|
||||||
|
|
||||||
buttonState.buttons = 0x0000;
|
|
||||||
buttonState.hatAndConstant = 0x08;
|
|
||||||
buttonState.axis[0] = 0;
|
buttonState.axis[0] = 0;
|
||||||
buttonState.axis[1] = 0;
|
buttonState.axis[1] = 0;
|
||||||
buttonState.axis[2] = 0;
|
buttonState.axis[2] = 0;
|
||||||
|
@ -43,8 +41,6 @@ void setup() {
|
||||||
buttonState.reserved1[i] = 0x0;
|
buttonState.reserved1[i] = 0x0;
|
||||||
}
|
}
|
||||||
buttonState.finalConstant = 0x0200020002000200;
|
buttonState.finalConstant = 0x0200020002000200;
|
||||||
buttonState.buttons = 0;
|
|
||||||
buttonState.hatAndConstant = 0x08; // This apparently means "nothing pressed"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// The 3.3v Pro Micro is on the slow side.
|
// The 3.3v Pro Micro is on the slow side.
|
||||||
|
@ -52,57 +48,58 @@ void setup() {
|
||||||
// send an update every 10ms,
|
// send an update every 10ms,
|
||||||
// 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() {
|
||||||
static uint16_t buttons = 0;
|
register uint16_t buttons = 0;
|
||||||
static unsigned long next = 0;
|
register uint16_t buttons_prior = 0;
|
||||||
unsigned long now = millis();
|
|
||||||
|
|
||||||
buttons |= (0
|
while (1) {
|
||||||
| (digitalRead(BUTTON_BLUE) << 0)
|
buttons = (0
|
||||||
| (digitalRead(BUTTON_GREEN) << 1)
|
| (digitalRead(BUTTON_BLUE) << 0)
|
||||||
| (digitalRead(BUTTON_RED) << 2)
|
| (digitalRead(BUTTON_GREEN) << 1)
|
||||||
| (digitalRead(BUTTON_YELLOW) << 3)
|
| (digitalRead(BUTTON_RED) << 2)
|
||||||
| (digitalRead(BUTTON_ORANGE) << 4)
|
| (digitalRead(BUTTON_YELLOW) << 3)
|
||||||
| (digitalRead(TILT_SWITCH) << 5)
|
| (digitalRead(BUTTON_ORANGE) << 4)
|
||||||
| (digitalRead(STRUM_UP) << 6) // Not in USB packet
|
| (digitalRead(TILT_SWITCH) << 5)
|
||||||
| (digitalRead(STRUM_DOWN) << 7) // Not in USB packet
|
| (digitalRead(STRUM_UP) << 6) // Not in USB packet
|
||||||
| (digitalRead(BUTTON_MINUS) << 8)
|
| (digitalRead(STRUM_DOWN) << 7) // Not in USB packet
|
||||||
| (digitalRead(BUTTON_PLUS) << 9)
|
| (digitalRead(BUTTON_MINUS) << 8)
|
||||||
| (digitalRead(SOLO_BLUE) << 10) // Not in USB packet
|
| (digitalRead(BUTTON_PLUS) << 9)
|
||||||
| (digitalRead(SOLO_GREEN) << 11) // Not in USB packet
|
| (digitalRead(SOLO_BLUE) << 10) // Not in USB packet
|
||||||
| (digitalRead(SOLO_RED) << 12) // Not in USB packet
|
| (digitalRead(SOLO_GREEN) << 11) // Not in USB packet
|
||||||
| (digitalRead(SOLO_YELLOW) << 13) // Not in USB packet
|
| (digitalRead(SOLO_RED) << 12) // Not in USB packet
|
||||||
| (digitalRead(SOLO_ORANGE) << 14) // Not in USB packet
|
| (digitalRead(SOLO_YELLOW) << 13) // Not in USB packet
|
||||||
);
|
| (digitalRead(SOLO_ORANGE) << 14) // Not in USB packet
|
||||||
|
);
|
||||||
|
|
||||||
if (next > now) {
|
if (buttons == buttons_prior) {
|
||||||
return;
|
continue;
|
||||||
|
}
|
||||||
|
buttons_prior = buttons;
|
||||||
|
|
||||||
|
// Open pullup reads 1, so invert everything we've read
|
||||||
|
buttons = ~buttons;
|
||||||
|
|
||||||
|
buttonState.buttons = (buttons & 0b1100111111); // All directly-mappable bits
|
||||||
|
buttonState.buttons |= ((buttons >> 10) & 0b11111); // Solo keys
|
||||||
|
bitWrite(buttonState.buttons, 6, (buttons >> 10) & 0b11111); // Solo bit
|
||||||
|
|
||||||
|
// I don't understand why any rational engineer would have done this.
|
||||||
|
if (bitRead(buttons, 6)) {
|
||||||
|
buttonState.hatAndConstant = 0x00; // up
|
||||||
|
} else if (false) {
|
||||||
|
buttonState.hatAndConstant = 0x02; // right
|
||||||
|
} else if (bitRead(buttons, 7)) {
|
||||||
|
buttonState.hatAndConstant = 0x04; // down
|
||||||
|
} else if (false) {
|
||||||
|
buttonState.hatAndConstant = 0x06; // left
|
||||||
|
} else {
|
||||||
|
buttonState.hatAndConstant = 0x08; // nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonState.axis[2] = analogRead(ANALOG_WAMMY) / 4;
|
||||||
|
|
||||||
|
// Send an update
|
||||||
|
HID().SendReport(0, (uint8_t *)&buttonState, 27);
|
||||||
|
|
||||||
|
buttons = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open pullup reads 1, so invert everything we've read
|
|
||||||
buttons = ~buttons;
|
|
||||||
|
|
||||||
buttonState.buttons = (buttons & 0b1100111111); // All directly-mappable bits
|
|
||||||
buttonState.buttons |= ((buttons >> 10) & 0b11111); // Solo keys
|
|
||||||
bitWrite(buttonState.buttons, 6, (buttons >> 10) & 0b11111); // Solo bit
|
|
||||||
|
|
||||||
// I don't understand why any rational engineer would have done this.
|
|
||||||
if (bitRead(buttons, 6)) {
|
|
||||||
buttonState.hatAndConstant = 0x00; // up
|
|
||||||
} else if (false) {
|
|
||||||
buttonState.hatAndConstant = 0x02; // right
|
|
||||||
} else if (bitRead(buttons, 7)) {
|
|
||||||
buttonState.hatAndConstant = 0x04; // down
|
|
||||||
} else if (false) {
|
|
||||||
buttonState.hatAndConstant = 0x06; // left
|
|
||||||
} else {
|
|
||||||
buttonState.hatAndConstant = 0x08; // nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
buttonState.axis[2] = analogRead(ANALOG_WAMMY) / 4;
|
|
||||||
|
|
||||||
// Send an update
|
|
||||||
HID().SendReport(0, (uint8_t *)&buttonState, 27);
|
|
||||||
|
|
||||||
next = now + 10;
|
|
||||||
buttons = 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue