SrmMall fixes.

Added option for disable debug output.
main
Holger Wirtz 1 year ago
parent bbaeb25b54
commit 2a313af85e
  1. 40
      MIDI-Host-Adapter.ino

@ -23,6 +23,8 @@
#include <limits.h> #include <limits.h>
#include <EEPROM.h> #include <EEPROM.h>
#define DEBUG
#define STROBE_TM 9 #define STROBE_TM 9
#define CLOCK_TM 8 #define CLOCK_TM 8
#define DIO_TM 7 #define DIO_TM 7
@ -37,7 +39,6 @@ bool high_freq = false;
#define BRIGHTNESS 6 #define BRIGHTNESS 6
#define INITIAL_MIDI_CHANNEL 1 #define INITIAL_MIDI_CHANNEL 1
#define BUTTON_DEBOUNCE_TIME_MS 150 #define BUTTON_DEBOUNCE_TIME_MS 150
#define BUTTON_DOUBLE_PRESS_MS 250
#define BLINK_FREQUENCY_MS 500 #define BLINK_FREQUENCY_MS 500
#define EEPROM_ADDRESS 0x42 #define EEPROM_ADDRESS 0x42
@ -52,20 +53,26 @@ void setup() {
Serial.begin(9600); Serial.begin(9600);
delay(50); delay(50);
#if defined(DEBUG)
Serial.println("<SETUP>"); Serial.println("<SETUP>");
#endif
tm.displayBegin(); tm.displayBegin();
tm.brightness(BRIGHTNESS); tm.brightness(BRIGHTNESS);
tm.DisplayStr("MIDIHOST", 0); tm.DisplayStr("HLLOWRLD", 0);
uint8_t tmp_channel = EEPROM.read(EEPROM_ADDRESS); uint8_t tmp_channel = EEPROM.read(EEPROM_ADDRESS);
if (tmp_channel & 0xf0 != 0xf0) { if (tmp_channel & 0xf0 != 0xf0) {
actual_channel = 1; actual_channel = 1;
#if defined(DEBUG)
Serial.println("Setting channel to 1"); Serial.println("Setting channel to 1");
#endif
} else { } else {
actual_channel = 0x0f & tmp_channel; actual_channel = 0x0f & tmp_channel;
#if defined(DEBUG)
Serial.print("Reading channel from EEPROM: "); Serial.print("Reading channel from EEPROM: ");
Serial.println(actual_channel, DEC); Serial.println(actual_channel, DEC);
#endif
} }
new_channel = actual_channel; new_channel = actual_channel;
@ -76,11 +83,13 @@ void setup() {
SetMidiChannel(INITIAL_MIDI_CHANNEL); SetMidiChannel(INITIAL_MIDI_CHANNEL);
delay(500); delay(200);
tm.DisplayDecNum(actual_channel, 0, false, TMAlignTextRight); tm.DisplayDecNum(actual_channel, 0, false, TMAlignTextRight);
#if defined(DEBUG)
Serial.println("</SETUP>"); Serial.println("</SETUP>");
#endif
} }
void loop() { void loop() {
@ -90,20 +99,25 @@ void loop() {
if (button > 0 && button != actual_channel && button_debounce_timer > BUTTON_DEBOUNCE_TIME_MS) { if (button > 0 && button != actual_channel && button_debounce_timer > BUTTON_DEBOUNCE_TIME_MS) {
if (button != new_channel) { if (button != new_channel) {
// Button pressed once // Button pressed once
Serial.print("Button once: "); #if defined(DEBUG)
Serial.print("Button pressed once: ");
Serial.println(button, DEC); Serial.println(button, DEC);
#endif
button_debounce_timer = 0; button_debounce_timer = 0;
blink_timer = 0; blink_timer = 0;
new_channel = button; new_channel = button;
tm.DisplayDecNumNibble(new_channel, actual_channel, 0, false, TMAlignTextRight); tm.DisplayDecNumNibble(new_channel, actual_channel, 0, false, TMAlignTextRight);
} else { } else {
// Button pressed twice // Button pressed twice
Serial.print("Button twice: "); #if defined(DEBUG)
Serial.print("Button pressed twice: ");
Serial.println(button, DEC); Serial.println(button, DEC);
#endif
actual_channel = new_channel; actual_channel = new_channel;
EEPROM.update(EEPROM_ADDRESS, 0xf0 | actual_channel); EEPROM.update(EEPROM_ADDRESS, 0xf0 | actual_channel);
SetMidiChannel(actual_channel); SetMidiChannel(actual_channel);
tm.DisplayDecNum(actual_channel, 0, false, TMAlignTextRight);
} }
} }
@ -114,21 +128,25 @@ void loop() {
} else if (blink_timer > BLINK_FREQUENCY_MS / 2) { } else if (blink_timer > BLINK_FREQUENCY_MS / 2) {
tm.DisplayDecNumNibble(new_channel, actual_channel, 0, false, TMAlignTextRight); tm.DisplayDecNumNibble(new_channel, actual_channel, 0, false, TMAlignTextRight);
} }
} else tm.DisplayDecNum(actual_channel, 0, false, TMAlignTextRight); }
} }
void SetMidiChannel(uint8_t channel) { void SetMidiChannel(uint8_t channel) {
if (channel < 1 || channel > 16) { if (channel < 1 || channel > 16) {
#if defined(DEBUG)
Serial.print("ERROR: MIDI channel number out of range: "); Serial.print("ERROR: MIDI channel number out of range: ");
Serial.print(channel, DEC); Serial.print(channel, DEC);
#endif
return; return;
} }
#if defined(DEBUG)
Serial.print("Setting MIDI channel to: "); Serial.print("Setting MIDI channel to: ");
Serial.print(channel, DEC); Serial.print(channel, DEC);
channel--;
Serial.print(" ("); Serial.print(" (");
printBinary(channel, 4); printBinary(--channel, 4);
Serial.println(")"); Serial.println(")");
#endif
digitalWrite(MIDI_CH_BIT0, channel & 0x00); digitalWrite(MIDI_CH_BIT0, channel & 0x00);
digitalWrite(MIDI_CH_BIT1, channel & 0x01); digitalWrite(MIDI_CH_BIT1, channel & 0x01);
@ -136,8 +154,10 @@ void SetMidiChannel(uint8_t channel) {
digitalWrite(MIDI_CH_BIT3, channel & 0x08); digitalWrite(MIDI_CH_BIT3, channel & 0x08);
} }
#if defined(DEBUG)
void printBinary(uint32_t value, uint8_t len) { void printBinary(uint32_t value, uint8_t len) {
for (uint8_t b = len; b > 0; --b) { for (uint8_t b = len; b > 0; --b) {
Serial.print((char)('0' + ((value >> (b - 1)) & 1))); Serial.print((char)('0' + ((value >> (b - 1)) & 1)));
} }
} }
#endif
Loading…
Cancel
Save