QMK/keyboards/betalupi_ergodox/rawhid.c

85 lines
1.6 KiB
C

#include "rawhid.h"
uint8_t hid_anim_data[32];
// See rawhid.h for prococol documentation
void raw_hid_receive(uint8_t *data, uint8_t length) {
uint8_t cmd = data[0];
switch (cmd) {
case CMD_HELLO:
ergodox_right_led_1_on();
_delay_ms(50);
ergodox_right_led_1_off();
hid_send_state();
break;
#ifdef RGB_MATRIX_DATAPOINTER_ENABLED
case CMD_ANIM_DATA:
cmd_animation(data, length);
break;
#endif
default:
break;
}
}
void hid_send_state() {
uint8_t packet[RAW_EPSIZE] = {
CMD_SEND_STATE
};
if (rgb_matrix_get_flags() != LED_FLAG_ALL) {
// RGB matrix is disabled
packet[1] = 0x00;
} else {
uint8_t mode = rgb_matrix_get_mode();
switch (mode) {
case RGB_MATRIX_CUSTOM_FFT_ANIM:
// FFT Animation is active
packet[1] = 0x02;
break;
default:
// Normal animation is active
packet[1] = 0x01;
break;
}
}
// Note that all sent packets MUST be
// RAW_EPSIZE long.
raw_hid_send(packet, RAW_EPSIZE);
}
#ifdef RGB_MATRIX_DATAPOINTER_ENABLED
void cmd_animation(uint8_t *data, uint8_t length) {
switch (data[1]) {
case CMD_ANIM_DATA_fft:
// Only read data if animation is in fft mode
if (rgb_matrix_get_mode() == RGB_MATRIX_CUSTOM_FFT_ANIM) {
// rgb_matrix_anim_data is set to NULL at animation init.
if (rgb_matrix_anim_data == NULL) { rgb_matrix_anim_data = hid_anim_data; }
// Copy data into rgb matrix array
memcpy(
hid_anim_data,
data + 2,
sizeof(uint8_t) + 10
);
} else {
// If not in fft mode and we receive fft data, send a state packet so host stops sending data.
hid_send_state();
}
break;
}
}
#endif