Another attempt

This commit is contained in:
Neale Pickett 2023-12-31 17:04:49 -07:00
parent a0a2b9dde5
commit 0960b0e2f7
1 changed files with 13 additions and 11 deletions

View File

@ -47,11 +47,16 @@ void setup() {
buttonState.hatAndConstant = 0x08; // This apparently means "nothing pressed" buttonState.hatAndConstant = 0x08; // This apparently means "nothing pressed"
} }
// The 3.3v Pro Micro is on the slow side.
// Our strategy is to poll button state as quickly as possible,
// send an update every 10ms,
// and hope we don't miss anything while we're doing USB stuff.
void loop() { void loop() {
static uint16_t buttons = 0; static uint16_t buttons = 0;
static uint16_t last_buttons = 0; static unsigned long next = 0;
unsigned long now = millis();
buttons = (0 buttons |= (0
| (digitalRead(BUTTON_BLUE) << 0) | (digitalRead(BUTTON_BLUE) << 0)
| (digitalRead(BUTTON_GREEN) << 1) | (digitalRead(BUTTON_GREEN) << 1)
| (digitalRead(BUTTON_RED) << 2) | (digitalRead(BUTTON_RED) << 2)
@ -69,12 +74,11 @@ void loop() {
| (digitalRead(SOLO_ORANGE) << 14) // Not in USB packet | (digitalRead(SOLO_ORANGE) << 14) // Not in USB packet
); );
if (buttons == last_buttons) { if (next > now) {
return; return;
} }
last_buttons = buttons;
// open switch will read 1, so invert everything // Open pullup reads 1, so invert everything we've read
buttons = ~buttons; buttons = ~buttons;
buttonState.buttons = (buttons & 0b1100111111); // All directly-mappable bits buttonState.buttons = (buttons & 0b1100111111); // All directly-mappable bits
@ -94,13 +98,11 @@ void loop() {
buttonState.hatAndConstant = 0x08; // nothing buttonState.hatAndConstant = 0x08; // nothing
} }
// I'm not implementing this for the time being buttonState.axis[2] = analogRead(ANALOG_WAMMY) / 4;
//buttonState.axis[2] = analogRead(ANALOG_WAMMY) / 4;
// Send an update // Send an update
HID().SendReport(0, (uint8_t *)&buttonState, 27); HID().SendReport(0, (uint8_t *)&buttonState, 27);
// don't report more frequently than 100Hz next = now + 10;
// this doubles as debouncing logic buttons = 0;
delay(10);
} }