diff options
Diffstat (limited to 'software/rhmixxx')
-rw-r--r-- | software/rhmixxx/keypad.c | 38 | ||||
-rw-r--r-- | software/rhmixxx/keypad.h | 7 | ||||
-rw-r--r-- | software/rhmixxx/rhmixxx.c | 12 |
3 files changed, 49 insertions, 8 deletions
diff --git a/software/rhmixxx/keypad.c b/software/rhmixxx/keypad.c index 7a58ad0..6bdb01f 100644 --- a/software/rhmixxx/keypad.c +++ b/software/rhmixxx/keypad.c @@ -38,6 +38,11 @@ static struct { int16_t lp_cnt; } keypad_state[KEYPAD_NUM_KEYS]; +static struct { + uint16_t delay; + uint16_t cnt; +} led_blink_state[KEYPAD_NUM_KEYS]; + void keypad_init(void) { KEYPAD_DDR = 0x00; @@ -46,6 +51,9 @@ void keypad_init(void) for(i = 0; i < KEYPAD_NUM_KEYS; ++i) { keypad_state[i].last_sent = 0; keypad_state[i].lp_cnt = 0; + + led_blink_state[i].delay = 0; + led_blink_state[i].cnt = 0; } DDRC = 0xFF; @@ -78,6 +86,7 @@ void keypad_led_on(uint8_t led) case 15: PORTD |= (1 << (led - 12 + 4)); break; case 127: PORTC = 0xFF; PORTB |= 0xF0; PORTD |= 0xF0; break; } + keypad_led_blink(led, 0); } void keypad_led_off(uint8_t led) @@ -101,6 +110,7 @@ void keypad_led_off(uint8_t led) case 15: PORTD &= ~(1 << (led - 12 + 4)); break; case 127: PORTC = 0x00; PORTB &= 0x0F; PORTD &= 0x0F; break; } + keypad_led_blink(led, 0); } void keypad_led_toggle(uint8_t led) @@ -126,7 +136,21 @@ void keypad_led_toggle(uint8_t led) } } -static void keypad_key_lowpass(uint8_t key_idx, uint8_t current_state) +void keypad_led_blink(uint8_t led, uint8_t value) +{ + if(led < KEYPAD_NUM_KEYS) { + led_blink_state[led].delay = value * 64; + led_blink_state[led].cnt = 0; + } else { + uint8_t i; + for(i = 0; i < KEYPAD_NUM_KEYS; ++i) { + led_blink_state[i].delay = value * 64; + led_blink_state[i].cnt = 0; + } + } +} + +static inline void keypad_key_lowpass(uint8_t key_idx, uint8_t current_state) { keypad_state[key_idx].lp_cnt += current_state ? -1 : +1; if(keypad_state[key_idx].lp_cnt <= 0 || @@ -146,6 +170,16 @@ static void keypad_key_lowpass(uint8_t key_idx, uint8_t current_state) } } +static inline void keypad_led_blinking(uint8_t key_idx) +{ + if(led_blink_state[key_idx].delay > 1) { + if(++led_blink_state[key_idx].cnt >= led_blink_state[key_idx].delay) { + keypad_led_toggle(key_idx); + led_blink_state[key_idx].cnt = 0; + } + } +} + void keypad_task(void) { uint8_t col, row; @@ -159,6 +193,8 @@ void keypad_task(void) uint8_t current_state = KEYPAD_PIN & (1 << row); keypad_key_lowpass(key_idx, current_state); + + keypad_led_blinking(key_idx); } } KEYPAD_DDR = 0x00; diff --git a/software/rhmixxx/keypad.h b/software/rhmixxx/keypad.h index efd8a87..92c4188 100644 --- a/software/rhmixxx/keypad.h +++ b/software/rhmixxx/keypad.h @@ -24,9 +24,10 @@ void keypad_init(void); -void keypad_led_on(uint8_t leds); -void keypad_led_off(uint8_t leds); -void keypad_led_toggle(uint8_t leds); +void keypad_led_on(uint8_t led); +void keypad_led_off(uint8_t led); +void keypad_led_toggle(uint8_t led); +void keypad_led_blink(uint8_t led, uint8_t value); void keypad_task(void); diff --git a/software/rhmixxx/rhmixxx.c b/software/rhmixxx/rhmixxx.c index 1a10a03..4e591d6 100644 --- a/software/rhmixxx/rhmixxx.c +++ b/software/rhmixxx/rhmixxx.c @@ -84,10 +84,14 @@ static void process_incoming_midi(void) 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;
+ if(value <= 2) {
+ switch(value) {
+ case 0: keypad_led_off(note); break;
+ case 1: keypad_led_on(note); break;
+ case 2: keypad_led_toggle(note); break;
+ }
+ } else if(value <= 0x7F) {
+ keypad_led_blink(note, value);
}
}
}
|