mirror of
https://github.com/speedypotato/Pico-Game-Controller.git
synced 2026-09-29 18:27:57 +03:00
Merge pull request #40 from speedypotato/feature/debounce_rename
Renamed debounce algorithms
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* Debouncing algorithm which waits for switch to output a constant n amount of time before outputting
|
||||
* @author SpeedyPotato
|
||||
**/
|
||||
|
||||
uint16_t constant_switch() {
|
||||
uint16_t translate_buttons = 0;
|
||||
for (int i = SW_GPIO_SIZE - 1; i >= 0; i--) {
|
||||
if (!gpio_get(SW_GPIO[i]) &&
|
||||
time_us_64() - sw_timestamp[i] >= SW_DEBOUNCE_TIME_US) {
|
||||
translate_buttons = (translate_buttons << 1) | 1;
|
||||
} else {
|
||||
translate_buttons <<= 1;
|
||||
}
|
||||
}
|
||||
return translate_buttons;
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
/**
|
||||
* Simple header file to include all files in the folder
|
||||
* @author SpeedyPotato
|
||||
*
|
||||
* To add a debounce mode, return a uint16_t representing the button states. These are saved in report.buttons as truth.
|
||||
* Create debounce mode as desired and then add the #include here.
|
||||
*
|
||||
* To add a debounce mode, return a uint16_t representing the button states.
|
||||
* These are saved in report.buttons as truth. Create debounce mode as desired
|
||||
* and then add the #include here.
|
||||
**/
|
||||
extern uint64_t sw_timestamp[SW_GPIO_SIZE];
|
||||
|
||||
#include "constant_switch.c"
|
||||
#include "minimum_hold.c"
|
||||
#include "deferred.c"
|
||||
#include "eager.c"
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Debouncing algorithm which waits for switch to output a constant n amount of
|
||||
* time before outputting
|
||||
* @author SpeedyPotato
|
||||
**/
|
||||
|
||||
uint16_t debounce_deferred() {
|
||||
uint16_t translate_buttons = 0;
|
||||
for (int i = SW_GPIO_SIZE - 1; i >= 0; i--) {
|
||||
if (!gpio_get(SW_GPIO[i]) &&
|
||||
time_us_64() - sw_timestamp[i] >= SW_DEBOUNCE_TIME_US) {
|
||||
translate_buttons = (translate_buttons << 1) | 1;
|
||||
} else {
|
||||
translate_buttons <<= 1;
|
||||
}
|
||||
}
|
||||
return translate_buttons;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Debouncing algorithm which sends a report immediately when a switch is
|
||||
* triggered and holds it for n amount of time.
|
||||
* @author SpeedyPotato
|
||||
**/
|
||||
|
||||
uint16_t debounce_eager() {
|
||||
uint16_t translate_buttons = 0;
|
||||
for (int i = SW_GPIO_SIZE - 1; i >= 0; i--) {
|
||||
if (time_us_64() - sw_timestamp[i] <= SW_DEBOUNCE_TIME_US ||
|
||||
!gpio_get(SW_GPIO[i])) {
|
||||
translate_buttons = (translate_buttons << 1) | 1;
|
||||
} else {
|
||||
translate_buttons <<= 1;
|
||||
}
|
||||
}
|
||||
return translate_buttons;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Debouncing algorithm which sends a report immediately when a switch is triggered and holds it for n amount of time.
|
||||
* @author SpeedyPotato
|
||||
**/
|
||||
|
||||
uint16_t minimum_hold() {
|
||||
uint16_t translate_buttons = 0;
|
||||
for (int i = SW_GPIO_SIZE - 1; i >= 0; i--) {
|
||||
if (time_us_64() - sw_timestamp[i] <= SW_DEBOUNCE_TIME_US || !gpio_get(SW_GPIO[i])) {
|
||||
translate_buttons = (translate_buttons << 1) | 1;
|
||||
} else {
|
||||
translate_buttons <<= 1;
|
||||
}
|
||||
}
|
||||
return translate_buttons;
|
||||
}
|
||||
@@ -19,9 +19,10 @@
|
||||
#include "pico/stdlib.h"
|
||||
#include "tusb.h"
|
||||
#include "usb_descriptors.h"
|
||||
|
||||
#include "rgb/rgb_include.h"
|
||||
// clang-format off
|
||||
#include "debounce/debounce_include.h"
|
||||
#include "rgb/rgb_include.h"
|
||||
// clang-format on
|
||||
|
||||
PIO pio, pio_1;
|
||||
uint32_t enc_val[ENC_GPIO_SIZE];
|
||||
@@ -274,7 +275,7 @@ void init() {
|
||||
}
|
||||
|
||||
// Debouncing Mode
|
||||
debounce_mode = &minimum_hold;
|
||||
debounce_mode = &debounce_eager;
|
||||
|
||||
// Disable RGB
|
||||
if (gpio_get(SW_GPIO[8])) {
|
||||
|
||||
Reference in New Issue
Block a user