Skip to content

Commit

Permalink
Switch to DIN-5 only mode on USB disconnect / suspend.
Browse files Browse the repository at this point in the history
  • Loading branch information
gtrainavicius committed Jul 16, 2019
1 parent d91226e commit f41b388
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
9 changes: 7 additions & 2 deletions midimon.cpp
Expand Up @@ -97,6 +97,11 @@ void Midimon::switchMode(uint8_t modeId)
getActiveMode()->onEnter(this);
}

void Midimon::setUsbSuspended(bool suspended)
{
m_isUsbSuspended = suspended;
}

void Midimon::setProcessFunction(midimon_process_fn fn)
{
m_processFn = fn;
Expand Down Expand Up @@ -131,7 +136,7 @@ void Midimon::setInterfaceMode(MidimonInterfaceMode mode)

MidimonInterfaceMode Midimon::getInterfaceMode() const
{
return m_mode;
return m_isUsbSuspended ? MODE_DIN5_ONLY : m_mode;
}

void Midimon::runModalMode(IMidimonModalMode &mode)
Expand Down Expand Up @@ -212,7 +217,7 @@ void Midimon::handleOutgoing(MidimonPort dst, const midi_event_t &event)
void Midimon::poll()
{
Midiboy.think();
switch (m_mode)
switch (getInterfaceMode())
{
case MODE_DIN5_ONLY:
process(PORT_DIN5, PORT_DIN5, Serial, Serial, m_serializerDIN5);
Expand Down
5 changes: 5 additions & 0 deletions midimon.h
Expand Up @@ -66,6 +66,7 @@ class Midimon
:m_display(display)
,m_serializerDIN5(0)
,m_serializerUSB(0)
,m_isUsbSuspended(false)
{
init(modes, count);
}
Expand All @@ -74,10 +75,12 @@ class Midimon
:m_display(display)
,m_serializerDIN5(0)
,m_serializerUSB(0)
,m_isUsbSuspended(false)
{
init(modes, count);
}

void setUsbSuspended(bool suspended);
void setProcessFunction(midimon_process_fn fn);

void begin();
Expand Down Expand Up @@ -118,6 +121,8 @@ class Midimon
MidimonInterfaceMode m_mode;
MidiToUsb m_serializerDIN5;
MidiToUsb m_serializerUSB;

bool m_isUsbSuspended;
};

#endif // MIDIMON_H
6 changes: 6 additions & 0 deletions midimon.ino
Expand Up @@ -32,6 +32,11 @@ MODES_END()

Midimon midimon(Midiboy, modes);

void onUsbSuspended(bool suspended)
{
midimon.setUsbSuspended(suspended);
}

bool midimon_process(MidimonPort src, MidimonPort dst, u8 msg[3], u8 n)
{
return true;
Expand All @@ -41,6 +46,7 @@ void setup()
{
midimon.setProcessFunction(&midimon_process);
midimon.begin();
USBMIDI.setSuspendResumeCallback(&onUsbSuspended);
}

void loop()
Expand Down

0 comments on commit f41b388

Please sign in to comment.