Target detection and simplified auto-instanciation.

This commit is contained in:
Francois Best 2012-10-02 21:51:18 +02:00
parent 39a9c3eb2d
commit 691b172187
4 changed files with 22 additions and 31 deletions

View File

@ -25,28 +25,11 @@
// -----------------------------------------------------------------------------
#if MIDI_AUTO_INSTANCIATE
# if MIDI_USE_SOFTWARE_SERIAL
# ifndef FSE_AVR
# include "../SoftwareSerial/SoftwareSerial.h"
SoftwareSerial softSerialClass(MIDI_SOFTSERIAL_RX_PIN,
MIDI_SOFTSERIAL_TX_PIN);
# else
# error Todo: implement SoftwareSerial for avr core.
# endif
# undef MIDI_SERIAL_PORT
# define MIDI_SERIAL_PORT softSerialClass
MIDI_NAMESPACE::MidiInterface<SoftwareSerial> MIDI(MIDI_SERIAL_PORT);
# else
# ifdef FSE_AVR
# include <hardware_Serial.h>
# else
# include "HardwareSerial.h"
# endif
MIDI_NAMESPACE::MidiInterface<HardwareSerial> MIDI((HardwareSerial&)Serial);
# endif // MIDI_USE_SOFTWARE_SERIAL
#endif // MIDI_AUTO_INSTANCIATE
#if MIDI_AUTO_INSTANCIATE && defined(ARDUINO)
MIDI_CREATE_INSTANCE(MIDI_DEFAULT_SERIAL_CLASS,
MIDI_DEFAULT_SERIAL_PORT,
MIDI);
#endif
// -----------------------------------------------------------------------------

View File

@ -225,8 +225,8 @@ END_MIDI_NAMESPACE
// -----------------------------------------------------------------------------
#if MIDI_AUTO_INSTANCIATE
extern MIDI_NAMESPACE::MidiInterface<MIDI_SERIAL_CLASS> MIDI;
#if MIDI_AUTO_INSTANCIATE && defined(ARDUINO)
extern MIDI_NAMESPACE::MidiInterface<MIDI_DEFAULT_SERIAL_CLASS> MIDI;
#endif // MIDI_AUTO_INSTANCIATE
// -----------------------------------------------------------------------------

View File

@ -14,7 +14,9 @@
// -----------------------------------------------------------------------------
#ifdef FSE_AVR
#if defined(ARDUINO)
# include <inttypes.h>
#elif defined(FSE_AVR)
# include <core_Types.h>
#else
# include <inttypes.h>

View File

@ -23,7 +23,7 @@
// Compilation flags. Set them to 1 to build the associated feature
// (MIDI in, out, thru), or to 0 to disable the feature and save space.
// Note that the Thru can only work if in and out are enabled.
// Note that thru can work only if input and output are enabled.
#define MIDI_BUILD_INPUT 1
#define MIDI_BUILD_OUTPUT 1
@ -37,8 +37,10 @@
// You can turn this off by adding #define MIDI_AUTO_INSTANCIATE 0 just before
// including <MIDI.h> in your sketch.
#ifndef MIDI_AUTO_INSTANCIATE
# ifndef FSE_AVR
# ifdef ARDUINO
# define MIDI_AUTO_INSTANCIATE 1
# else
# define MIDI_AUTO_INSTANCIATE 0 ///< @see MIDI_CREATE_INSTANCE
# endif
#endif
@ -47,10 +49,14 @@
// Set the default port to use for MIDI.
#if MIDI_AUTO_INSTANCIATE
# define MIDI_DEFAULT_SERIAL_PORT Serial
# define MIDI_SERIAL_CLASS HardwareSerial
# include "Arduino.h"
# include "HardwareSerial.h"
# ifdef ARDUINO
# define MIDI_DEFAULT_SERIAL_PORT Serial
# define MIDI_DEFAULT_SERIAL_CLASS HardwareSerial
# include "Arduino.h"
# include "HardwareSerial.h"
# else
# error Auto-instanciation disabled. Use MIDI_CREATE_INSTANCE macro.
# endif
#endif
// -----------------------------------------------------------------------------