Make flash latency tunable at runtime via 'latency N' serial command
This commit is contained in:
+15
-2
@@ -21,6 +21,8 @@ UsbMidiTransport midi_transport;
|
||||
AppTask controller(&led_driver, &switch_driver, &midi_transport);
|
||||
ExpressionPedal exp_pedal(4);
|
||||
|
||||
static volatile uint32_t flash_latency = 20; // ms delay to compensate for Loopy Pro rendering
|
||||
|
||||
TaskHandle_t midi_task_handle = NULL;
|
||||
|
||||
void midi_task(void* parameter) {
|
||||
@@ -29,7 +31,6 @@ void midi_task(void* parameter) {
|
||||
// Beat timing fixes for precise beat alignment - sync to real MIDI time, not hardcoded tempo
|
||||
uint32_t last_beat = 0;
|
||||
uint32_t flash_start = 0;
|
||||
const uint32_t FLASH_LATENCY = 20; // ms delay to compensate for audio buffer
|
||||
|
||||
while (true) {
|
||||
midi_transport.update();
|
||||
@@ -42,7 +43,7 @@ void midi_task(void* parameter) {
|
||||
|
||||
if (current_beat != last_beat) {
|
||||
last_beat = current_beat;
|
||||
flash_start = now + FLASH_LATENCY;
|
||||
flash_start = now + flash_latency;
|
||||
// Beat 1 (every 4th) = RED, others = WHITE
|
||||
if (current_beat % 4 == 0) {
|
||||
mux.set_led_color(6, 255, 0, 0);
|
||||
@@ -122,6 +123,16 @@ void handle_serial_command(const String& cmd) {
|
||||
} else if (cmd == "exp") {
|
||||
Serial.printf("[CMD] EXP ADC=%d MIDI=%d\n",
|
||||
exp_pedal.get_raw(), exp_pedal.get_value());
|
||||
} else if (cmd == "latency") {
|
||||
Serial.printf("[CMD] Current flash latency: %d ms\n", flash_latency);
|
||||
} else if (cmd.startsWith("latency ")) {
|
||||
int val = atoi(cmd.c_str() + 8);
|
||||
if (val >= 0 && val <= 500) {
|
||||
flash_latency = val;
|
||||
Serial.printf("[CMD] Flash latency set to %d ms\n", flash_latency);
|
||||
} else {
|
||||
Serial.println("[CMD] Latency must be 0-500 ms");
|
||||
}
|
||||
} else if (cmd == "usb") {
|
||||
Serial.printf("[CMD] USB mounted: %s\n", TinyUSBDevice.mounted() ? "YES" : "NO");
|
||||
Serial.printf("[CMD] USB ready: %s\n", TinyUSBDevice.ready() ? "YES" : "NO");
|
||||
@@ -166,6 +177,8 @@ void handle_serial_command(const String& cmd) {
|
||||
Serial.println(" red/green/blue - solid colour");
|
||||
Serial.println(" pixel0/pixel1 - single pixel test");
|
||||
Serial.println(" exp - expression pedal ADC/MIDI value");
|
||||
Serial.println(" latency - show current flash latency");
|
||||
Serial.println(" latency N - set flash latency to N ms (0-500)");
|
||||
Serial.println(" usb - USB connection status and descriptor info");
|
||||
Serial.println(" gpiotest - raw GPIO pin diagnostic");
|
||||
Serial.println(" rawled - bit-bang WS2812 (no library)");
|
||||
|
||||
Reference in New Issue
Block a user