Merge pull request #40 from speedypotato/feature/debounce_rename

Renamed debounce algorithms
This commit is contained in:
Nick G
2022-08-18 21:38:31 -04:00
committed by GitHub
6 changed files with 46 additions and 41 deletions
-17
View File
@@ -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;
}
+6 -5
View File
@@ -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"
+18
View File
@@ -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;
}
+18
View File
@@ -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;
}
-16
View File
@@ -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;
}
+4 -3
View File
@@ -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])) {