mirror of
https://github.com/speedypotato/Pico-Game-Controller.git
synced 2026-10-01 19:27:59 +03:00
HID timeout using timestamps, updated HID SET buffer to work with pico-sdk 1.3.0
This commit is contained in:
Binary file not shown.
+10
-10
@@ -1,16 +1,16 @@
|
||||
#ifndef CONTROLLER_CONFIG_H
|
||||
#define CONTROLLER_CONFIG_H
|
||||
|
||||
#define SW_GPIO_SIZE 11 // Number of switches
|
||||
#define LED_GPIO_SIZE 10 // Number of switch LEDs
|
||||
#define ENC_GPIO_SIZE 2 // Number of encoders
|
||||
#define ENC_PPR 600 // Encoder PPR
|
||||
#define ENC_DEBOUNCE true // Encoder Debouncing
|
||||
#define SW_DEBOUNCE_TIME_US 4000 // Switch debounce delay in us
|
||||
#define ENC_PULSE (ENC_PPR * 4) // 4 pulses per PPR
|
||||
#define REACTIVE_TIMEOUT_MAX 500000 // Cycles before HID falls back to reactive
|
||||
#define WS2812B_LED_SIZE 10 // Number of WS2812B LEDs
|
||||
#define WS2812B_LED_ZONES 2 // Number of WS2812B LED Zones
|
||||
#define SW_GPIO_SIZE 11 // Number of switches
|
||||
#define LED_GPIO_SIZE 10 // Number of switch LEDs
|
||||
#define ENC_GPIO_SIZE 2 // Number of encoders
|
||||
#define ENC_PPR 600 // Encoder PPR
|
||||
#define ENC_DEBOUNCE true // Encoder Debouncing
|
||||
#define SW_DEBOUNCE_TIME_US 4000 // Switch debounce delay in us
|
||||
#define ENC_PULSE (ENC_PPR * 4) // 4 pulses per PPR
|
||||
#define REACTIVE_TIMEOUT_MAX 1000000 // HID to reactive timeout in us
|
||||
#define WS2812B_LED_SIZE 10 // Number of WS2812B LEDs
|
||||
#define WS2812B_LED_ZONES 2 // Number of WS2812B LED Zones
|
||||
#define WS2812B_LEDS_PER_ZONE \
|
||||
WS2812B_LED_SIZE / WS2812B_LED_ZONES // Number of LEDs per zone
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ uint64_t sw_timestamp[SW_GPIO_SIZE];
|
||||
|
||||
bool kbm_report;
|
||||
|
||||
unsigned long reactive_timeout_count = REACTIVE_TIMEOUT_MAX;
|
||||
uint64_t reactive_timeout_timestamp;
|
||||
|
||||
void (*loop_mode)();
|
||||
bool joy_mode_check = true;
|
||||
@@ -94,7 +94,7 @@ void ws2812b_color_cycle(uint32_t counter) {
|
||||
* @param counter Current number of WS2812B cycles
|
||||
**/
|
||||
void ws2812b_update(uint32_t counter) {
|
||||
if (reactive_timeout_count >= REACTIVE_TIMEOUT_MAX) {
|
||||
if (time_us_64() - reactive_timeout_timestamp >= REACTIVE_TIMEOUT_MAX) {
|
||||
ws2812b_color_cycle(counter);
|
||||
} else {
|
||||
for (int i = 0; i < WS2812B_LED_ZONES; i++) {
|
||||
@@ -111,11 +111,8 @@ void ws2812b_update(uint32_t counter) {
|
||||
* HID/Reactive Lights
|
||||
**/
|
||||
void update_lights() {
|
||||
if (reactive_timeout_count < REACTIVE_TIMEOUT_MAX) {
|
||||
reactive_timeout_count++;
|
||||
}
|
||||
for (int i = 0; i < LED_GPIO_SIZE; i++) {
|
||||
if (reactive_timeout_count >= REACTIVE_TIMEOUT_MAX) {
|
||||
if (time_us_64() - reactive_timeout_timestamp >= REACTIVE_TIMEOUT_MAX) {
|
||||
if (!gpio_get(SW_GPIO[i])) {
|
||||
gpio_put(LED_GPIO[i], 1);
|
||||
} else {
|
||||
@@ -276,6 +273,8 @@ void init() {
|
||||
dma_channel_set_irq0_enabled(i, true);
|
||||
}
|
||||
|
||||
reactive_timeout_timestamp = time_us_64();
|
||||
|
||||
// Set up WS2812B
|
||||
pio_1 = pio1;
|
||||
uint offset2 = pio_add_program(pio_1, &ws2812_program);
|
||||
@@ -365,12 +364,12 @@ void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id,
|
||||
uint16_t bufsize) {
|
||||
(void)itf;
|
||||
if (report_id == 2 && report_type == HID_REPORT_TYPE_OUTPUT &&
|
||||
buffer[0] == 2 && bufsize >= sizeof(lights_report)) // light data
|
||||
bufsize >= sizeof(lights_report)) // light data
|
||||
{
|
||||
size_t i = 0;
|
||||
for (i; i < sizeof(lights_report); i++) {
|
||||
lights_report.raw[i] = buffer[i + 1];
|
||||
lights_report.raw[i] = buffer[i];
|
||||
}
|
||||
reactive_timeout_count = 0;
|
||||
reactive_timeout_timestamp = time_us_64();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user