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:
+19
-24
@@ -1,6 +1,10 @@
|
|||||||
#include "led_stub.h"
|
#include "led_stub.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
static const uint8_t LED_PINS[10] = {
|
||||||
|
11, 12, 13, 14, 15, 16, 17, 18, 19, 20
|
||||||
|
};
|
||||||
|
|
||||||
DefaultLedStub::DefaultLedStub() : initialized(false) {
|
DefaultLedStub::DefaultLedStub() : initialized(false) {
|
||||||
for (int i = 0; i < NUM_LEDS; i++) {
|
for (int i = 0; i < NUM_LEDS; i++) {
|
||||||
led_states[i].active = false;
|
led_states[i].active = false;
|
||||||
@@ -12,37 +16,23 @@ DefaultLedStub::DefaultLedStub() : initialized(false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DefaultLedStub::begin() {
|
void DefaultLedStub::begin() {
|
||||||
|
for (int i = 0; i < NUM_LEDS; i++) {
|
||||||
|
pinMode(LED_PINS[i], OUTPUT);
|
||||||
|
digitalWrite(LED_PINS[i], LOW);
|
||||||
|
}
|
||||||
initialized = true;
|
initialized = true;
|
||||||
|
|
||||||
Serial.println("[LED] Startup colour cycle...");
|
Serial.println("[LED] Startup colour cycle...");
|
||||||
|
|
||||||
uint16_t colours[] = {
|
|
||||||
0xF800, // Red
|
|
||||||
0x07E0, // Green
|
|
||||||
0x001F, // Blue
|
|
||||||
0xFFE0, // Yellow
|
|
||||||
0xF81F, // Magenta
|
|
||||||
0x07FF, // Cyan
|
|
||||||
0xFFFF, // White
|
|
||||||
};
|
|
||||||
int num_colours = sizeof(colours) / sizeof(colours[0]);
|
|
||||||
|
|
||||||
for (int c = 0; c < num_colours; c++) {
|
|
||||||
uint16_t colour = colours[c];
|
|
||||||
uint8_t r = (colour >> 11) & 0x1F;
|
|
||||||
uint8_t g = (colour >> 5) & 0x3F;
|
|
||||||
uint8_t b = colour & 0x1F;
|
|
||||||
|
|
||||||
for (int i = 0; i < NUM_LEDS; i++) {
|
for (int i = 0; i < NUM_LEDS; i++) {
|
||||||
led_states[i].note = i;
|
digitalWrite(LED_PINS[i], HIGH);
|
||||||
led_states[i].channel = 1;
|
Serial.printf("[LED] LED %d ON (GPIO %d)\n", i, LED_PINS[i]);
|
||||||
led_states[i].velocity = 100;
|
delay(100);
|
||||||
led_states[i].active = true;
|
|
||||||
led_states[i].timestamp = millis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.printf("[LED] Colour %d: R=%d G=%d B=%d\n", c, r, g, b);
|
for (int i = 0; i < NUM_LEDS; i++) {
|
||||||
delay(100);
|
digitalWrite(LED_PINS[i], LOW);
|
||||||
|
delay(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_all();
|
clear_all();
|
||||||
@@ -61,6 +51,8 @@ void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t veloci
|
|||||||
led_states[led_index].active = (velocity > 0);
|
led_states[led_index].active = (velocity > 0);
|
||||||
led_states[led_index].timestamp = millis();
|
led_states[led_index].timestamp = millis();
|
||||||
|
|
||||||
|
digitalWrite(LED_PINS[led_index], velocity > 0 ? HIGH : LOW);
|
||||||
|
|
||||||
Serial.printf("[LED] Note %d -> LED %d Ch %d Vel %d (%s)\n",
|
Serial.printf("[LED] Note %d -> LED %d Ch %d Vel %d (%s)\n",
|
||||||
note, led_index, channel, velocity,
|
note, led_index, channel, velocity,
|
||||||
velocity > 0 ? "ON" : "OFF");
|
velocity > 0 ? "ON" : "OFF");
|
||||||
@@ -73,6 +65,9 @@ void DefaultLedStub::clear_all() {
|
|||||||
for (int i = 0; i < NUM_LEDS; i++) {
|
for (int i = 0; i < NUM_LEDS; i++) {
|
||||||
led_states[i].active = false;
|
led_states[i].active = false;
|
||||||
led_states[i].velocity = 0;
|
led_states[i].velocity = 0;
|
||||||
|
if (initialized) {
|
||||||
|
digitalWrite(LED_PINS[i], LOW);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Serial.println("[LED] All LEDs cleared");
|
Serial.println("[LED] All LEDs cleared");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ UsbMidiTransport::~UsbMidiTransport() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool UsbMidiTransport::begin() {
|
bool UsbMidiTransport::begin() {
|
||||||
Serial.println("[MIDI] Initializing USB MIDI...");
|
Serial.println("[MIDI] Setting up USB MIDI device...");
|
||||||
|
|
||||||
TinyUSBDevice.setManufacturerDescriptor("Ashley Strahle");
|
TinyUSBDevice.setManufacturerDescriptor("Ashley Strahle");
|
||||||
TinyUSBDevice.setProductDescriptor("Loopy Foot Controller");
|
TinyUSBDevice.setProductDescriptor("Loopy Foot Controller");
|
||||||
@@ -22,9 +22,8 @@ bool UsbMidiTransport::begin() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TinyUSBDevice.begin();
|
|
||||||
initialized = true;
|
initialized = true;
|
||||||
Serial.println("[MIDI] USB MIDI initialized - waiting for host");
|
Serial.println("[MIDI] USB MIDI ready");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+33
-3
@@ -1,10 +1,14 @@
|
|||||||
#include "switch_stub.h"
|
#include "switch_stub.h"
|
||||||
#include <Arduino.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) {
|
DefaultSwitchStub::DefaultSwitchStub() : initialized(false) {
|
||||||
for (int i = 0; i < NUM_SWITCHES; i++) {
|
for (int i = 0; i < NUM_SWITCHES; i++) {
|
||||||
switch_states[i].id = 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].current_state = false;
|
||||||
switch_states[i].previous_state = false;
|
switch_states[i].previous_state = false;
|
||||||
switch_states[i].last_change_time = 0;
|
switch_states[i].last_change_time = 0;
|
||||||
@@ -13,20 +17,46 @@ DefaultSwitchStub::DefaultSwitchStub() : initialized(false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DefaultSwitchStub::begin() {
|
void DefaultSwitchStub::begin() {
|
||||||
|
for (int i = 0; i < NUM_SWITCHES; i++) {
|
||||||
|
pinMode(switch_states[i].gpio_pin, INPUT_PULLUP);
|
||||||
|
}
|
||||||
initialized = true;
|
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) {
|
bool DefaultSwitchStub::is_pressed(uint8_t switch_id) {
|
||||||
if (!initialized || switch_id >= NUM_SWITCHES) {
|
if (!initialized || switch_id >= NUM_SWITCHES) {
|
||||||
return false;
|
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) {
|
void DefaultSwitchStub::configure_switch(uint8_t switch_id, uint8_t gpio_pin) {
|
||||||
if (switch_id >= NUM_SWITCHES) return;
|
if (switch_id >= NUM_SWITCHES) return;
|
||||||
switch_states[switch_id].gpio_pin = gpio_pin;
|
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);
|
Serial.printf("[SW] Switch %d configured to GPIO %d\n", switch_id, gpio_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user