code cleanup
This commit is contained in:
Binary file not shown.
+8
-11
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
#include "hyperx_elite2.h"
|
#include "hyperx_elite2.h"
|
||||||
|
|
||||||
static bool sending = false;
|
|
||||||
static absolute_time_t lastSend;
|
static absolute_time_t lastSend;
|
||||||
static absolute_time_t lastRead;
|
static absolute_time_t lastRead;
|
||||||
static bool backlight = false;
|
static bool backlight = false;
|
||||||
@@ -42,10 +41,10 @@ void rgb_task(uint8_t dev_addr) {
|
|||||||
// the RGB protocol used by HyperX sends individual key RGB data in
|
// the RGB protocol used by HyperX sends individual key RGB data in
|
||||||
// multiple packets
|
// multiple packets
|
||||||
// the code here will determine if we are in the middle of sending
|
// the code here will determine if we are in the middle of sending
|
||||||
// updated color info (sending==true) and continue to send the next
|
// updated color info (packets_sent>0) and continue to send the next
|
||||||
// packet if so at a rate of one packet every 20ms
|
// packet if so at a rate of one packet every 20ms
|
||||||
// otherwise, wait 1s before sending the next set of color packets
|
// otherwise, wait 0.5s before sending the next set of color packets
|
||||||
if (sending) {
|
if (packets_sent>0) {
|
||||||
if ( absolute_time_diff_us(lastSend, get_absolute_time()) >= 20000) {
|
if ( absolute_time_diff_us(lastSend, get_absolute_time()) >= 20000) {
|
||||||
if (backlight) {
|
if (backlight) {
|
||||||
send_color(dev_addr, 0x20, 0x20, 0x20);
|
send_color(dev_addr, 0x20, 0x20, 0x20);
|
||||||
@@ -76,8 +75,7 @@ static void send_color(uint8_t dev_addr, uint8_t red, uint8_t green, uint8_t blu
|
|||||||
if(color_idx < NUM_KEYS)
|
if(color_idx < NUM_KEYS)
|
||||||
{
|
{
|
||||||
while (color_idx < NUM_KEYS && buf_idx < BUF_SIZE) {
|
while (color_idx < NUM_KEYS && buf_idx < BUF_SIZE) {
|
||||||
if(*skip_idx == color_idx + skipped)
|
if (*skip_idx == color_idx + skipped) {
|
||||||
{
|
|
||||||
// keys in skip_idx are not assigned to a key, so send all 0x00
|
// keys in skip_idx are not assigned to a key, so send all 0x00
|
||||||
buf[buf_idx] = 0x00;
|
buf[buf_idx] = 0x00;
|
||||||
buf[buf_idx + 1] = 0x00;
|
buf[buf_idx + 1] = 0x00;
|
||||||
@@ -140,8 +138,8 @@ static void send_color(uint8_t dev_addr, uint8_t red, uint8_t green, uint8_t blu
|
|||||||
packets_sent++;
|
packets_sent++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// mark that sending of a full round of color packets completed
|
// a full round of color packets completed, reset packets to 0
|
||||||
sending=false;
|
packets_sent=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -161,9 +159,8 @@ static void send_initial(uint8_t dev_addr) {
|
|||||||
|
|
||||||
if (tuh_hid_set_report(dev_addr, 0, 0, HID_REPORT_TYPE_FEATURE, buf, BUF_SIZE))
|
if (tuh_hid_set_report(dev_addr, 0, 0, HID_REPORT_TYPE_FEATURE, buf, BUF_SIZE))
|
||||||
{
|
{
|
||||||
// we have begun sending packets, so set flag to continue sending
|
// we have begun sending packets, so indicate first packet was sent
|
||||||
// packets at regular intervals
|
// remaining packets will be sent at regular intervals
|
||||||
sending = true;
|
|
||||||
packets_sent=1;
|
packets_sent=1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-8
@@ -6,14 +6,11 @@
|
|||||||
#define LDR_OFF_THRESHOLD 500
|
#define LDR_OFF_THRESHOLD 500
|
||||||
#define LDR_ON_THRESHOLD 400
|
#define LDR_ON_THRESHOLD 400
|
||||||
|
|
||||||
enum
|
#define HYPERX_KEYBOARD_VID 0x0951
|
||||||
{
|
#define HYPERX_ELITE2_PID 0x1711
|
||||||
HYPERX_KEYBOARD_VID = 0x0951,
|
#define NUM_KEYS 128
|
||||||
HYPERX_ELITE2_PID = 0x1711,
|
#define BUF_SIZE 64
|
||||||
NUM_KEYS = 128,
|
#define NUM_PACKETS 10
|
||||||
BUF_SIZE = 64,
|
|
||||||
NUM_PACKETS = 10,
|
|
||||||
};
|
|
||||||
|
|
||||||
void get_light();
|
void get_light();
|
||||||
void rgb_task(uint8_t dev_addr);
|
void rgb_task(uint8_t dev_addr);
|
||||||
|
|||||||
+1
-1
@@ -73,7 +73,7 @@ void usb_device_main(void) {
|
|||||||
break;
|
break;
|
||||||
case DEVICE_RESTART:
|
case DEVICE_RESTART:
|
||||||
if (tud_disconnect()) {
|
if (tud_disconnect()) {
|
||||||
sleep_ms(100);
|
sleep_ms(10);
|
||||||
if (tud_connect()) {
|
if (tud_connect()) {
|
||||||
if ( host_state == HOST_INACTIVE ) {
|
if ( host_state == HOST_INACTIVE ) {
|
||||||
device_state = DEVICE_INACTIVE;
|
device_state = DEVICE_INACTIVE;
|
||||||
|
|||||||
+2
-2
@@ -16,7 +16,6 @@ host_state_t host_state;
|
|||||||
struct report_desc *descriptors;
|
struct report_desc *descriptors;
|
||||||
uint8_t num_mounted=0;
|
uint8_t num_mounted=0;
|
||||||
static absolute_time_t request_time;
|
static absolute_time_t request_time;
|
||||||
static struct report_data *report;
|
|
||||||
static bool enabled=false;
|
static bool enabled=false;
|
||||||
static uint8_t kb_addr=0;
|
static uint8_t kb_addr=0;
|
||||||
|
|
||||||
@@ -91,7 +90,7 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
|
|||||||
cdc_count = sprintf(cdc_buf, "Mount: [%04x:%04x][%u:%u] Protocol = %u\n", vid, pid, dev_addr, instance, itf_protocol);
|
cdc_count = sprintf(cdc_buf, "Mount: [%04x:%04x][%u:%u] Protocol = %u\n", vid, pid, dev_addr, instance, itf_protocol);
|
||||||
tud_cdc_write(cdc_buf, cdc_count);
|
tud_cdc_write(cdc_buf, cdc_count);
|
||||||
|
|
||||||
|
// enable RGB control if HyperX Elite 2 is mounted
|
||||||
if (vid==HYPERX_KEYBOARD_VID && pid==HYPERX_ELITE2_PID) {
|
if (vid==HYPERX_KEYBOARD_VID && pid==HYPERX_ELITE2_PID) {
|
||||||
kb_addr = dev_addr;
|
kb_addr = dev_addr;
|
||||||
enabled = true;
|
enabled = true;
|
||||||
@@ -119,6 +118,7 @@ void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance)
|
|||||||
remove_instance(dev_addr, instance);
|
remove_instance(dev_addr, instance);
|
||||||
if (dev_addr == kb_addr) {
|
if (dev_addr == kb_addr) {
|
||||||
enabled = false;
|
enabled = false;
|
||||||
|
kb_addr=0;
|
||||||
}
|
}
|
||||||
num_mounted--;
|
num_mounted--;
|
||||||
host_state=HOST_UNMOUNTED;
|
host_state=HOST_UNMOUNTED;
|
||||||
|
|||||||
@@ -23,15 +23,7 @@ struct report_desc {
|
|||||||
bool listening;
|
bool listening;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct report_data {
|
|
||||||
uint8_t dev_addr;
|
|
||||||
uint8_t instance;
|
|
||||||
uint8_t report[REPORT_MAX_SIZE];
|
|
||||||
uint16_t len;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define REPORT_DESC_ALLOC() (struct report_desc *)malloc(sizeof(struct report_desc))
|
#define REPORT_DESC_ALLOC() (struct report_desc *)malloc(sizeof(struct report_desc))
|
||||||
#define REPORT_DATA_ALLOC() (struct report_data *)malloc(sizeof(struct report_data))
|
|
||||||
|
|
||||||
extern host_state_t host_state;
|
extern host_state_t host_state;
|
||||||
extern struct report_desc *descriptors;
|
extern struct report_desc *descriptors;
|
||||||
|
|||||||
Reference in New Issue
Block a user