summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2014-06-01 18:45:33 (GMT)
committerChristian Pointner <equinox@helsinki.at>2014-06-01 18:45:33 (GMT)
commit96e244403e182672ee15706c8419e61a2075fa01 (patch)
tree8b6eaf2bf03a6b6efb59641f3f10cdc3881ad80f
parenta1586f0d7b3490ed3fa2e9c130adeb32b4d0f7d6 (diff)
some cleanup
-rw-r--r--software/rhmixxx/rhmixxx.c81
1 files changed, 46 insertions, 35 deletions
diff --git a/software/rhmixxx/rhmixxx.c b/software/rhmixxx/rhmixxx.c
index 79a3e48..1a10a03 100644
--- a/software/rhmixxx/rhmixxx.c
+++ b/software/rhmixxx/rhmixxx.c
@@ -75,18 +75,27 @@ void EVENT_USB_Device_ControlRequest(void)
#include "keypad.h"
#include "eventqueue.h"
-int main(void)
+static void process_incoming_midi(void)
{
- MCUSR &= ~(1 << WDRF);
- wdt_disable();
-
- cpu_init();
- eventqueue_init();
- keypad_init();
-
- USB_Init();
- sei();
+ MIDI_EventPacket_t ReceivedMIDIEvent;
+ while(MIDI_Device_ReceiveEventPacket(&MIDI_Interface, &ReceivedMIDIEvent)) {
+ uint8_t cmd = ReceivedMIDIEvent.Data1 & 0xF0;
+ uint8_t note = ReceivedMIDIEvent.Data2;
+ uint8_t value = ReceivedMIDIEvent.Data3 & 0x7F;
+ if(note < 16 || note == 0x7F) { // TODO: hardcoded value
+ if(cmd == MIDI_COMMAND_NOTE_ON) {
+ switch(value) {
+ case 0: keypad_led_off(note); break;
+ case 1: keypad_led_on(note); break;
+ case 2: keypad_led_toggle(note); break;
+ }
+ }
+ }
+ }
+}
+static void process_outgoing_midi(void)
+{
MIDI_EventPacket_t MIDIEventOn = (MIDI_EventPacket_t)
{
.CableNumber = 0, // TODO: hardcoded value
@@ -104,34 +113,36 @@ int main(void)
.Data3 = 0,
};
- for(;;) {
- MIDI_EventPacket_t ReceivedMIDIEvent;
- while(MIDI_Device_ReceiveEventPacket(&MIDI_Interface, &ReceivedMIDIEvent)) {
- uint8_t cmd = ReceivedMIDIEvent.Data1 & 0xF0;
- uint8_t note = ReceivedMIDIEvent.Data2;
- uint8_t value = ReceivedMIDIEvent.Data3 & 0x7F;
- if(note < 16 || note == 0x7F) { // TODO: hardcoded value
- if(cmd == MIDI_COMMAND_NOTE_ON) {
- switch(value) {
- case 0: keypad_led_off(note); break;
- case 1: keypad_led_on(note); break;
- case 2: keypad_led_toggle(note); break;
- }
- }
- }
+ uint8_t key, state;
+ while(eventqueue_pop(&key, &state)) {
+ if (USB_DeviceState == DEVICE_STATE_Configured) {
+ MIDI_EventPacket_t* MIDIEvent = state ? &MIDIEventOn : &MIDIEventOff;
+ MIDIEvent->Data2 = key;
+ MIDI_Device_SendEventPacket(&MIDI_Interface, MIDIEvent);
}
+ }
+ if (USB_DeviceState == DEVICE_STATE_Configured)
+ MIDI_Device_Flush(&MIDI_Interface);
+}
+
+int main(void)
+{
+ MCUSR &= ~(1 << WDRF);
+ wdt_disable();
+
+ cpu_init();
+ eventqueue_init();
+ keypad_init();
+
+ USB_Init();
+ sei();
+
+ for(;;) {
+ process_incoming_midi();
+
keypad_task();
- uint8_t key, state;
- while(eventqueue_pop(&key, &state)) {
- if (USB_DeviceState == DEVICE_STATE_Configured) {
- MIDI_EventPacket_t* MIDIEvent = state ? &MIDIEventOn : &MIDIEventOff;
- MIDIEvent->Data2 = key;
- MIDI_Device_SendEventPacket(&MIDI_Interface, MIDIEvent);
- }
- }
- if (USB_DeviceState == DEVICE_STATE_Configured)
- MIDI_Device_Flush(&MIDI_Interface);
+ process_outgoing_midi();
MIDI_Device_USBTask(&MIDI_Interface);
USB_USBTask();