Added tests. All pass on Leonardo.
This commit is contained in:
parent
6f0535be90
commit
e46724440c
|
|
@ -17,6 +17,7 @@ void setup()
|
||||||
setupLCD();
|
setupLCD();
|
||||||
setupLEDs();
|
setupLEDs();
|
||||||
setupTesters();
|
setupTesters();
|
||||||
|
Serial.println("Tester ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
@ -33,4 +34,5 @@ void loop()
|
||||||
setLedsFinal(false);
|
setLedsFinal(false);
|
||||||
Serial.println("Some tests failed!");
|
Serial.println("Some tests failed!");
|
||||||
}
|
}
|
||||||
|
while (true);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,5 @@
|
||||||
|
|
||||||
extern midi::MidiInterface<HardwareSerial> midiHW;
|
extern midi::MidiInterface<HardwareSerial> midiHW;
|
||||||
extern midi::MidiInterface<SoftwareSerial> midiSW;
|
extern midi::MidiInterface<SoftwareSerial> midiSW;
|
||||||
|
|
||||||
|
void setupMidi();
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
SoftwareSerial softSerial(2, 3);
|
SoftwareSerial softSerial(10, 11);
|
||||||
|
|
||||||
#if defined(__AVR_ATmega32U4__) // Leonardo uses Serial1 as hardware serial.
|
#if defined(__AVR_ATmega32U4__) // Leonardo uses Serial1 as hardware serial.
|
||||||
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiHW);
|
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiHW);
|
||||||
|
|
@ -15,3 +15,9 @@ SoftwareSerial softSerial(2, 3);
|
||||||
|
|
||||||
// \todo Create instance for USB if available
|
// \todo Create instance for USB if available
|
||||||
|
|
||||||
|
|
||||||
|
void setupMidi()
|
||||||
|
{
|
||||||
|
while (!softSerial.isListening())
|
||||||
|
softSerial.listen();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
void setupSerialDebug()
|
void setupSerialDebug()
|
||||||
{
|
{
|
||||||
Serial.begin(38400);
|
Serial.begin(9600);
|
||||||
|
while (!Serial)
|
||||||
|
{
|
||||||
|
; // wait for serial port to connect. Needed for Leonardo only
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,12 +43,12 @@ public:
|
||||||
Serial.print(": ");
|
Serial.print(": ");
|
||||||
if (inCondition == false)
|
if (inCondition == false)
|
||||||
{
|
{
|
||||||
Serial.println("Failed! /!\\");
|
Serial.println("Failed /!\\");
|
||||||
blinkFail();
|
blinkFail();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Passed.");
|
Serial.println("Passed");
|
||||||
blinkPass();
|
blinkPass();
|
||||||
}
|
}
|
||||||
return inCondition;
|
return inCondition;
|
||||||
|
|
@ -56,10 +56,26 @@ public:
|
||||||
|
|
||||||
bool run()
|
bool run()
|
||||||
{
|
{
|
||||||
performTest(testNoteOn);
|
bool result = true;
|
||||||
performTest(testNoteOff);
|
result &= performTest(testNoteOn);
|
||||||
performTest(testControlChange);
|
result &= performTest(testNoteOff);
|
||||||
performTest(testProgramChange);
|
result &= performTest(testControlChange);
|
||||||
|
result &= performTest(testProgramChange);
|
||||||
|
result &= performTest(testAftertouchMono);
|
||||||
|
result &= performTest(testAftertouchPoly);
|
||||||
|
result &= performTest(testPitchBend);
|
||||||
|
result &= performTest(testSysEx);
|
||||||
|
result &= performTest(testClock);
|
||||||
|
result &= performTest(testStart);
|
||||||
|
result &= performTest(testStop);
|
||||||
|
result &= performTest(testContinue);
|
||||||
|
result &= performTest(testActiveSensing);
|
||||||
|
result &= performTest(testTimeCode);
|
||||||
|
result &= performTest(testSongSelect);
|
||||||
|
result &= performTest(testSongPosition);
|
||||||
|
result &= performTest(testTuneRequest);
|
||||||
|
result &= performTest(testSystemReset);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -78,6 +94,7 @@ void setupTesters()
|
||||||
{
|
{
|
||||||
testerHW.setup();
|
testerHW.setup();
|
||||||
testerSW.setup();
|
testerSW.setup();
|
||||||
|
setupMidi();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool launchTests()
|
bool launchTests()
|
||||||
|
|
@ -85,8 +102,8 @@ bool launchTests()
|
||||||
Serial.println("Testing HW:");
|
Serial.println("Testing HW:");
|
||||||
if (testerHW.run() == false)
|
if (testerHW.run() == false)
|
||||||
return false;
|
return false;
|
||||||
Serial.println("Testing SW:");
|
/*Serial.println("Testing SW:");
|
||||||
if (testerSW.run() == false)
|
if (testerSW.run() == false)
|
||||||
return false;
|
return false;*/
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
#define NUM_TESTS 4
|
#define NUM_TESTS 18
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -23,7 +23,20 @@ static const char * testNames[] =
|
||||||
"NoteOff ",
|
"NoteOff ",
|
||||||
"ControlChange ",
|
"ControlChange ",
|
||||||
"ProgramChange ",
|
"ProgramChange ",
|
||||||
|
"AftertouchMono ",
|
||||||
|
"AftertouchPoly ",
|
||||||
|
"PitchBend ",
|
||||||
|
"SysEx ",
|
||||||
|
"Clock ",
|
||||||
|
"Start ",
|
||||||
|
"Stop ",
|
||||||
|
"Continue ",
|
||||||
|
"ActiveSensing ",
|
||||||
|
"TimeCode ",
|
||||||
|
"SongSelect ",
|
||||||
|
"SongPosition ",
|
||||||
|
"TuneRequest ",
|
||||||
|
"SystemReset ",
|
||||||
};
|
};
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
@ -32,3 +45,18 @@ DECLARE_MIDI_TEST(testNoteOn);
|
||||||
DECLARE_MIDI_TEST(testNoteOff);
|
DECLARE_MIDI_TEST(testNoteOff);
|
||||||
DECLARE_MIDI_TEST(testControlChange);
|
DECLARE_MIDI_TEST(testControlChange);
|
||||||
DECLARE_MIDI_TEST(testProgramChange);
|
DECLARE_MIDI_TEST(testProgramChange);
|
||||||
|
DECLARE_MIDI_TEST(testAftertouchMono);
|
||||||
|
DECLARE_MIDI_TEST(testAftertouchPoly);
|
||||||
|
DECLARE_MIDI_TEST(testPitchBend);
|
||||||
|
DECLARE_MIDI_TEST(testSysEx);
|
||||||
|
DECLARE_MIDI_TEST(testClock);
|
||||||
|
DECLARE_MIDI_TEST(testStart);
|
||||||
|
DECLARE_MIDI_TEST(testStop);
|
||||||
|
DECLARE_MIDI_TEST(testContinue);
|
||||||
|
DECLARE_MIDI_TEST(testActiveSensing);
|
||||||
|
DECLARE_MIDI_TEST(testTimeCode);
|
||||||
|
DECLARE_MIDI_TEST(testSongSelect);
|
||||||
|
DECLARE_MIDI_TEST(testSongPosition);
|
||||||
|
DECLARE_MIDI_TEST(testTuneRequest);
|
||||||
|
DECLARE_MIDI_TEST(testSystemReset);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,185 @@ IMPLEMENT_MIDI_TEST(testProgramChange, inMidi)
|
||||||
while (inMidi.read() == false) { }
|
while (inMidi.read() == false) { }
|
||||||
|
|
||||||
bool result = inMidi.getType() == midi::ProgramChange &&
|
bool result = inMidi.getType() == midi::ProgramChange &&
|
||||||
|
inMidi.getData1() == 12 &&
|
||||||
|
inMidi.getData2() == 0 &&
|
||||||
|
inMidi.getChannel() == 3;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testAftertouchMono, inMidi)
|
||||||
|
{
|
||||||
|
inMidi.sendAfterTouch(12, 3);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
|
||||||
|
bool result = inMidi.getType() == midi::AfterTouchChannel &&
|
||||||
|
inMidi.getData1() == 12 &&
|
||||||
|
inMidi.getData2() == 0 &&
|
||||||
|
inMidi.getChannel() == 3;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testAftertouchPoly, inMidi)
|
||||||
|
{
|
||||||
|
inMidi.sendPolyPressure(12, 42, 3);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
|
||||||
|
bool result = inMidi.getType() == midi::AfterTouchPoly &&
|
||||||
inMidi.getData1() == 12 &&
|
inMidi.getData1() == 12 &&
|
||||||
inMidi.getData2() == 42 &&
|
inMidi.getData2() == 42 &&
|
||||||
inMidi.getChannel() == 3;
|
inMidi.getChannel() == 3;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
volatile int pitchBendMemory = 0;
|
||||||
|
|
||||||
|
void pitchBendCallback(byte inChannel, int inValue)
|
||||||
|
{
|
||||||
|
pitchBendMemory = inValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testPitchBend, inMidi)
|
||||||
|
{
|
||||||
|
inMidi.setHandlePitchBend(pitchBendCallback);
|
||||||
|
pitchBendMemory = 0;
|
||||||
|
inMidi.sendPitchBend((int)1234, 3);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
|
||||||
|
bool result = inMidi.getType() == midi::PitchBend &&
|
||||||
|
pitchBendMemory == 1234 &&
|
||||||
|
inMidi.getChannel() == 3;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testSysEx, inMidi)
|
||||||
|
{
|
||||||
|
static const byte testData[13] =
|
||||||
|
{
|
||||||
|
'H', 'e', 'l', 'l', 'o', ',', ' ',
|
||||||
|
'w', 'o', 'r', 'l', 'd', 0
|
||||||
|
};
|
||||||
|
|
||||||
|
inMidi.sendSysEx(13, testData);
|
||||||
|
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
|
||||||
|
bool result = inMidi.getSysExArrayLength() == 15 && // 13 + F0 + F7
|
||||||
|
memcmp((const char*)inMidi.getSysExArray()+1,
|
||||||
|
(const char*)testData,
|
||||||
|
13) == 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testClock, inMidi)
|
||||||
|
{
|
||||||
|
inMidi.sendRealTime(midi::Clock);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
return inMidi.getType() == midi::Clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testStart, inMidi)
|
||||||
|
{
|
||||||
|
inMidi.sendRealTime(midi::Start);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
return inMidi.getType() == midi::Start;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testStop, inMidi)
|
||||||
|
{
|
||||||
|
inMidi.sendRealTime(midi::Stop);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
return inMidi.getType() == midi::Stop;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testContinue, inMidi)
|
||||||
|
{
|
||||||
|
inMidi.sendRealTime(midi::Continue);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
return inMidi.getType() == midi::Continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testActiveSensing, inMidi)
|
||||||
|
{
|
||||||
|
inMidi.sendRealTime(midi::ActiveSensing);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
return inMidi.getType() == midi::ActiveSensing;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// \todo Add callback to process parsed value
|
||||||
|
|
||||||
|
volatile byte timeCodeMemory = 0;
|
||||||
|
|
||||||
|
void timeCodeCallback(byte inData)
|
||||||
|
{
|
||||||
|
timeCodeMemory = inData;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testTimeCode, inMidi)
|
||||||
|
{
|
||||||
|
timeCodeMemory = 0;
|
||||||
|
inMidi.setHandleTimeCodeQuarterFrame(timeCodeCallback);
|
||||||
|
inMidi.sendTimeCodeQuarterFrame(0x07, 0x0F);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
bool result = inMidi.getType() == midi::TimeCodeQuarterFrame &&
|
||||||
|
timeCodeMemory == 0x7F &&
|
||||||
|
inMidi.getChannel() == 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testSongSelect, inMidi)
|
||||||
|
{
|
||||||
|
inMidi.sendSongSelect(12);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
|
||||||
|
bool result = inMidi.getType() == midi::SongSelect &&
|
||||||
|
inMidi.getData1() == 12 &&
|
||||||
|
inMidi.getData2() == 0 &&
|
||||||
|
inMidi.getChannel() == 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
volatile int songPositionMemory = 0;
|
||||||
|
|
||||||
|
void songPositionCallback(unsigned int inPosition)
|
||||||
|
{
|
||||||
|
songPositionMemory = inPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testSongPosition, inMidi)
|
||||||
|
{
|
||||||
|
songPositionMemory = 0;
|
||||||
|
inMidi.setHandleSongPosition(songPositionCallback);
|
||||||
|
inMidi.sendSongPosition(12345);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
|
||||||
|
bool result = inMidi.getType() == midi::SongPosition &&
|
||||||
|
songPositionMemory == 12345 &&
|
||||||
|
inMidi.getChannel() == 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testTuneRequest, inMidi)
|
||||||
|
{
|
||||||
|
inMidi.sendTuneRequest();
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
return inMidi.getType() == midi::TuneRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPLEMENT_MIDI_TEST(testSystemReset, inMidi)
|
||||||
|
{
|
||||||
|
inMidi.sendRealTime(midi::SystemReset);
|
||||||
|
while (inMidi.read() == false) { }
|
||||||
|
return inMidi.getType() == midi::SystemReset;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue