Control Surface  1.2.0
MIDI Control Surface library for Arduino
DebugMIDI_Interface.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <ctype.h>
5 
7 
15  public:
23 
24  MIDIReadEvent read() override;
25 
26  protected:
27  void sendImpl(uint8_t header, uint8_t d1, uint8_t d2, uint8_t cn) override;
28 
29  void sendImpl(uint8_t header, uint8_t d1, uint8_t cn) override;
30 
31  void sendImpl(const uint8_t *data, size_t length, uint8_t cn) override;
32 
33  void sendImpl(uint8_t rt, uint8_t cn) override;
34 
35  private:
36  char firstChar = '\0';
37  char secondChar = '\0';
38 
42  static uint8_t hexCharToNibble(char hex) {
43  return hex < 'a' ? hex - '0' : hex - 'a' + 10;
44  }
45 };
46 
57 template <typename T>
59  public:
70  unsigned long baud = AH::defaultBaudRate)
75  void begin() override { serial.begin(baud); }
76 
77  private:
78  T &serial;
79  const unsigned long baud;
80 };
81 
89  : public SerialDebugMIDI_Interface<HardwareSerial> {
90  public:
101  unsigned long baud = AH::defaultBaudRate)
103 };
104 
115  : public SerialDebugMIDI_Interface<decltype(Serial)> {
116  public:
124  : SerialDebugMIDI_Interface(Serial, baud) {}
125 };
126 
127 // TODO: Teensy 4.0 SoftwareSerial bug
128 #if defined(__AVR__) || (defined(TEENSYDUINO) && TEENSYDUINO != 147) || \
129  (defined(TEENSYDUINO) && !defined(__IMXRT1052__) && \
130  !defined(__IMXRT1062__))
131 #include <SoftwareSerial.h>
139  : public SerialDebugMIDI_Interface<SoftwareSerial> {
140  public:
151  unsigned long baud)
153 };
154 #endif
155 
StreamMIDI_Interface::stream
Stream & stream
Definition: SerialMIDI_Interface.hpp:91
StreamDebugMIDI_Interface::sendImpl
void sendImpl(uint8_t header, uint8_t d1, uint8_t d2, uint8_t cn) override
Low-level function for sending a 3-byte MIDI message.
Definition: DebugMIDI_Interface.cpp:77
SerialDebugMIDI_Interface::serial
T & serial
Definition: DebugMIDI_Interface.hpp:78
SerialDebugMIDI_Interface
A wrapper class for debug MIDI interfaces sending and receiving human-readable MIDI messages over a S...
Definition: DebugMIDI_Interface.hpp:58
HardwareSerialDebugMIDI_Interface
A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over a HardwareS...
Definition: DebugMIDI_Interface.hpp:89
SerialMIDI_Interface.hpp
StreamDebugMIDI_Interface::hexCharToNibble
static uint8_t hexCharToNibble(char hex)
Convert a hexadecimal character to a 4-bit nibble.
Definition: DebugMIDI_Interface.hpp:42
BEGIN_CS_NAMESPACE
#define BEGIN_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:9
END_CS_NAMESPACE
#define END_CS_NAMESPACE
Definition: Settings/NamespaceSettings.hpp:10
SerialDebugMIDI_Interface::SerialDebugMIDI_Interface
SerialDebugMIDI_Interface(T &serial, unsigned long baud=AH::defaultBaudRate)
Construct a new Debug MIDI Interface on the given Serial interface with the given baud rate.
Definition: DebugMIDI_Interface.hpp:69
USBDebugMIDI_Interface::USBDebugMIDI_Interface
USBDebugMIDI_Interface(unsigned long baud=AH::defaultBaudRate)
Construct a USBDebugMIDI_Interface with the given baud rate.
Definition: DebugMIDI_Interface.hpp:123
StreamDebugMIDI_Interface::secondChar
char secondChar
Definition: DebugMIDI_Interface.hpp:37
AH::defaultBaudRate
constexpr unsigned long defaultBaudRate
The default baud rate for debug output.
Definition: AH/Settings/Settings.hpp:36
StreamDebugMIDI_Interface::StreamDebugMIDI_Interface
StreamDebugMIDI_Interface(Stream &stream)
Construct a debug MIDI interface on the given Stream.
Definition: DebugMIDI_Interface.hpp:22
StreamDebugMIDI_Interface::firstChar
char firstChar
Definition: DebugMIDI_Interface.hpp:36
SerialDebugMIDI_Interface::baud
const unsigned long baud
Definition: DebugMIDI_Interface.hpp:79
AH::hex
Print & hex(Print &printer)
Definition: PrintStream.cpp:62
StreamDebugMIDI_Interface::read
MIDIReadEvent read() override
Try reading and parsing a single incoming MIDI message.
Definition: DebugMIDI_Interface.cpp:40
SerialDebugMIDI_Interface::begin
void begin() override
Start the Serial interface at the predefined baud rate.
Definition: DebugMIDI_Interface.hpp:75
StreamDebugMIDI_Interface
A class for MIDI interfaces sending and receiving human-readable MIDI messages over a Stream.
Definition: DebugMIDI_Interface.hpp:14
SoftwareSerialDebugMIDI_Interface
A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over a SoftwareS...
Definition: DebugMIDI_Interface.hpp:139
MIDIReadEvent
MIDIReadEvent
Result of the MIDI interface read methods.
Definition: MIDI_Parser.hpp:15
SoftwareSerialDebugMIDI_Interface::SoftwareSerialDebugMIDI_Interface
SoftwareSerialDebugMIDI_Interface(SoftwareSerial &serial, unsigned long baud)
Construct a SoftwareSerialDebugMIDI_Interface on the given SoftwareSerial interface with the given ba...
Definition: DebugMIDI_Interface.hpp:150
StreamMIDI_Interface
A class for MIDI interfaces sending and receiving MIDI messages over a Stream.
Definition: SerialMIDI_Interface.hpp:22
USBDebugMIDI_Interface
A class for debug MIDI interfaces sending and receiving human-readable MIDI messages over the USB CDC...
Definition: DebugMIDI_Interface.hpp:115
HardwareSerialDebugMIDI_Interface::HardwareSerialDebugMIDI_Interface
HardwareSerialDebugMIDI_Interface(HardwareSerial &serial, unsigned long baud=AH::defaultBaudRate)
Construct a new Debug MIDI Interface on the given HardwareSerial interface with the given baud rate.
Definition: DebugMIDI_Interface.hpp:100