QMK/rawhid.c

85 lines
1.6 KiB
C
Raw Normal View History

2022-07-08 10:50:17 -07:00
#include "rawhid.h"
2022-07-07 17:12:13 -07:00
2022-07-08 10:50:17 -07:00
uint8_t hid_anim_data[32];
2022-07-07 17:12:13 -07:00
2022-07-08 10:50:17 -07:00
// See rawhid.h for prococol documentation
2022-07-07 17:12:13 -07:00
void raw_hid_receive(uint8_t *data, uint8_t length) {
uint8_t cmd = data[0];
switch (cmd) {
2022-07-08 10:50:17 -07:00
case CMD_HELLO:
ergodox_right_led_1_on();
_delay_ms(50);
ergodox_right_led_1_off();
hid_send_state();
break;
2022-07-07 17:12:13 -07:00
#ifdef RGB_MATRIX_DATAPOINTER_ENABLED
2022-07-08 10:50:17 -07:00
case CMD_ANIM_DATA:
2022-07-07 17:12:13 -07:00
cmd_animation(data, length);
break;
#endif
default:
break;
}
}
2022-07-08 10:50:17 -07:00
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; }
2022-07-07 17:12:13 -07:00
2022-07-08 10:50:17 -07:00
// 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();
2022-07-07 17:12:13 -07:00
}
break;
}
}
#endif