From 3169a499a2d51d53843b65770d93d3fbbb75552a Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 25 Jun 2022 18:37:15 -0700 Subject: [PATCH] Added basic spectrum code --- keymaps/default/keymap.c | 83 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/keymaps/default/keymap.c b/keymaps/default/keymap.c index a7bd9d5..b817c87 100644 --- a/keymaps/default/keymap.c +++ b/keymaps/default/keymap.c @@ -1,15 +1,90 @@ #include "keymap.h" -#include "layers.h" -#include "tapdance.h" -#include "raw_hid.h" + +// -1 => skip +int8_t col_to_array[10][5] = { + { 47, 43, 38, 33, 28 }, + { 46, 42, 37, 32, 27 }, + { 45, 41, 36, 31, 26 }, + { 44, 40, 35, 30, 25 }, + { -1, 39, 34, 29, 24 }, + { -1, 15, 10, 5, 0 }, + { 20, 16, 11, 6, 1 }, + { 21, 17, 12, 7, 2 }, + { 22, 18, 13, 8, 3 }, + { 23, 19, 14, 9, 4 } +}; + +void cmd_animation(uint8_t *data, uint8_t length) { + uint8_t subcmd = data[1]; + + + switch (subcmd) { + case 0x02: // Data input (fft) + + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { + // Turn off all LEDs + rgb_matrix_set_color( + i, + 0x00, 0x00, 0x00 + ); + } + + for (uint8_t bin = 0; bin < 10; bin++) { + uint8_t d = data[bin + 2]; + uint8_t bin_height = d / 20; + uint8_t last_brightness = ((d % 20)/20.0) * 0xFF; + + + if (bin_height == 0) { + continue; + } + + for (uint8_t i = 0; i < bin_height; i++) { + if (col_to_array[bin][i] < 0) { + continue; + } + if (i == bin_height - 1) { + rgb_matrix_set_color( + col_to_array[bin][i], + last_brightness, 0x00, last_brightness + ); + } else { + rgb_matrix_set_color( + col_to_array[bin][i], + 0x00, 0x00, 0xFF + ); + } + } + } + break; + } +} void raw_hid_receive(uint8_t *data, uint8_t length) { + uint8_t cmd = data[0]; + + switch (cmd) { + case 0x01: // animation + cmd_animation(data, length); + break; + + + default: + break; + } + + /* raw_hid_send(data, length); ergodox_right_led_1_on(); - _delay_ms(50); + _delay_ms(10); ergodox_right_led_1_off(); + + i2c_start(0x14, ERGODOX_EZ_I2C_TIMEOUT); + i2c_write(0, ERGODOX_EZ_I2C_TIMEOUT); + i2c_stop(); + */ } // Define custom keys