Well, my project is pretty simple and straightforward.
It is not for a midibox, it just uses the hardware as a switch for my amplifier’s channels.
I wanted to control :
* 4 relays that controll optocouplers (circuit
* 4 LEDs (channel indicator on frontpanel)
* (1 relay and one LED is on at a time - 4 total channels)
and to control them with:
* 4 buttons (amp frontpanel)
* midi Program Change messages 1-4 (floorboard)
midio128 firmware was not adequate because of the inconsistency between midi and the frontpanel buttons.
My main.c changes consist of:
void Init(void) __wparam
{
// **On Powerup** //
// set shift register update frequency
MIOS_SRIO_UpdateFrqSet(1); // ms
// only one DOUTX4 module is connected
MIOS_SRIO_NumberSet(1);
// debouncing value for DINs
MIOS_SRIO_DebounceSet(20);
// turn channel 1 on on powerup
MIOS_DOUT_PinSet(0x07, 1);
MIOS_DOUT_PinSet(0x00, 1);
// and transmit program change 1 for consistency with pedalboard
MIOS_MIDI_TxBufferPut(0xc0);
MIOS_MIDI_TxBufferPut(0x00);
}
void MPROC_NotifyReceivedEvnt(unsigned char evnt0, unsigned char evnt1, unsigned char evnt2) __wparam
{
// **On MIDI Recieve** //
//only work if Program Change is received on channel 1
if( evnt0 == 0xc0) {
//only work if Program Change 1,2,3 or 4 is recieved
if(evnt1 == 0x00 || evnt1 == 0x01 || evnt1 == 0x02 || evnt1 == 0x03) {
//reset all pins
MIOS_DOUT_PinSet(0x00, 0);
MIOS_DOUT_PinSet(0x01, 0);
MIOS_DOUT_PinSet(0x02, 0);
MIOS_DOUT_PinSet(0x03, 0);
MIOS_DOUT_PinSet(0x04, 0);
MIOS_DOUT_PinSet(0x05, 0);
MIOS_DOUT_PinSet(0x06, 0);
MIOS_DOUT_PinSet(0x07, 0);
//activate the recieved program change's pin to control the relay
MIOS_DOUT_PinSet(evnt1, 1);
//the following code is a strange workaround for my peculiar wiring of the leds
if(evnt1 == 0x00) {
evnt1 = 0x07;
}
if(evnt1 == 0x01) {
evnt1 = 0x04;
}
if(evnt1 == 0x02) {
evnt1 = 0x05;
}
if(evnt1 == 0x03) {
evnt1 = 0x06;
}
//set the correct LED on
MIOS_DOUT_PinSet(evnt1, 1);
}
}
}
void DIN_NotifyToggle(unsigned char pin, unsigned char pin_value) __wparam
{
// **On Button Press** //
//Only parse if button is pressed, not released
if (!pin_value) {
MIOS_MIDI_TxBufferPut(0xc0); // Program Change at channel #1
MIOS_MIDI_TxBufferPut(pin); // just forward the pin number (0-3)
//Reset relays and LEDs
MIOS_DOUT_PinSet(0x00, 0);
MIOS_DOUT_PinSet(0x01, 0);
MIOS_DOUT_PinSet(0x02, 0);
MIOS_DOUT_PinSet(0x03, 0);
MIOS_DOUT_PinSet(0x04, 0);
MIOS_DOUT_PinSet(0x05, 0);
MIOS_DOUT_PinSet(0x06, 0);
MIOS_DOUT_PinSet(0x07, 0);
// Turn Relay ON
MIOS_DOUT_PinSet(pin, 1);
// Same workaround for my peculiar led wiring
if(pin == 0x00) {
pin = 0x07;
}
if(pin == 0x01) {
pin = 0x04;
}
if(pin == 0x02) {
pin = 0x05;
}
if(pin == 0x03) {
pin = 0x06;
}
//turn the correct LED on
MIOS_DOUT_PinSet(pin, 1);
}
}
I know my code could be simpler but this is a proof that one should not be afraid to use the C wrapper if his C skills are not that good!
My app works fine and I hope that my amp will switch fine soon too !!!