Move all source files to src/ to fix LDF linking
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
#include "app_task.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
AppTask::AppTask(LedStub* led, SwitchStub* sw, UsbMidiTransport* midi)
|
||||
: led_driver(led), switch_driver(sw), midi_transport(midi) {
|
||||
|
||||
// Default pad mapping
|
||||
for (uint8_t i = 0; i < NUM_PADS; i++) {
|
||||
pad_mapping[i].physical_switch = i;
|
||||
pad_mapping[i].midi_channel = 1;
|
||||
pad_mapping[i].midi_note = i;
|
||||
pad_mapping[i].led_index = i;
|
||||
last_switch_state[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void AppTask::begin() {
|
||||
Serial.println("[APP] Controller task started");
|
||||
|
||||
// Register MIDI callback
|
||||
midi_transport->on_midi_receive([this](const MidiEvent& event) {
|
||||
process_midi_event(event);
|
||||
});
|
||||
}
|
||||
|
||||
void AppTask::update() {
|
||||
// Poll switches
|
||||
for (uint8_t i = 0; i < NUM_PADS; i++) {
|
||||
bool is_pressed = switch_driver->is_pressed(i);
|
||||
|
||||
if (is_pressed && !last_switch_state[i]) {
|
||||
process_switch_event(i, true);
|
||||
last_switch_state[i] = true;
|
||||
} else if (!is_pressed && last_switch_state[i]) {
|
||||
process_switch_event(i, false);
|
||||
last_switch_state[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppTask::process_midi_event(const MidiEvent& event) {
|
||||
uint8_t led_index = 0xFF;
|
||||
uint8_t midi_channel = event.channel;
|
||||
uint8_t midi_note = event.data1;
|
||||
uint8_t midi_velocity = event.data2;
|
||||
|
||||
// Find matching LED index from pad mapping
|
||||
for (uint8_t i = 0; i < NUM_PADS; i++) {
|
||||
if (pad_mapping[i].midi_channel == midi_channel &&
|
||||
pad_mapping[i].midi_note == midi_note) {
|
||||
led_index = pad_mapping[i].led_index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (led_index < NUM_PADS) {
|
||||
led_driver->set_led_state(
|
||||
pad_mapping[led_index].midi_note,
|
||||
pad_mapping[led_index].midi_channel,
|
||||
event.type == MidiEvent::NOTE_ON ? midi_velocity : 0
|
||||
);
|
||||
|
||||
Serial.printf("[APP] MIDI -> LED: Ch%d Note%d Vel%d -> LED%d\n",
|
||||
midi_channel, midi_note, midi_velocity, led_index);
|
||||
}
|
||||
}
|
||||
|
||||
void AppTask::process_switch_event(uint8_t switch_id, bool pressed) {
|
||||
// Find mapping for this switch
|
||||
for (uint8_t i = 0; i < NUM_PADS; i++) {
|
||||
if (pad_mapping[i].physical_switch == switch_id) {
|
||||
uint8_t channel = pad_mapping[i].midi_channel;
|
||||
uint8_t note = pad_mapping[i].midi_note;
|
||||
uint8_t velocity = pressed ? 127 : 0;
|
||||
|
||||
if (pressed) {
|
||||
midi_transport->send_note_on(channel, note, velocity);
|
||||
} else {
|
||||
midi_transport->send_note_off(channel, note, velocity);
|
||||
}
|
||||
|
||||
Serial.printf("[APP] Switch %d -> Ch%d Note%d Vel%d (%s)\n",
|
||||
switch_id, channel, note, velocity,
|
||||
pressed ? "PRESS" : "RELEASE");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "led_stub.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
DefaultLedStub::DefaultLedStub() : initialized(false) {
|
||||
for (int i = 0; i < NUM_LEDS; i++) {
|
||||
led_states[i].active = false;
|
||||
led_states[i].velocity = 0;
|
||||
led_states[i].note = 0;
|
||||
led_states[i].channel = 0;
|
||||
led_states[i].timestamp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultLedStub::begin() {
|
||||
initialized = true;
|
||||
Serial.println("[LED] Stub initialized (GPIO pins not configured yet)");
|
||||
}
|
||||
|
||||
void DefaultLedStub::set_led_state(uint8_t note, uint8_t channel, uint8_t velocity) {
|
||||
if (!initialized) return;
|
||||
|
||||
uint8_t led_index = note_to_index(note);
|
||||
|
||||
if (led_index < NUM_LEDS) {
|
||||
led_states[led_index].note = note;
|
||||
led_states[led_index].channel = channel;
|
||||
led_states[led_index].velocity = velocity;
|
||||
led_states[led_index].active = (velocity > 0);
|
||||
led_states[led_index].timestamp = millis();
|
||||
|
||||
Serial.printf("[LED] Note %d -> LED %d Ch %d Vel %d (%s)\n",
|
||||
note, led_index, channel, velocity,
|
||||
velocity > 0 ? "ON" : "OFF");
|
||||
} else {
|
||||
Serial.printf("[LED] Index out of range: %d (Note: %d)\n", led_index, note);
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultLedStub::clear_all() {
|
||||
for (int i = 0; i < NUM_LEDS; i++) {
|
||||
led_states[i].active = false;
|
||||
led_states[i].velocity = 0;
|
||||
}
|
||||
Serial.println("[LED] All LEDs cleared");
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
#include "midi_transport.h"
|
||||
#include <Arduino.h>
|
||||
#include <USB.h>
|
||||
#include <USBMIDI.h>
|
||||
|
||||
// TinyUSB MIDI interface
|
||||
static USBMIDI MIDI;
|
||||
|
||||
UsbMidiTransport::UsbMidiTransport() : initialized(false) {
|
||||
}
|
||||
|
||||
UsbMidiTransport::~UsbMidiTransport() {
|
||||
}
|
||||
|
||||
bool UsbMidiTransport::begin() {
|
||||
USB.begin();
|
||||
MIDI.begin(MIDI_CHANNEL_OMNI);
|
||||
initialized = true;
|
||||
Serial.println("[MIDI] USB MIDI transport initialized");
|
||||
return true;
|
||||
}
|
||||
|
||||
void UsbMidiTransport::update() {
|
||||
if (!initialized) return;
|
||||
|
||||
// Check for incoming MIDI
|
||||
if (MIDI.read()) {
|
||||
MidiEvent event;
|
||||
midi_message_t msg = MIDI.getMessage();
|
||||
|
||||
event.channel = msg.channel;
|
||||
event.data1 = msg.data1;
|
||||
event.data2 = msg.data2;
|
||||
event.timestamp = millis();
|
||||
|
||||
// Map Arduino MIDI types to our types
|
||||
switch (msg.type) {
|
||||
case midi::NoteOn:
|
||||
event.type = (msg.data2 > 0) ? MidiEvent::NOTE_ON : MidiEvent::NOTE_OFF;
|
||||
break;
|
||||
case midi::NoteOff:
|
||||
event.type = MidiEvent::NOTE_OFF;
|
||||
break;
|
||||
case midi::ControlChange:
|
||||
event.type = MidiEvent::CONTROL_CHANGE;
|
||||
break;
|
||||
case midi::ProgramChange:
|
||||
event.type = MidiEvent::PROGRAM_CHANGE;
|
||||
break;
|
||||
case midi::PitchBend:
|
||||
event.type = MidiEvent::PITCH_BEND;
|
||||
break;
|
||||
default:
|
||||
return; // Unknown type, skip
|
||||
}
|
||||
|
||||
// Diagnostic logging
|
||||
const char* type_str = "UNK";
|
||||
switch (event.type) {
|
||||
case MidiEvent::NOTE_ON: type_str = "NOTE_ON"; break;
|
||||
case MidiEvent::NOTE_OFF: type_str = "NOTE_OFF"; break;
|
||||
case MidiEvent::CONTROL_CHANGE: type_str = "CC"; break;
|
||||
case MidiEvent::PROGRAM_CHANGE: type_str = "PC"; break;
|
||||
case MidiEvent::PITCH_BEND: type_str = "PB"; break;
|
||||
default: break;
|
||||
}
|
||||
Serial.printf("[MIDI IN] Ch:%d %s:%d:%d\n", event.channel, type_str, event.data1, event.data2);
|
||||
|
||||
// Call callback
|
||||
if (receive_callback) {
|
||||
receive_callback(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UsbMidiTransport::on_midi_receive(std::function<void(const MidiEvent&)> callback) {
|
||||
receive_callback = callback;
|
||||
}
|
||||
|
||||
void UsbMidiTransport::send_note_on(uint8_t channel, uint8_t note, uint8_t velocity) {
|
||||
if (!initialized) return;
|
||||
MIDI.sendNoteOn(note, velocity, channel);
|
||||
}
|
||||
|
||||
void UsbMidiTransport::send_note_off(uint8_t channel, uint8_t note, uint8_t velocity) {
|
||||
if (!initialized) return;
|
||||
MIDI.sendNoteOff(note, velocity, channel);
|
||||
}
|
||||
|
||||
void UsbMidiTransport::send_cc(uint8_t channel, uint8_t cc, uint8_t value) {
|
||||
if (!initialized) return;
|
||||
MIDI.sendControlChange(cc, value, channel);
|
||||
}
|
||||
|
||||
void UsbMidiTransport::parse_midi_packet(const uint8_t* buffer, uint32_t size, MidiEvent& event) {
|
||||
// Not used with Arduino MIDI library - kept for reference
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "switch_stub.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
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].current_state = false;
|
||||
switch_states[i].previous_state = false;
|
||||
switch_states[i].last_change_time = 0;
|
||||
switch_states[i].debounce_time = 50;
|
||||
}
|
||||
}
|
||||
|
||||
void DefaultSwitchStub::begin() {
|
||||
initialized = true;
|
||||
Serial.println("[SW] Stub initialized (GPIO pins not configured yet)");
|
||||
}
|
||||
|
||||
bool DefaultSwitchStub::is_pressed(uint8_t switch_id) {
|
||||
if (!initialized || switch_id >= NUM_SWITCHES) {
|
||||
return false;
|
||||
}
|
||||
return switch_states[switch_id].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;
|
||||
Serial.printf("[SW] Switch %d configured to GPIO %d\n", switch_id, gpio_pin);
|
||||
}
|
||||
|
||||
void DefaultSwitchStub::set_debounce_time(uint32_t time_ms) {
|
||||
for (int i = 0; i < NUM_SWITCHES; i++) {
|
||||
switch_states[i].debounce_time = time_ms;
|
||||
}
|
||||
Serial.printf("[SW] Debounce time set to %lu ms\n", time_ms);
|
||||
}
|
||||
Reference in New Issue
Block a user