Chris Arndt / Mbed OS STM32F103_USBMIDI_Switchbox

Dependencies:   PinDetect USBDevice_STM32F103 mbed-STM32F103C8T6

midiswitch.cpp

Committer:
SpotlightKid
Date:
2017-08-04
Revision:
7:553836a26221
Parent:
6:2f804d29cbb0
Child:
8:75c5ec68765e

File content as of revision 7:553836a26221:

#include "mbed.h"
#include "midiswitch.h"

SwitchHandler::SwitchHandler(EventQueue * queue, MIDI_CB cb, SwitchConfig * sw) :
    queue(queue), write_cb(cb), btn(sw->pin), control(sw->control), channel(sw->channel), on_value(sw->on_value), off_value(sw->off_value) {
    btn.mode(Pullup);
    btn.setAssertValue(0);
    btn.attach_asserted(this, &SwitchHandler::handle_pressed);
    btn.attach_deasserted(this, &SwitchHandler::handle_released);
    btn.setSampleFrequency();
};

void SwitchHandler::handle_pressed(void) {
    queue->call(write_cb, MIDIMessage::ControlChange((int) control, (int) on_value, (int) (channel - 1)));
};

void SwitchHandler::handle_released(void) {
    queue->call(write_cb, MIDIMessage::ControlChange((int) control, (int) off_value, (int) (channel - 1)));
};