From 55ab6ba1122ed2c04596feea6c94ea056da825a3 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 3 Jun 2014 15:40:33 +0000 Subject: enable and disable analog channel via midi works now diff --git a/software/rhmixxx/Makefile b/software/rhmixxx/Makefile index ae51e01..60531a5 100644 --- a/software/rhmixxx/Makefile +++ b/software/rhmixxx/Makefile @@ -41,5 +41,3 @@ LUFA_OPTS += -D USB_PRODUCT="L\"rhmixxx midi controller\"" -D USB_PRODUCT_LEN=23 LUFA_COMPONENTS := USB USBCLASS SERIAL include ../include.mk - -CFLAGS += -DDISABLE_ANALOG diff --git a/software/rhmixxx/analog.c b/software/rhmixxx/analog.c index e15c2eb..5ddd20f 100644 --- a/software/rhmixxx/analog.c +++ b/software/rhmixxx/analog.c @@ -27,56 +27,81 @@ #define ANALOG_PORT PORTF #define ANALOG_DDR DDRF -#ifndef DISABLE_ANALOG - #include -uint8_t analog_last_sent[ANALOG_NUM_INPUTS]; + +static struct { + uint8_t enabled; + uint8_t last_sent; +} analog_input_state[ANALOG_NUM_INPUTS]; + static uint8_t analog_channels[] = { ADC_CHANNEL0, ADC_CHANNEL1, ADC_CHANNEL2, ADC_CHANNEL3, ADC_CHANNEL4, ADC_CHANNEL5, ADC_CHANNEL6, ADC_CHANNEL7 }; -#endif - void analog_init(void) { ANALOG_DDR = 0x00; ANALOG_PORT = 0x00; -#ifndef DISABLE_ANALOG int i; - for(i = 0; i < ANALOG_NUM_INPUTS; ++i) - analog_last_sent[i] = 0; + for(i = 0; i < ANALOG_NUM_INPUTS; ++i) { + analog_input_state[i].enabled = 0; + analog_input_state[i].last_sent = 0; + } - ADC_Init(ADC_SINGLE_CONVERSION | ADC_PRESCALE_2); - ADC_SetupChannel(ADC_CHANNEL0); - ADC_SetupChannel(ADC_CHANNEL1); - ADC_SetupChannel(ADC_CHANNEL2); - ADC_SetupChannel(ADC_CHANNEL3); - ADC_SetupChannel(ADC_CHANNEL4); - ADC_SetupChannel(ADC_CHANNEL5); - ADC_SetupChannel(ADC_CHANNEL6); - ADC_SetupChannel(ADC_CHANNEL7); -#endif + ADC_Init(ADC_SINGLE_CONVERSION | ADC_PRESCALE_32); } -uint8_t analog_get_value(uint8_t channel) +static void analog_channel_set_enabled(uint8_t channel, uint8_t enabled) +{ + if(enabled) { + ADC_SetupChannel(channel); + analog_input_state[channel].enabled = 1; + } else { + ADC_DisableChannel(channel); + analog_input_state[channel].enabled = 0; + } +} + +void analog_enable_channel(uint8_t channel) { -#ifndef DISABLE_ANALOG if(channel < ANALOG_NUM_INPUTS) - return analog_last_sent[channel]; -#endif - return 0; + analog_channel_set_enabled(channel, 1); + else if(channel == ANALOG_MIDI_NOTE_ALL_INPUTS - ANALOG_MIDI_NOTE_OFFSET) { + int i; + for(i = 0; i < ANALOG_NUM_INPUTS; ++i) + analog_channel_set_enabled(i, 1); + } +} + +void analog_disable_channel(uint8_t channel) +{ + if(channel < ANALOG_NUM_INPUTS) + analog_channel_set_enabled(channel, 0); + else if(channel == ANALOG_MIDI_NOTE_ALL_INPUTS - ANALOG_MIDI_NOTE_OFFSET) { + int i; + for(i = 0; i < ANALOG_NUM_INPUTS; ++i) + analog_channel_set_enabled(i, 0); + } +} + +uint8_t analog_get_value(uint8_t channel) +{ + if(channel >= ANALOG_NUM_INPUTS) + return 0; + + return analog_input_state[channel].last_sent; } void analog_task(void) { -#ifndef DISABLE_ANALOG uint8_t i; for(i = 0; i < ANALOG_NUM_INPUTS; ++i) { - uint8_t tmp = (ADC_GetChannelReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | analog_channels[i])) >> 3; - if(analog_last_sent[i] != tmp) { - analog_last_sent[i] = tmp; - eventqueue_push(ANALOG_MIDI_NOTE_OFFSET + i, 0); + if(analog_input_state[i].enabled) { + uint8_t tmp = (ADC_GetChannelReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | analog_channels[i])) >> 3; + if(analog_input_state[i].last_sent != tmp) { + analog_input_state[i].last_sent = tmp; + eventqueue_push(ANALOG_MIDI_NOTE_OFFSET + i, 0); + } } } -#endif } diff --git a/software/rhmixxx/analog.h b/software/rhmixxx/analog.h index 4c98157..d72be94 100644 --- a/software/rhmixxx/analog.h +++ b/software/rhmixxx/analog.h @@ -24,8 +24,11 @@ #define ANALOG_NUM_INPUTS 8 #define ANALOG_MIDI_NOTE_OFFSET 64 +#define ANALOG_MIDI_NOTE_ALL_INPUTS ANALOG_MIDI_NOTE_OFFSET + 31 void analog_init(void); +void analog_enable_channel(uint8_t channel); +void analog_disable_channel(uint8_t channel); uint8_t analog_get_value(uint8_t channel); void analog_task(void); diff --git a/software/rhmixxx/rhmixxx.c b/software/rhmixxx/rhmixxx.c index f77c23a..a9d3fcc 100644 --- a/software/rhmixxx/rhmixxx.c +++ b/software/rhmixxx/rhmixxx.c @@ -103,6 +103,14 @@ static void process_incoming_midi(void) case 2: gpio_out_toggle(note - GPIO_MIDI_NOTE_OFFSET); break; } } + } else if((note >= ANALOG_MIDI_NOTE_OFFSET && note < ANALOG_MIDI_NOTE_OFFSET + ANALOG_NUM_INPUTS) || // ANALOG + note == ANALOG_MIDI_NOTE_ALL_INPUTS) { + if(cmd == MIDI_COMMAND_NOTE_ON) { + switch(value) { + case 0: analog_disable_channel(note - ANALOG_MIDI_NOTE_OFFSET); break; + case 1: analog_enable_channel(note - ANALOG_MIDI_NOTE_OFFSET); break; + } + } } } } -- cgit v0.10.2