Cleanup old validator
This commit is contained in:
parent
49b109b4a2
commit
d0523b3fc1
|
|
@ -1,39 +0,0 @@
|
|||
|
||||
#include <SoftwareSerial.h>
|
||||
#include <MIDI.h>
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "midi_ValidatorSerialDebug.h"
|
||||
#include "midi_ValidatorLCD.h"
|
||||
#include "midi_ValidatorLEDs.h"
|
||||
#include "midi_ValidatorInstances.h"
|
||||
#include "midi_ValidatorTester.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void setup()
|
||||
{
|
||||
setupSerialDebug();
|
||||
setupLCD();
|
||||
setupLEDs();
|
||||
setupTesters();
|
||||
Serial.println("Tester ready");
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (launchTests() == true)
|
||||
{
|
||||
setLedsFinal(true);
|
||||
Serial.println("All tests passed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
setLedsFinal(false);
|
||||
Serial.println("Some tests failed!");
|
||||
}
|
||||
while (true);
|
||||
}
|
||||
Binary file not shown.
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
#include <MIDI.h>
|
||||
|
||||
extern midi::MidiInterface<HardwareSerial> midiHW;
|
||||
extern midi::MidiInterface<SoftwareSerial> midiSW;
|
||||
|
||||
void setupMidi();
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#include <Arduino.h>
|
||||
#include "midi_ValidatorInstances.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
SoftwareSerial softSerial(10, 11);
|
||||
|
||||
#if defined(__AVR_ATmega32U4__) // Leonardo uses Serial1 as hardware serial.
|
||||
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, midiHW);
|
||||
MIDI_CREATE_INSTANCE(SoftwareSerial, softSerial, midiSW);
|
||||
#else
|
||||
MIDI_CREATE_INSTANCE(HardwareSerial, Serial, midiHW);
|
||||
MIDI_CREATE_INSTANCE(SoftwareSerial, softSerial, midiSW);
|
||||
#endif
|
||||
|
||||
void setupMidi()
|
||||
{
|
||||
while (!softSerial.isListening())
|
||||
softSerial.listen();
|
||||
}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
#pragma once
|
||||
#include <LiquidCrystal.h>
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
extern LiquidCrystal lcd;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void setupLCD();
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void setProgressBar(unsigned inProgress, unsigned inTotal);
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
#include <Arduino.h>
|
||||
#include "midi_ValidatorLCD.h"
|
||||
|
||||
#define LCD_D4 8
|
||||
#define LCD_D5 9
|
||||
#define LCD_D6 10
|
||||
#define LCD_D7 11
|
||||
#define LCD_RS 12
|
||||
#define LCD_EN 13
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
byte progressChar[6][8] =
|
||||
{
|
||||
{ B00000, B00000, B00000, B00000, B00000, B00000, B00000, B00000 },
|
||||
{ B10000, B10000, B10000, B10000, B10000, B10000, B10000, B10000 },
|
||||
{ B11000, B11000, B11000, B11000, B11000, B11000, B11000, B11000 },
|
||||
{ B11100, B11100, B11100, B11100, B11100, B11100, B11100, B11100 },
|
||||
{ B11110, B11110, B11110, B11110, B11110, B11110, B11110, B11110 },
|
||||
{ B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 },
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
|
||||
|
||||
void setupLCD()
|
||||
{
|
||||
for (byte i = 0; i < 6; ++i)
|
||||
lcd.createChar(i, progressChar[i]);
|
||||
|
||||
lcd.begin(16,2);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void setProgressBar(unsigned inProgress, unsigned inTotal)
|
||||
{
|
||||
const byte numCols = 16;
|
||||
const byte numPix = 5;
|
||||
const unsigned progress = (inProgress * numCols* numPix) / inTotal;
|
||||
const byte cursorX = progress / numPix;
|
||||
const byte charIndex = progress % numPix;
|
||||
|
||||
lcd.setCursor(cursorX, 1);
|
||||
lcd.write(charIndex);
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#define LED_PASS 4
|
||||
#define LED_FAIL 5
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void setupLEDs();
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
inline void blinkLed(byte inLedNum)
|
||||
{
|
||||
digitalWrite(inLedNum, HIGH);
|
||||
delay(100);
|
||||
digitalWrite(inLedNum, LOW);
|
||||
}
|
||||
|
||||
inline void blinkPass()
|
||||
{
|
||||
blinkLed(LED_PASS);
|
||||
}
|
||||
|
||||
inline void blinkFail()
|
||||
{
|
||||
blinkLed(LED_FAIL);
|
||||
}
|
||||
|
||||
inline void setLedsFinal(bool inSuccess)
|
||||
{
|
||||
if (inSuccess)
|
||||
{
|
||||
digitalWrite(LED_PASS, HIGH);
|
||||
digitalWrite(LED_FAIL, LOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
digitalWrite(LED_FAIL, HIGH);
|
||||
digitalWrite(LED_PASS, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
#include <Arduino.h>
|
||||
#include "midi_ValidatorLEDs.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void setupLEDs()
|
||||
{
|
||||
pinMode(LED_PASS, OUTPUT);
|
||||
pinMode(LED_FAIL, OUTPUT);
|
||||
}
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
void setupSerialDebug();
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
#include <Arduino.h>
|
||||
#include "midi_ValidatorSerialDebug.h"
|
||||
|
||||
void setupSerialDebug()
|
||||
{
|
||||
Serial.begin(9600);
|
||||
while (!Serial)
|
||||
{
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
void setupTesters();
|
||||
bool launchTests();
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
#include <Arduino.h>
|
||||
#include "midi_ValidatorTester.h"
|
||||
#include "midi_ValidatorInstances.h"
|
||||
#include "midi_ValidatorTests.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
template<class SerialClass>
|
||||
class Tester
|
||||
{
|
||||
public:
|
||||
typedef bool (*Functor) (MIDI_CLASS(SerialClass)&);
|
||||
|
||||
public:
|
||||
explicit Tester(MIDI_CLASS(SerialClass)& inInstance)
|
||||
: mMidiInstance(inInstance)
|
||||
, mProgress(0)
|
||||
{
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
mProgress = 0;
|
||||
mMidiInstance.begin(MIDI_CHANNEL_OMNI);
|
||||
mMidiInstance.turnThruOff();
|
||||
}
|
||||
|
||||
public:
|
||||
inline bool performTest(Functor inTestMethod)
|
||||
{
|
||||
if (inTestMethod != 0)
|
||||
{
|
||||
const bool result = expect((*inTestMethod)(mMidiInstance));
|
||||
setProgressBar(++mProgress, NUM_TESTS);
|
||||
return result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool expect(bool inCondition) const
|
||||
{
|
||||
Serial.print(testNames[mProgress]);
|
||||
Serial.print(": ");
|
||||
if (inCondition == false)
|
||||
{
|
||||
Serial.println("Failed /!\\");
|
||||
blinkFail();
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("Passed");
|
||||
blinkPass();
|
||||
}
|
||||
return inCondition;
|
||||
}
|
||||
|
||||
bool run()
|
||||
{
|
||||
bool result = true;
|
||||
result &= performTest(testNoteOn);
|
||||
result &= performTest(testNoteOff);
|
||||
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:
|
||||
MIDI_CLASS(SerialClass)& mMidiInstance;
|
||||
unsigned mProgress;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Tester<HardwareSerial> testerHW(midiHW);
|
||||
Tester<SoftwareSerial> testerSW(midiSW);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
void setupTesters()
|
||||
{
|
||||
testerHW.setup();
|
||||
testerSW.setup();
|
||||
setupMidi();
|
||||
}
|
||||
|
||||
bool launchTests()
|
||||
{
|
||||
Serial.println("Testing HW:");
|
||||
if (testerHW.run() == false)
|
||||
return false;
|
||||
Serial.println("Testing SW:");
|
||||
if (testerSW.run() == false)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define NUM_TESTS 18
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define DECLARE_MIDI_TEST(Name) \
|
||||
template<class SerialClass> \
|
||||
bool Name(MIDI_CLASS(SerialClass)& inMidi)
|
||||
|
||||
#define IMPLEMENT_MIDI_TEST(Name, Instance) \
|
||||
template<class SerialClass> \
|
||||
bool Name(MIDI_CLASS(SerialClass)& Instance)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static const char * testNames[] =
|
||||
{
|
||||
// 0123456789ABCDEF
|
||||
"NoteOn ",
|
||||
"NoteOff ",
|
||||
"ControlChange ",
|
||||
"ProgramChange ",
|
||||
"AftertouchMono ",
|
||||
"AftertouchPoly ",
|
||||
"PitchBend ",
|
||||
"SysEx ",
|
||||
"Clock ",
|
||||
"Start ",
|
||||
"Stop ",
|
||||
"Continue ",
|
||||
"ActiveSensing ",
|
||||
"TimeCode ",
|
||||
"SongSelect ",
|
||||
"SongPosition ",
|
||||
"TuneRequest ",
|
||||
"SystemReset ",
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
DECLARE_MIDI_TEST(testNoteOn);
|
||||
DECLARE_MIDI_TEST(testNoteOff);
|
||||
DECLARE_MIDI_TEST(testControlChange);
|
||||
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);
|
||||
|
||||
|
|
@ -1,229 +0,0 @@
|
|||
#include <Arduino.h>
|
||||
#include "midi_ValidatorTests.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_MIDI_TEST(testNoteOn, inMidi)
|
||||
{
|
||||
inMidi.sendNoteOn(12, 42, 3);
|
||||
while (inMidi.read() == false) { }
|
||||
|
||||
bool result = inMidi.getType() == midi::NoteOn &&
|
||||
inMidi.getData1() == 12 &&
|
||||
inMidi.getData2() == 42 &&
|
||||
inMidi.getChannel() == 3;
|
||||
return result;
|
||||
}
|
||||
|
||||
IMPLEMENT_MIDI_TEST(testNoteOff, inMidi)
|
||||
{
|
||||
inMidi.sendNoteOff(12, 42, 3);
|
||||
while (inMidi.read() == false) { }
|
||||
|
||||
bool result = inMidi.getType() == midi::NoteOff &&
|
||||
inMidi.getData1() == 12 &&
|
||||
inMidi.getData2() == 42 &&
|
||||
inMidi.getChannel() == 3;
|
||||
return result;
|
||||
}
|
||||
|
||||
IMPLEMENT_MIDI_TEST(testControlChange, inMidi)
|
||||
{
|
||||
inMidi.sendControlChange(12, 42, 3);
|
||||
while (inMidi.read() == false) { }
|
||||
|
||||
bool result = inMidi.getType() == midi::ControlChange &&
|
||||
inMidi.getData1() == 12 &&
|
||||
inMidi.getData2() == 42 &&
|
||||
inMidi.getChannel() == 3;
|
||||
return result;
|
||||
}
|
||||
|
||||
IMPLEMENT_MIDI_TEST(testProgramChange, inMidi)
|
||||
{
|
||||
inMidi.sendProgramChange(12, 3);
|
||||
while (inMidi.read() == false) { }
|
||||
|
||||
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.getData2() == 42 &&
|
||||
inMidi.getChannel() == 3;
|
||||
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