summaryrefslogtreecommitdiff
path: root/software/rhmixxx
diff options
context:
space:
mode:
Diffstat (limited to 'software/rhmixxx')
-rw-r--r--software/rhmixxx/keypad.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/software/rhmixxx/keypad.c b/software/rhmixxx/keypad.c
index fdb31dd..1e9ca6b 100644
--- a/software/rhmixxx/keypad.c
+++ b/software/rhmixxx/keypad.c
@@ -36,10 +36,10 @@ static struct {
} keypad_state[KEYPAD_NUM_KEYS];
static struct {
- uint16_t delay;
+ uint16_t timebase;
uint16_t cnt;
} led_blink_state[KEYPAD_NUM_KEYS];
-#define KEYPAD_BLINK_DELAY_MULT 64
+#define KEYPAD_BLINK_TIMEBASE_MULT 64
void keypad_init(void)
{
@@ -50,7 +50,7 @@ void keypad_init(void)
keypad_state[i].last_sent = 0;
keypad_state[i].lp_cnt = 0;
- led_blink_state[i].delay = 0;
+ led_blink_state[i].timebase = 0;
led_blink_state[i].cnt = 0;
}
@@ -134,15 +134,54 @@ void keypad_led_toggle(uint8_t led)
}
}
+static uint8_t keypad_led_get_state(uint8_t led)
+{
+ switch(led) {
+ case 0:
+ case 1:
+ case 2:
+ case 3:
+ case 4:
+ case 5:
+ case 6:
+ case 7: return (PORTC & (1 << led)) ? 1 : 0;
+ case 8:
+ case 9:
+ case 10:
+ case 11: return (PORTB & (1 << (led - 8 + 4))) ? 1 : 0;
+ case 12:
+ case 13:
+ case 14:
+ case 15: return (PORTD & (1 << (led - 12 + 4))) ? 1 : 0;
+ default: return 0;
+ }
+}
+
+static void keypad_led_blink_sync(uint8_t led)
+{
+ uint8_t i;
+ for(i = 0; i < KEYPAD_NUM_KEYS; ++i) {
+ if(i != led && led_blink_state[i].timebase == led_blink_state[led].timebase) {
+ led_blink_state[led].cnt = led_blink_state[i].cnt;
+ if(keypad_led_get_state(led) != keypad_led_get_state(i))
+ keypad_led_toggle(led);
+ break;
+ }
+ }
+}
+
void keypad_led_blink(uint8_t led, uint8_t value)
{
if(led < KEYPAD_NUM_KEYS) {
- led_blink_state[led].delay = value * KEYPAD_BLINK_DELAY_MULT;
+ led_blink_state[led].timebase = value * KEYPAD_BLINK_TIMEBASE_MULT;
led_blink_state[led].cnt = 0;
+ if(value)
+ keypad_led_blink_sync(led);
+
} else {
uint8_t i;
for(i = 0; i < KEYPAD_NUM_KEYS; ++i) {
- led_blink_state[i].delay = value * KEYPAD_BLINK_DELAY_MULT;
+ led_blink_state[i].timebase = value * KEYPAD_BLINK_TIMEBASE_MULT;
led_blink_state[i].cnt = 0;
}
}
@@ -165,8 +204,8 @@ static inline 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) {
+ if(led_blink_state[key_idx].timebase > 1) {
+ if(++led_blink_state[key_idx].cnt >= led_blink_state[key_idx].timebase) {
keypad_led_toggle(key_idx);
led_blink_state[key_idx].cnt = 0;
}