Added basic spectrum code

master
Mark 2022-06-25 18:37:15 -07:00
parent 76b0530f3c
commit 3169a499a2
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 79 additions and 4 deletions

View File

@ -1,15 +1,90 @@
#include "keymap.h" #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) { 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); raw_hid_send(data, length);
ergodox_right_led_1_on(); ergodox_right_led_1_on();
_delay_ms(50); _delay_ms(10);
ergodox_right_led_1_off(); ergodox_right_led_1_off();
i2c_start(0x14, ERGODOX_EZ_I2C_TIMEOUT);
i2c_write(0, ERGODOX_EZ_I2C_TIMEOUT);
i2c_stop();
*/
} }
// Define custom keys // Define custom keys