diff --git a/common/action.c b/common/action.c index 4ef5d791..de79ee0b 100644 --- a/common/action.c +++ b/common/action.c @@ -43,6 +43,8 @@ void action_exec(keyevent_t event) keyrecord_t record = { .event = event }; + key_event(event); + #ifndef NO_ACTION_TAPPING action_tapping_process(record); #else diff --git a/common/action.h b/common/action.h index 077711c2..5cac78d5 100644 --- a/common/action.h +++ b/common/action.h @@ -66,6 +66,7 @@ void clear_keyboard(void); void clear_keyboard_but_mods(void); void layer_switch(uint8_t new_layer); bool is_tap_key(key_t key); +void key_event(keyevent_t event); /* debug */ void debug_event(keyevent_t event); diff --git a/common/softpwm_led.c b/common/softpwm_led.c index d21c0357..fe689bcb 100644 --- a/common/softpwm_led.c +++ b/common/softpwm_led.c @@ -111,11 +111,15 @@ inline uint8_t softpwm_led_get_state(void) * Table[floor((exp(sin(x/256*2*pi+3/2*pi))-1/e)*(256/(e-1/e))), {x,0,255,1}] * (0..255).each {|x| print ((exp(sin(x/256.0*2*PI+3.0/2*PI))-1/E)*(256/(E-1/E))).to_i, ', ' } */ -static const uint8_t breathing_table[256] PROGMEM = { -0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 32, 34, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 56, 58, 61, 63, 66, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 102, 105, 108, 112, 116, 119, 123, 126, 130, 134, 138, 142, 145, 149, 153, 157, 161, 165, 169, 173, 176, 180, 184, 188, 192, 195, 199, 203, 206, 210, 213, 216, 219, 223, 226, 228, 231, 234, 236, 239, 241, 243, 245, 247, 248, 250, 251, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 254, 253, 252, 251, 250, 248, 247, 245, 243, 241, 239, 236, 234, 231, 228, 226, 223, 219, 216, 213, 210, 206, 203, 199, 195, 192, 188, 184, 180, 176, 173, 169, 165, 161, 157, 153, 149, 145, 142, 138, 134, 130, 126, 123, 119, 116, 112, 108, 105, 102, 98, 95, 92, 89, 86, 83, 80, 77, 74, 71, 68, 66, 63, 61, 58, 56, 53, 51, 49, 47, 45, 43, 41, 39, 37, 35, 34, 32, 30, 29, 27, 26, 25, 23, 22, 21, 19, 18, 17, 16, 15, 14, 13, 12, 11, 11, 10, 9, 8, 8, 7, 6, 6, 5, 5, 4, 4, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 +static const uint8_t breathing_table[128] PROGMEM = { +0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 32, 34, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 56, 58, 61, 63, 66, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 102, 105, 108, 112, 116, 119, 123, 126, 130, 134, 138, 142, 145, 149, 153, 157, 161, 165, 169, 173, 176, 180, 184, 188, 192, 195, 199, 203, 206, 210, 213, 216, 219, 223, 226, 228, 231, 234, 236, 239, 241, 243, 245, 247, 248, 250, 251, 252, 253, 254, 255, 255, 255 }; -static led_state_t breathing_led_state = 0; +static led_pack_t breathing_led_state = 0; +static led_pack_t breathing_led_direction = 0; +static led_pack_t breathing_led_rebound_low = 0; +static led_pack_t breathing_led_rebound_high = 0; +static uint8_t breathing_led_index[LED_COUNT] = {0}; static uint8_t breathing_led_duration[LED_COUNT] = {0}; void breathing_led_enable(uint8_t index) @@ -152,12 +156,82 @@ void breathing_led_toggle_all(void) } } +void breathing_led_increase(uint8_t index, uint8_t offset) +{ + if (breathing_led_index[index] + offset > 0x7F) { + breathing_led_index[index] = 0x7F; + if (breathing_led_rebound_high & LED_BIT(index)) { + LED_BIT_SET(breathing_led_direction, index); + } + } + else { + breathing_led_index[index] += offset; + } +} + +void breathing_led_decrease(uint8_t index, uint8_t offset) +{ + if (breathing_led_index[index] < offset) { + breathing_led_index[index] = 0; + if (breathing_led_rebound_low & LED_BIT(index)) { + LED_BIT_CLEAR(breathing_led_direction, index); + } + } + else { + breathing_led_index[index] -= offset; + } +} + +void breathing_led_set_mode(uint8_t index, uint8_t mode) +{ + switch (mode) { + case BREATHING_LED_UP: + breathing_led_index[index] = 0; + LED_BIT_CLEAR(breathing_led_direction, index); + LED_BIT_CLEAR(breathing_led_rebound_low, index); + LED_BIT_CLEAR(breathing_led_rebound_high, index); + break; + case BREATHING_LED_DOWN: + breathing_led_index[index] = 0x7F; + LED_BIT_SET(breathing_led_direction, index); + LED_BIT_CLEAR(breathing_led_rebound_low, index); + LED_BIT_CLEAR(breathing_led_rebound_high, index); + break; + case BREATHING_LED_CYCLE: + breathing_led_index[index] = 0; + LED_BIT_CLEAR(breathing_led_direction, index); + LED_BIT_SET(breathing_led_rebound_low, index); + LED_BIT_SET(breathing_led_rebound_high, index); + } +} + void breathing_led_set_duration(uint8_t index, uint8_t dur) { breathing_led_duration[index] = dur; //dprintf("breathing led set duration: %u\n", breathing_led_duration); } +void breathing_led_increase_all(uint8_t offset) +{ + for (uint8_t i = 0; i < LED_COUNT; i++) { + breathing_led_increase(i, offset); + } +} + +void breathing_led_decrease_all(uint8_t offset) +{ + for (uint8_t i = 0; i < LED_COUNT; i++) { + breathing_led_decrease(i, offset); + } +} + +void breathing_led_set_mode_all(uint8_t mode) +{ + for (uint8_t i = 0; i < LED_COUNT; i++) { + breathing_led_set_mode(i, mode); + } +} + void breathing_led_set_duration_all(uint8_t dur) { for (uint8_t i = 0; i < LED_COUNT; i++) { @@ -191,7 +265,6 @@ ISR(TIMER1_COMPA_vect) #ifdef BREATHING_LED_ENABLE static uint8_t count = 0; - static uint8_t index[LED_COUNT] = {0}; static uint8_t step[LED_COUNT] = {0}; if (breathing_led_state) { if (++count > SOFTPWM_LED_FREQ) { @@ -200,8 +273,13 @@ ISR(TIMER1_COMPA_vect) if (breathing_led_state & LED_BIT(i)) { if (++step[i] > breathing_led_duration[i]) { step[i] = 0; - softpwm_led_ocr_buff[i] = pgm_read_byte(&breathing_table[index[i]]); - index[i]++; + softpwm_led_ocr_buff[i] = pgm_read_byte(&breathing_table[breathing_led_index[i]]); + if (breathing_led_direction & LED_BIT(i)) { + breathing_led_decrease(i, 1); + } + else { + breathing_led_increase(i, 1); + } } } } diff --git a/common/softpwm_led.h b/common/softpwm_led.h index ad95b577..fc4d2757 100644 --- a/common/softpwm_led.h +++ b/common/softpwm_led.h @@ -4,7 +4,6 @@ #include "stdint.h" #include "led.h" -typedef led_pack_t led_state_t; #ifdef SOFTPWM_LED_ENABLE @@ -21,6 +20,12 @@ uint8_t softpwm_led_get_state(void); void softpwm_led_state_change(uint8_t state); #ifdef BREATHING_LED_ENABLE +enum { + BREATHING_LED_NO = 0, + BREATHING_LED_UP, + BREATHING_LED_DOWN, + BREATHING_LED_CYCLE +}; #define breathing_led_init() void breathing_led_enable(uint8_t index); void breathing_led_enable_all(void); @@ -28,8 +33,14 @@ void breathing_led_disable(uint8_t index); void breathing_led_disable_all(void); void breathing_led_toggle(uint8_t index); void breathing_led_toggle_all(void); +void breathing_led_set_mode(uint8_t index, uint8_t mode); void breathing_led_set_duration(uint8_t index, uint8_t dur); +void breathing_led_increase(uint8_t index, uint8_t offset); +void breathing_led_decrease(uint8_t index, uint8_t offset); +void breathing_led_set_mode_all(uint8_t mode); void breathing_led_set_duration_all(uint8_t dur); +void breathing_led_increase_all(uint8_t offset); +void breathing_led_decrease_all(uint8_t offset); #else #define breathing_led_init() #define breathing_led_enable() @@ -38,8 +49,14 @@ void breathing_led_set_duration_all(uint8_t dur); #define breathing_led_disable_all() #define breathing_led_toggle() #define breathing_led_toggle_all() +#define breathing_led_set_mode() #define breathing_led_set_duration() +#define breathing_led_increase() +#define breathing_led_decrease() +#define breathing_led_set_mode_all() #define breathing_led_set_duration_all() +#define breathing_led_increase_all() +#define breathing_led_decrease_all() #endif #else