Fix USB MIDI, add GPIO for switches and LEDs

- Remove TinyUSBDevice.begin() conflict with Arduino core
- Switch stub now reads GPIO with debounce (pins 1-10)
- LED stub now drives GPIO pins (pins 11-20) with startup animation
- All pins printed to console on init
This commit is contained in:
2026-06-23 13:18:20 +00:00
parent 22572b9baa
commit bb32ec65d1
3 changed files with 56 additions and 32 deletions
+33 -3
View File
@@ -1,10 +1,14 @@
#include "switch_stub.h"
#include <Arduino.h>
static const uint8_t SWITCH_PINS[10] = {
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
};
DefaultSwitchStub::DefaultSwitchStub() : initialized(false) {
for (int i = 0; i < NUM_SWITCHES; i++) {
switch_states[i].id = i;
switch_states[i].gpio_pin = 0;
switch_states[i].gpio_pin = SWITCH_PINS[i];
switch_states[i].current_state = false;
switch_states[i].previous_state = false;
switch_states[i].last_change_time = 0;
@@ -13,20 +17,46 @@ DefaultSwitchStub::DefaultSwitchStub() : initialized(false) {
}
void DefaultSwitchStub::begin() {
for (int i = 0; i < NUM_SWITCHES; i++) {
pinMode(switch_states[i].gpio_pin, INPUT_PULLUP);
}
initialized = true;
Serial.println("[SW] Stub initialized (GPIO pins not configured yet)");
Serial.printf("[SW] Initialized %d switches on GPIOs: ", NUM_SWITCHES);
for (int i = 0; i < NUM_SWITCHES; i++) {
Serial.printf("%d ", switch_states[i].gpio_pin);
}
Serial.println();
}
bool DefaultSwitchStub::is_pressed(uint8_t switch_id) {
if (!initialized || switch_id >= NUM_SWITCHES) {
return false;
}
return switch_states[switch_id].current_state;
SwitchState& sw = switch_states[switch_id];
bool raw = (digitalRead(sw.gpio_pin) == LOW);
uint32_t now = millis();
if (raw != sw.previous_state) {
sw.last_change_time = now;
}
if ((now - sw.last_change_time) >= sw.debounce_time) {
if (raw != sw.current_state) {
sw.current_state = raw;
}
}
sw.previous_state = raw;
return sw.current_state;
}
void DefaultSwitchStub::configure_switch(uint8_t switch_id, uint8_t gpio_pin) {
if (switch_id >= NUM_SWITCHES) return;
switch_states[switch_id].gpio_pin = gpio_pin;
if (initialized) {
pinMode(gpio_pin, INPUT_PULLUP);
}
Serial.printf("[SW] Switch %d configured to GPIO %d\n", switch_id, gpio_pin);
}