Format code according to conventions (#15193)

master
QMK Bot 2021-11-17 12:28:38 -08:00 committed by GitHub
parent b06740c933
commit 2c5d66987d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 576 additions and 516 deletions

View File

@ -17,7 +17,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "adns5050.h" #include "adns5050.h"
#include "wait.h" #include "wait.h"
#include "debug.h" #include "debug.h"
@ -61,13 +60,9 @@ void adns_sync(void) {
writePinHigh(ADNS_CS_PIN); writePinHigh(ADNS_CS_PIN);
} }
void adns_cs_select(void) { void adns_cs_select(void) { writePinLow(ADNS_CS_PIN); }
writePinLow(ADNS_CS_PIN);
}
void adns_cs_deselect(void) { void adns_cs_deselect(void) { writePinHigh(ADNS_CS_PIN); }
writePinHigh(ADNS_CS_PIN);
}
uint8_t adns_serial_read(void) { uint8_t adns_serial_read(void) {
setPinInput(ADNS_SDIO_PIN); setPinInput(ADNS_SDIO_PIN);
@ -121,7 +116,7 @@ uint8_t adns_read_reg(uint8_t reg_addr) {
// We don't need a minimum tSRAD here. That's because a 4ms wait time is // We don't need a minimum tSRAD here. That's because a 4ms wait time is
// already included in adns_serial_write(), so we're good. // already included in adns_serial_write(), so we're good.
// See page 10 and 15 of the ADNS spec sheet. // See page 10 and 15 of the ADNS spec sheet.
//wait_us(4); // wait_us(4);
uint8_t byte = adns_serial_read(); uint8_t byte = adns_serial_read();
@ -138,7 +133,7 @@ uint8_t adns_read_reg(uint8_t reg_addr) {
void adns_write_reg(uint8_t reg_addr, uint8_t data) { void adns_write_reg(uint8_t reg_addr, uint8_t data) {
adns_cs_select(); adns_cs_select();
adns_serial_write( 0b10000000 | reg_addr ); adns_serial_write(0b10000000 | reg_addr);
adns_serial_write(data); adns_serial_write(data);
adns_cs_deselect(); adns_cs_deselect();
} }
@ -155,7 +150,7 @@ report_adns_t adns_read_burst(void) {
// We don't need a minimum tSRAD here. That's because a 4ms wait time is // We don't need a minimum tSRAD here. That's because a 4ms wait time is
// already included in adns_serial_write(), so we're good. // already included in adns_serial_write(), so we're good.
// See page 10 and 15 of the ADNS spec sheet. // See page 10 and 15 of the ADNS spec sheet.
//wait_us(4); // wait_us(4);
uint8_t x = adns_serial_read(); uint8_t x = adns_serial_read();
uint8_t y = adns_serial_read(); uint8_t y = adns_serial_read();
@ -180,9 +175,7 @@ int8_t convert_twoscomp(uint8_t data) {
} }
// Don't forget to use the definitions for CPI in the header file. // Don't forget to use the definitions for CPI in the header file.
void adns_set_cpi(uint8_t cpi) { void adns_set_cpi(uint8_t cpi) { adns_write_reg(REG_MOUSE_CONTROL2, cpi); }
adns_write_reg(REG_MOUSE_CONTROL2, cpi);
}
bool adns_check_signature(void) { bool adns_check_signature(void) {
uint8_t pid = adns_read_reg(REG_PRODUCT_ID); uint8_t pid = adns_read_reg(REG_PRODUCT_ID);

View File

@ -70,7 +70,7 @@
#define MIN_CPI 200 #define MIN_CPI 200
#define MAX_CPI 8200 #define MAX_CPI 8200
#define CPI_STEP 200 #define CPI_STEP 200
#define CLAMP_CPI(value) value < MIN_CPI ? MIN_CPI : value > MAX_CPI ? MAX_CPI : value #define CLAMP_CPI(value) value<MIN_CPI ? MIN_CPI : value> MAX_CPI ? MAX_CPI : value
#define SPI_MODE 3 #define SPI_MODE 3
#define SPI_DIVISOR (F_CPU / ADNS_CLOCK_SPEED) #define SPI_DIVISOR (F_CPU / ADNS_CLOCK_SPEED)
#define US_BETWEEN_WRITES 120 #define US_BETWEEN_WRITES 120
@ -80,12 +80,9 @@
extern const uint8_t firmware_data[]; extern const uint8_t firmware_data[];
void adns_spi_start(void){ void adns_spi_start(void) { spi_start(SPI_SS_PIN, false, SPI_MODE, SPI_DIVISOR); }
spi_start(SPI_SS_PIN, false, SPI_MODE, SPI_DIVISOR);
}
void adns_write(uint8_t reg_addr, uint8_t data){
void adns_write(uint8_t reg_addr, uint8_t data) {
adns_spi_start(); adns_spi_start();
spi_write(reg_addr | MSB1); spi_write(reg_addr | MSB1);
spi_write(data); spi_write(data);
@ -93,10 +90,9 @@ void adns_write(uint8_t reg_addr, uint8_t data){
wait_us(US_BETWEEN_WRITES); wait_us(US_BETWEEN_WRITES);
} }
uint8_t adns_read(uint8_t reg_addr){ uint8_t adns_read(uint8_t reg_addr) {
adns_spi_start(); adns_spi_start();
spi_write(reg_addr & 0x7f ); spi_write(reg_addr & 0x7f);
uint8_t data = spi_read(); uint8_t data = spi_read();
spi_stop(); spi_stop();
wait_us(US_BETWEEN_READS); wait_us(US_BETWEEN_READS);
@ -105,7 +101,6 @@ uint8_t adns_read(uint8_t reg_addr){
} }
void adns_init() { void adns_init() {
setPinOutput(SPI_SS_PIN); setPinOutput(SPI_SS_PIN);
spi_init(); spi_init();
@ -144,7 +139,7 @@ void adns_init() {
// send all bytes of the firmware // send all bytes of the firmware
unsigned char c; unsigned char c;
for(int i = 0; i < FIRMWARE_LENGTH; i++){ for (int i = 0; i < FIRMWARE_LENGTH; i++) {
c = (unsigned char)pgm_read_byte(firmware_data + i); c = (unsigned char)pgm_read_byte(firmware_data + i);
spi_write(c); spi_write(c);
wait_us(15); wait_us(15);
@ -161,7 +156,7 @@ void adns_init() {
config_adns_t adns_get_config(void) { config_adns_t adns_get_config(void) {
uint8_t config_1 = adns_read(REG_Configuration_I); uint8_t config_1 = adns_read(REG_Configuration_I);
return (config_adns_t){ (config_1 & 0xFF) * CPI_STEP }; return (config_adns_t){(config_1 & 0xFF) * CPI_STEP};
} }
void adns_set_config(config_adns_t config) { void adns_set_config(config_adns_t config) {
@ -169,20 +164,17 @@ void adns_set_config(config_adns_t config) {
adns_write(REG_Configuration_I, config_1); adns_write(REG_Configuration_I, config_1);
} }
static int16_t convertDeltaToInt(uint8_t high, uint8_t low){ static int16_t convertDeltaToInt(uint8_t high, uint8_t low) {
// join bytes into twos compliment // join bytes into twos compliment
uint16_t twos_comp = (high << 8) | low; uint16_t twos_comp = (high << 8) | low;
// convert twos comp to int // convert twos comp to int
if (twos_comp & 0x8000) if (twos_comp & 0x8000) return -1 * (~twos_comp + 1);
return -1 * (~twos_comp + 1);
return twos_comp; return twos_comp;
} }
report_adns_t adns_get_report(void) { report_adns_t adns_get_report(void) {
report_adns_t report = {0, 0}; report_adns_t report = {0, 0};
adns_spi_start(); adns_spi_start();
@ -194,8 +186,7 @@ report_adns_t adns_get_report(void) {
uint8_t motion = spi_read(); uint8_t motion = spi_read();
if(motion & 0x80) { if (motion & 0x80) {
// clear observation register // clear observation register
spi_read(); spi_read();

View File

@ -66,8 +66,6 @@ typedef struct {
int8_t mdy; int8_t mdy;
} report_pmw_t; } report_pmw_t;
bool spi_start_adv(void); bool spi_start_adv(void);
void spi_stop_adv(void); void spi_stop_adv(void);
spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data); spi_status_t spi_write_adv(uint8_t reg_addr, uint8_t data);
@ -79,7 +77,6 @@ void pmw_upload_firmware(void);
bool pmw_check_signature(void); bool pmw_check_signature(void);
report_pmw_t pmw_read_burst(void); report_pmw_t pmw_read_burst(void);
#define degToRad(angleInDegrees) ((angleInDegrees)*M_PI / 180.0) #define degToRad(angleInDegrees) ((angleInDegrees)*M_PI / 180.0)
#define radToDeg(angleInRadians) ((angleInRadians)*180.0 / M_PI) #define radToDeg(angleInRadians) ((angleInRadians)*180.0 / M_PI)
#define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt))) #define constrain(amt, low, high) ((amt) < (low) ? (low) : ((amt) > (high) ? (high) : (amt)))

View File

@ -1,4 +1,4 @@
{ {
"keyboard_name": "AVA", "keyboard_name": "AVA",
"url": "https://sneakbox.com", "url": "https://sneakbox.com",
"maintainer": "mujimanic", "maintainer": "mujimanic",

View File

@ -782,7 +782,8 @@ void register_code(uint8_t code) {
} }
#endif #endif
else if IS_KEY (code) { else if
IS_KEY(code) {
// TODO: should push command_proc out of this block? // TODO: should push command_proc out of this block?
if (command_proc(code)) return; if (command_proc(code)) return;
@ -812,19 +813,21 @@ void register_code(uint8_t code) {
add_key(code); add_key(code);
send_keyboard_report(); send_keyboard_report();
} }
} else if IS_MOD (code) { }
else if
IS_MOD(code) {
add_mods(MOD_BIT(code)); add_mods(MOD_BIT(code));
send_keyboard_report(); send_keyboard_report();
} }
#ifdef EXTRAKEY_ENABLE #ifdef EXTRAKEY_ENABLE
else if IS_SYSTEM (code) { else if
host_system_send(KEYCODE2SYSTEM(code)); IS_SYSTEM(code) { host_system_send(KEYCODE2SYSTEM(code)); }
} else if IS_CONSUMER (code) { else if
host_consumer_send(KEYCODE2CONSUMER(code)); IS_CONSUMER(code) { host_consumer_send(KEYCODE2CONSUMER(code)); }
}
#endif #endif
#ifdef MOUSEKEY_ENABLE #ifdef MOUSEKEY_ENABLE
else if IS_MOUSEKEY (code) { else if
IS_MOUSEKEY(code) {
mousekey_on(code); mousekey_on(code);
mousekey_send(); mousekey_send();
} }
@ -872,19 +875,23 @@ void unregister_code(uint8_t code) {
} }
#endif #endif
else if IS_KEY (code) { else if
IS_KEY(code) {
del_key(code); del_key(code);
send_keyboard_report(); send_keyboard_report();
} else if IS_MOD (code) { }
else if
IS_MOD(code) {
del_mods(MOD_BIT(code)); del_mods(MOD_BIT(code));
send_keyboard_report(); send_keyboard_report();
} else if IS_SYSTEM (code) {
host_system_send(0);
} else if IS_CONSUMER (code) {
host_consumer_send(0);
} }
else if
IS_SYSTEM(code) { host_system_send(0); }
else if
IS_CONSUMER(code) { host_consumer_send(0); }
#ifdef MOUSEKEY_ENABLE #ifdef MOUSEKEY_ENABLE
else if IS_MOUSEKEY (code) { else if
IS_MOUSEKEY(code) {
mousekey_off(code); mousekey_off(code);
mousekey_send(); mousekey_send();
} }

View File

@ -18,11 +18,11 @@
# define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed) # define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed)
# define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed) # define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed)
# define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k))) # define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k)))
#ifndef COMBO_ENABLE # ifndef COMBO_ENABLE
# define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key))) # define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key)))
#else # else
# define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode) # define IS_TAPPING_RECORD(r) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (r->event.key)) && tapping_key.keycode == r->keycode)
#endif # endif
__attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { return TAPPING_TERM; } __attribute__((weak)) uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) { return TAPPING_TERM; }
@ -212,10 +212,14 @@ bool process_tapping(keyrecord_t *keyp) {
if (tapping_key.tap.count > 1) { if (tapping_key.tap.count > 1) {
debug("Tapping: Start new tap with releasing last tap(>1).\n"); debug("Tapping: Start new tap with releasing last tap(>1).\n");
// unregister key // unregister key
process_record(&(keyrecord_t){.tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false, process_record(&(keyrecord_t){
#ifdef COMBO_ENABLE .tap = tapping_key.tap,
.event.key = tapping_key.event.key,
.event.time = event.time,
.event.pressed = false,
# ifdef COMBO_ENABLE
.keycode = tapping_key.keycode, .keycode = tapping_key.keycode,
#endif # endif
}); });
} else { } else {
debug("Tapping: Start while last tap(1).\n"); debug("Tapping: Start while last tap(1).\n");
@ -254,10 +258,14 @@ bool process_tapping(keyrecord_t *keyp) {
if (tapping_key.tap.count > 1) { if (tapping_key.tap.count > 1) {
debug("Tapping: Start new tap with releasing last timeout tap(>1).\n"); debug("Tapping: Start new tap with releasing last timeout tap(>1).\n");
// unregister key // unregister key
process_record(&(keyrecord_t){.tap = tapping_key.tap, .event.key = tapping_key.event.key, .event.time = event.time, .event.pressed = false, process_record(&(keyrecord_t){
#ifdef COMBO_ENABLE .tap = tapping_key.tap,
.event.key = tapping_key.event.key,
.event.time = event.time,
.event.pressed = false,
# ifdef COMBO_ENABLE
.keycode = tapping_key.keycode, .keycode = tapping_key.keycode,
#endif # endif
}); });
} else { } else {
debug("Tapping: Start while last timeout tap(1).\n"); debug("Tapping: Start while last timeout tap(1).\n");

View File

@ -56,7 +56,7 @@ static fast_timer_t last_time;
static bool counters_need_update; static bool counters_need_update;
static bool matrix_need_update; static bool matrix_need_update;
#define DEBOUNCE_ELAPSED 0 # define DEBOUNCE_ELAPSED 0
static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time); static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time);
static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows);

View File

@ -49,7 +49,7 @@ static debounce_counter_t *debounce_counters;
static fast_timer_t last_time; static fast_timer_t last_time;
static bool counters_need_update; static bool counters_need_update;
#define DEBOUNCE_ELAPSED 0 # define DEBOUNCE_ELAPSED 0
static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time); static void update_debounce_counters_and_transfer_if_expired(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, uint8_t elapsed_time);
static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); static void start_debounce_counters(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows);

View File

@ -50,7 +50,7 @@ static fast_timer_t last_time;
static bool counters_need_update; static bool counters_need_update;
static bool matrix_need_update; static bool matrix_need_update;
#define DEBOUNCE_ELAPSED 0 # define DEBOUNCE_ELAPSED 0
static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time); static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time);
static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows);

View File

@ -49,7 +49,7 @@ static debounce_counter_t *debounce_counters;
static fast_timer_t last_time; static fast_timer_t last_time;
static bool counters_need_update; static bool counters_need_update;
#define DEBOUNCE_ELAPSED 0 # define DEBOUNCE_ELAPSED 0
static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time); static void update_debounce_counters(uint8_t num_rows, uint8_t elapsed_time);
static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows); static void transfer_matrix_values(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows);

View File

@ -19,7 +19,8 @@
#include "debounce_test_common.h" #include "debounce_test_common.h"
TEST_F(DebounceTest, OneKeyShort1) { TEST_F(DebounceTest, OneKeyShort1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Release key after 1ms delay */ /* Release key after 1ms delay */
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -43,7 +44,8 @@ TEST_F(DebounceTest, OneKeyShort1) {
} }
TEST_F(DebounceTest, OneKeyShort2) { TEST_F(DebounceTest, OneKeyShort2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Release key after 2ms delay */ /* Release key after 2ms delay */
{2, {{0, 1, UP}}, {}}, {2, {{0, 1, UP}}, {}},
@ -58,7 +60,8 @@ TEST_F(DebounceTest, OneKeyShort2) {
} }
TEST_F(DebounceTest, OneKeyShort3) { TEST_F(DebounceTest, OneKeyShort3) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Release key after 3ms delay */ /* Release key after 3ms delay */
{3, {{0, 1, UP}}, {}}, {3, {{0, 1, UP}}, {}},
@ -73,7 +76,8 @@ TEST_F(DebounceTest, OneKeyShort3) {
} }
TEST_F(DebounceTest, OneKeyShort4) { TEST_F(DebounceTest, OneKeyShort4) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Release key after 4ms delay */ /* Release key after 4ms delay */
{4, {{0, 1, UP}}, {}}, {4, {{0, 1, UP}}, {}},
@ -88,7 +92,8 @@ TEST_F(DebounceTest, OneKeyShort4) {
} }
TEST_F(DebounceTest, OneKeyShort5) { TEST_F(DebounceTest, OneKeyShort5) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Release key after 5ms delay */ /* Release key after 5ms delay */
@ -102,7 +107,8 @@ TEST_F(DebounceTest, OneKeyShort5) {
} }
TEST_F(DebounceTest, OneKeyShort6) { TEST_F(DebounceTest, OneKeyShort6) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Release key after 6ms delay */ /* Release key after 6ms delay */
@ -116,7 +122,8 @@ TEST_F(DebounceTest, OneKeyShort6) {
} }
TEST_F(DebounceTest, OneKeyShort7) { TEST_F(DebounceTest, OneKeyShort7) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Release key after 7ms delay */ /* Release key after 7ms delay */
@ -130,7 +137,8 @@ TEST_F(DebounceTest, OneKeyShort7) {
} }
TEST_F(DebounceTest, OneKeyShort8) { TEST_F(DebounceTest, OneKeyShort8) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Release key after 1ms delay */ /* Release key after 1ms delay */
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -145,7 +153,8 @@ TEST_F(DebounceTest, OneKeyShort8) {
} }
TEST_F(DebounceTest, OneKeyShort9) { TEST_F(DebounceTest, OneKeyShort9) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Release key after 1ms delay */ /* Release key after 1ms delay */
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -159,7 +168,8 @@ TEST_F(DebounceTest, OneKeyShort9) {
} }
TEST_F(DebounceTest, OneKeyBouncing1) { TEST_F(DebounceTest, OneKeyBouncing1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
{2, {{0, 1, DOWN}}, {}}, {2, {{0, 1, DOWN}}, {}},
@ -185,7 +195,8 @@ TEST_F(DebounceTest, OneKeyBouncing1) {
} }
TEST_F(DebounceTest, OneKeyBouncing2) { TEST_F(DebounceTest, OneKeyBouncing2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Change twice in the same time period */ /* Change twice in the same time period */
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -217,7 +228,8 @@ TEST_F(DebounceTest, OneKeyBouncing2) {
} }
TEST_F(DebounceTest, OneKeyLong) { TEST_F(DebounceTest, OneKeyLong) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{25, {{0, 1, UP}}, {}}, {25, {{0, 1, UP}}, {}},
@ -236,7 +248,8 @@ TEST_F(DebounceTest, OneKeyLong) {
} }
TEST_F(DebounceTest, TwoKeysShort) { TEST_F(DebounceTest, TwoKeysShort) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 2, DOWN}}, {{0, 2, DOWN}}}, {1, {{0, 2, DOWN}}, {{0, 2, DOWN}}},
/* Release key after 2ms delay */ /* Release key after 2ms delay */
@ -254,9 +267,9 @@ TEST_F(DebounceTest, TwoKeysShort) {
runEvents(); runEvents();
} }
TEST_F(DebounceTest, OneKeyDelayedScan1) { TEST_F(DebounceTest, OneKeyDelayedScan1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late, immediately release key */ /* Processing is very late, immediately release key */
@ -269,7 +282,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan1) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan2) { TEST_F(DebounceTest, OneKeyDelayedScan2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late, immediately release key */ /* Processing is very late, immediately release key */
@ -283,7 +297,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan2) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan3) { TEST_F(DebounceTest, OneKeyDelayedScan3) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late */ /* Processing is very late */
@ -298,7 +313,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan3) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan4) { TEST_F(DebounceTest, OneKeyDelayedScan4) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late */ /* Processing is very late */
@ -314,7 +330,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan4) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan5) { TEST_F(DebounceTest, OneKeyDelayedScan5) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{5, {{0, 1, UP}}, {}}, {5, {{0, 1, UP}}, {}},
@ -329,7 +346,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan5) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan6) { TEST_F(DebounceTest, OneKeyDelayedScan6) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{5, {{0, 1, UP}}, {}}, {5, {{0, 1, UP}}, {}},
@ -345,7 +363,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan6) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan7) { TEST_F(DebounceTest, OneKeyDelayedScan7) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{5, {{0, 1, UP}}, {}}, {5, {{0, 1, UP}}, {}},
@ -358,7 +377,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan7) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan8) { TEST_F(DebounceTest, OneKeyDelayedScan8) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is a bit late */ /* Processing is a bit late */

View File

@ -31,9 +31,7 @@ void set_time(uint32_t t);
void advance_time(uint32_t ms); void advance_time(uint32_t ms);
} }
void DebounceTest::addEvents(std::initializer_list<DebounceTestEvent> events) { void DebounceTest::addEvents(std::initializer_list<DebounceTestEvent> events) { events_.insert(events_.end(), events.begin(), events.end()); }
events_.insert(events_.end(), events.begin(), events.end());
}
void DebounceTest::runEvents() { void DebounceTest::runEvents() {
/* Run the test multiple times, from 1kHz to 10kHz scan rate */ /* Run the test multiple times, from 1kHz to 10kHz scan rate */
@ -98,12 +96,7 @@ void DebounceTest::runEventsInternal() {
/* Check output matrix has expected change events */ /* Check output matrix has expected change events */
for (auto &output : event.outputs_) { for (auto &output : event.outputs_) {
EXPECT_EQ(!!(cooked_matrix_[output.row_] & (1U << output.col_)), directionValue(output.direction_)) EXPECT_EQ(!!(cooked_matrix_[output.row_] & (1U << output.col_)), directionValue(output.direction_)) << "Missing event at " << strTime() << " expected key " << output.row_ << "," << output.col_ << " " << directionLabel(output.direction_) << "\ninput_matrix: changed=" << !event.inputs_.empty() << "\n" << strMatrix(input_matrix_) << "\nexpected_matrix:\n" << strMatrix(output_matrix_) << "\nactual_matrix:\n" << strMatrix(cooked_matrix_);
<< "Missing event at " << strTime()
<< " expected key " << output.row_ << "," << output.col_ << " " << directionLabel(output.direction_)
<< "\ninput_matrix: changed=" << !event.inputs_.empty() << "\n" << strMatrix(input_matrix_)
<< "\nexpected_matrix:\n" << strMatrix(output_matrix_)
<< "\nactual_matrix:\n" << strMatrix(cooked_matrix_);
} }
/* Check output matrix has no other changes */ /* Check output matrix has no other changes */
@ -133,27 +126,20 @@ void DebounceTest::runDebounce(bool changed) {
debounce(raw_matrix_, cooked_matrix_, MATRIX_ROWS, changed); debounce(raw_matrix_, cooked_matrix_, MATRIX_ROWS, changed);
if (!std::equal(std::begin(input_matrix_), std::end(input_matrix_), std::begin(raw_matrix_))) { if (!std::equal(std::begin(input_matrix_), std::end(input_matrix_), std::begin(raw_matrix_))) {
FAIL() << "Fatal error: debounce() modified raw matrix at " << strTime() FAIL() << "Fatal error: debounce() modified raw matrix at " << strTime() << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_) << "\nraw_matrix:\n" << strMatrix(raw_matrix_);
<< "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_)
<< "\nraw_matrix:\n" << strMatrix(raw_matrix_);
} }
} }
void DebounceTest::checkCookedMatrix(bool changed, const std::string &error_message) { void DebounceTest::checkCookedMatrix(bool changed, const std::string &error_message) {
if (!std::equal(std::begin(output_matrix_), std::end(output_matrix_), std::begin(cooked_matrix_))) { if (!std::equal(std::begin(output_matrix_), std::end(output_matrix_), std::begin(cooked_matrix_))) {
FAIL() << "Unexpected event: " << error_message << " at " << strTime() FAIL() << "Unexpected event: " << error_message << " at " << strTime() << "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_) << "\nexpected_matrix:\n" << strMatrix(output_matrix_) << "\nactual_matrix:\n" << strMatrix(cooked_matrix_);
<< "\ninput_matrix: changed=" << changed << "\n" << strMatrix(input_matrix_)
<< "\nexpected_matrix:\n" << strMatrix(output_matrix_)
<< "\nactual_matrix:\n" << strMatrix(cooked_matrix_);
} }
} }
std::string DebounceTest::strTime() { std::string DebounceTest::strTime() {
std::stringstream text; std::stringstream text;
text << "time " << (timer_read_fast() - time_offset_) text << "time " << (timer_read_fast() - time_offset_) << " (extra_iterations=" << extra_iterations_ << ", auto_advance_time=" << auto_advance_time_ << ")";
<< " (extra_iterations=" << extra_iterations_
<< ", auto_advance_time=" << auto_advance_time_ << ")";
return text.str(); return text.str();
} }
@ -201,11 +187,7 @@ std::string DebounceTest::directionLabel(Direction direction) {
/* Modify a matrix and verify that events always specify a change */ /* Modify a matrix and verify that events always specify a change */
void DebounceTest::matrixUpdate(matrix_row_t matrix[], const std::string &name, const MatrixTestEvent &event) { void DebounceTest::matrixUpdate(matrix_row_t matrix[], const std::string &name, const MatrixTestEvent &event) {
ASSERT_NE(!!(matrix[event.row_] & (1U << event.col_)), directionValue(event.direction_)) ASSERT_NE(!!(matrix[event.row_] & (1U << event.col_)), directionValue(event.direction_)) << "Test " << name << " at " << strTime() << " sets key " << event.row_ << "," << event.col_ << " " << directionLabel(event.direction_) << " but it is already " << directionLabel(event.direction_) << "\n" << name << "_matrix:\n" << strMatrix(matrix);
<< "Test " << name << " at " << strTime()
<< " sets key " << event.row_ << "," << event.col_ << " " << directionLabel(event.direction_)
<< " but it is already " << directionLabel(event.direction_)
<< "\n" << name << "_matrix:\n" << strMatrix(matrix);
switch (event.direction_) { switch (event.direction_) {
case DOWN: case DOWN:
@ -218,12 +200,6 @@ void DebounceTest::matrixUpdate(matrix_row_t matrix[], const std::string &name,
} }
} }
DebounceTestEvent::DebounceTestEvent(fast_timer_t time, DebounceTestEvent::DebounceTestEvent(fast_timer_t time, std::initializer_list<MatrixTestEvent> inputs, std::initializer_list<MatrixTestEvent> outputs) : time_(time), inputs_(inputs), outputs_(outputs) {}
std::initializer_list<MatrixTestEvent> inputs,
std::initializer_list<MatrixTestEvent> outputs)
: time_(time), inputs_(inputs), outputs_(outputs) {
}
MatrixTestEvent::MatrixTestEvent(int row, int col, Direction direction) MatrixTestEvent::MatrixTestEvent(int row, int col, Direction direction) : row_(row), col_(col), direction_(direction) {}
: row_(row), col_(col), direction_(direction) {
}

View File

@ -31,7 +31,7 @@ enum Direction {
}; };
class MatrixTestEvent { class MatrixTestEvent {
public: public:
MatrixTestEvent(int row, int col, Direction direction); MatrixTestEvent(int row, int col, Direction direction);
const int row_; const int row_;
@ -40,11 +40,9 @@ public:
}; };
class DebounceTestEvent { class DebounceTestEvent {
public: public:
// 0, {{0, 1, DOWN}}, {{0, 1, DOWN}}) // 0, {{0, 1, DOWN}}, {{0, 1, DOWN}})
DebounceTestEvent(fast_timer_t time, DebounceTestEvent(fast_timer_t time, std::initializer_list<MatrixTestEvent> inputs, std::initializer_list<MatrixTestEvent> outputs);
std::initializer_list<MatrixTestEvent> inputs,
std::initializer_list<MatrixTestEvent> outputs);
const fast_timer_t time_; const fast_timer_t time_;
const std::list<MatrixTestEvent> inputs_; const std::list<MatrixTestEvent> inputs_;
@ -52,14 +50,14 @@ public:
}; };
class DebounceTest : public ::testing::Test { class DebounceTest : public ::testing::Test {
protected: protected:
void addEvents(std::initializer_list<DebounceTestEvent> events); void addEvents(std::initializer_list<DebounceTestEvent> events);
void runEvents(); void runEvents();
fast_timer_t time_offset_ = 7777; fast_timer_t time_offset_ = 7777;
bool time_jumps_ = false; bool time_jumps_ = false;
private: private:
static bool directionValue(Direction direction); static bool directionValue(Direction direction);
static std::string directionLabel(Direction direction); static std::string directionLabel(Direction direction);

View File

@ -19,7 +19,8 @@
#include "debounce_test_common.h" #include "debounce_test_common.h"
TEST_F(DebounceTest, OneKeyShort1) { TEST_F(DebounceTest, OneKeyShort1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
@ -32,7 +33,8 @@ TEST_F(DebounceTest, OneKeyShort1) {
} }
TEST_F(DebounceTest, OneKeyShort2) { TEST_F(DebounceTest, OneKeyShort2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
@ -45,7 +47,8 @@ TEST_F(DebounceTest, OneKeyShort2) {
} }
TEST_F(DebounceTest, OneKeyShort3) { TEST_F(DebounceTest, OneKeyShort3) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
@ -58,7 +61,8 @@ TEST_F(DebounceTest, OneKeyShort3) {
} }
TEST_F(DebounceTest, OneKeyTooQuick1) { TEST_F(DebounceTest, OneKeyTooQuick1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
/* Release key exactly on the debounce time */ /* Release key exactly on the debounce time */
{5, {{0, 1, UP}}, {}}, {5, {{0, 1, UP}}, {}},
@ -67,7 +71,8 @@ TEST_F(DebounceTest, OneKeyTooQuick1) {
} }
TEST_F(DebounceTest, OneKeyTooQuick2) { TEST_F(DebounceTest, OneKeyTooQuick2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
@ -80,7 +85,8 @@ TEST_F(DebounceTest, OneKeyTooQuick2) {
} }
TEST_F(DebounceTest, OneKeyBouncing1) { TEST_F(DebounceTest, OneKeyBouncing1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
{2, {{0, 1, DOWN}}, {}}, {2, {{0, 1, DOWN}}, {}},
@ -94,7 +100,8 @@ TEST_F(DebounceTest, OneKeyBouncing1) {
} }
TEST_F(DebounceTest, OneKeyBouncing2) { TEST_F(DebounceTest, OneKeyBouncing2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
{6, {{0, 1, UP}}, {}}, {6, {{0, 1, UP}}, {}},
@ -108,7 +115,8 @@ TEST_F(DebounceTest, OneKeyBouncing2) {
} }
TEST_F(DebounceTest, OneKeyLong) { TEST_F(DebounceTest, OneKeyLong) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
@ -125,7 +133,8 @@ TEST_F(DebounceTest, OneKeyLong) {
} }
TEST_F(DebounceTest, TwoKeysShort) { TEST_F(DebounceTest, TwoKeysShort) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{1, {{0, 2, DOWN}}, {}}, {1, {{0, 2, DOWN}}, {}},
@ -140,7 +149,8 @@ TEST_F(DebounceTest, TwoKeysShort) {
} }
TEST_F(DebounceTest, TwoKeysSimultaneous1) { TEST_F(DebounceTest, TwoKeysSimultaneous1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}, {0, 2, DOWN}}, {}}, {0, {{0, 1, DOWN}, {0, 2, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}, {0, 2, DOWN}}}, {5, {}, {{0, 1, DOWN}, {0, 2, DOWN}}},
@ -152,7 +162,8 @@ TEST_F(DebounceTest, TwoKeysSimultaneous1) {
} }
TEST_F(DebounceTest, TwoKeysSimultaneous2) { TEST_F(DebounceTest, TwoKeysSimultaneous2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{1, {{0, 2, DOWN}}, {}}, {1, {{0, 2, DOWN}}, {}},
@ -167,7 +178,8 @@ TEST_F(DebounceTest, TwoKeysSimultaneous2) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan1) { TEST_F(DebounceTest, OneKeyDelayedScan1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
/* Processing is very late */ /* Processing is very late */
@ -182,7 +194,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan1) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan2) { TEST_F(DebounceTest, OneKeyDelayedScan2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
/* Processing is very late */ /* Processing is very late */
@ -197,7 +210,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan2) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan3) { TEST_F(DebounceTest, OneKeyDelayedScan3) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
/* Release key before debounce expires */ /* Release key before debounce expires */
@ -208,7 +222,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan3) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan4) { TEST_F(DebounceTest, OneKeyDelayedScan4) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
/* Processing is a bit late */ /* Processing is a bit late */

View File

@ -19,7 +19,8 @@
#include "debounce_test_common.h" #include "debounce_test_common.h"
TEST_F(DebounceTest, OneKeyShort1) { TEST_F(DebounceTest, OneKeyShort1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
@ -32,7 +33,8 @@ TEST_F(DebounceTest, OneKeyShort1) {
} }
TEST_F(DebounceTest, OneKeyShort2) { TEST_F(DebounceTest, OneKeyShort2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
@ -45,7 +47,8 @@ TEST_F(DebounceTest, OneKeyShort2) {
} }
TEST_F(DebounceTest, OneKeyShort3) { TEST_F(DebounceTest, OneKeyShort3) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
@ -58,7 +61,8 @@ TEST_F(DebounceTest, OneKeyShort3) {
} }
TEST_F(DebounceTest, OneKeyTooQuick1) { TEST_F(DebounceTest, OneKeyTooQuick1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
/* Release key exactly on the debounce time */ /* Release key exactly on the debounce time */
{5, {{0, 1, UP}}, {}}, {5, {{0, 1, UP}}, {}},
@ -67,7 +71,8 @@ TEST_F(DebounceTest, OneKeyTooQuick1) {
} }
TEST_F(DebounceTest, OneKeyTooQuick2) { TEST_F(DebounceTest, OneKeyTooQuick2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
@ -80,7 +85,8 @@ TEST_F(DebounceTest, OneKeyTooQuick2) {
} }
TEST_F(DebounceTest, OneKeyBouncing1) { TEST_F(DebounceTest, OneKeyBouncing1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
{2, {{0, 1, DOWN}}, {}}, {2, {{0, 1, DOWN}}, {}},
@ -94,7 +100,8 @@ TEST_F(DebounceTest, OneKeyBouncing1) {
} }
TEST_F(DebounceTest, OneKeyBouncing2) { TEST_F(DebounceTest, OneKeyBouncing2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
{6, {{0, 1, UP}}, {}}, {6, {{0, 1, UP}}, {}},
@ -108,7 +115,8 @@ TEST_F(DebounceTest, OneKeyBouncing2) {
} }
TEST_F(DebounceTest, OneKeyLong) { TEST_F(DebounceTest, OneKeyLong) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}}}, {5, {}, {{0, 1, DOWN}}},
@ -125,7 +133,8 @@ TEST_F(DebounceTest, OneKeyLong) {
} }
TEST_F(DebounceTest, TwoKeysShort) { TEST_F(DebounceTest, TwoKeysShort) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{1, {{0, 2, DOWN}}, {}}, {1, {{0, 2, DOWN}}, {}},
@ -142,7 +151,8 @@ TEST_F(DebounceTest, TwoKeysShort) {
} }
TEST_F(DebounceTest, TwoKeysSimultaneous1) { TEST_F(DebounceTest, TwoKeysSimultaneous1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}, {0, 2, DOWN}}, {}}, {0, {{0, 1, DOWN}, {0, 2, DOWN}}, {}},
{5, {}, {{0, 1, DOWN}, {0, 2, DOWN}}}, {5, {}, {{0, 1, DOWN}, {0, 2, DOWN}}},
@ -154,7 +164,8 @@ TEST_F(DebounceTest, TwoKeysSimultaneous1) {
} }
TEST_F(DebounceTest, TwoKeysSimultaneous2) { TEST_F(DebounceTest, TwoKeysSimultaneous2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
{1, {{0, 2, DOWN}}, {}}, {1, {{0, 2, DOWN}}, {}},
@ -169,7 +180,8 @@ TEST_F(DebounceTest, TwoKeysSimultaneous2) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan1) { TEST_F(DebounceTest, OneKeyDelayedScan1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
/* Processing is very late */ /* Processing is very late */
@ -184,7 +196,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan1) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan2) { TEST_F(DebounceTest, OneKeyDelayedScan2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
/* Processing is very late */ /* Processing is very late */
@ -199,7 +212,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan2) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan3) { TEST_F(DebounceTest, OneKeyDelayedScan3) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
/* Release key before debounce expires */ /* Release key before debounce expires */
@ -210,7 +224,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan3) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan4) { TEST_F(DebounceTest, OneKeyDelayedScan4) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {}}, {0, {{0, 1, DOWN}}, {}},
/* Processing is a bit late */ /* Processing is a bit late */

View File

@ -19,7 +19,8 @@
#include "debounce_test_common.h" #include "debounce_test_common.h"
TEST_F(DebounceTest, OneKeyShort1) { TEST_F(DebounceTest, OneKeyShort1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -32,7 +33,8 @@ TEST_F(DebounceTest, OneKeyShort1) {
} }
TEST_F(DebounceTest, OneKeyShort2) { TEST_F(DebounceTest, OneKeyShort2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -45,7 +47,8 @@ TEST_F(DebounceTest, OneKeyShort2) {
} }
TEST_F(DebounceTest, OneKeyShort3) { TEST_F(DebounceTest, OneKeyShort3) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -58,7 +61,8 @@ TEST_F(DebounceTest, OneKeyShort3) {
} }
TEST_F(DebounceTest, OneKeyShort4) { TEST_F(DebounceTest, OneKeyShort4) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -71,7 +75,8 @@ TEST_F(DebounceTest, OneKeyShort4) {
} }
TEST_F(DebounceTest, OneKeyShort5) { TEST_F(DebounceTest, OneKeyShort5) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -83,7 +88,8 @@ TEST_F(DebounceTest, OneKeyShort5) {
} }
TEST_F(DebounceTest, OneKeyShort6) { TEST_F(DebounceTest, OneKeyShort6) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -95,7 +101,8 @@ TEST_F(DebounceTest, OneKeyShort6) {
} }
TEST_F(DebounceTest, OneKeyBouncing1) { TEST_F(DebounceTest, OneKeyBouncing1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
{2, {{0, 1, DOWN}}, {}}, {2, {{0, 1, DOWN}}, {}},
@ -110,7 +117,8 @@ TEST_F(DebounceTest, OneKeyBouncing1) {
} }
TEST_F(DebounceTest, OneKeyBouncing2) { TEST_F(DebounceTest, OneKeyBouncing2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Change twice in the same time period */ /* Change twice in the same time period */
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -135,7 +143,8 @@ TEST_F(DebounceTest, OneKeyBouncing2) {
} }
TEST_F(DebounceTest, OneKeyLong) { TEST_F(DebounceTest, OneKeyLong) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{25, {{0, 1, UP}}, {{0, 1, UP}}}, {25, {{0, 1, UP}}, {{0, 1, UP}}},
@ -146,7 +155,8 @@ TEST_F(DebounceTest, OneKeyLong) {
} }
TEST_F(DebounceTest, TwoKeysShort) { TEST_F(DebounceTest, TwoKeysShort) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
{2, {{0, 2, DOWN}}, {{0, 2, DOWN}}}, {2, {{0, 2, DOWN}}, {{0, 2, DOWN}}},
@ -167,7 +177,8 @@ TEST_F(DebounceTest, TwoKeysShort) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan1) { TEST_F(DebounceTest, OneKeyDelayedScan1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late but the change will now be accepted */ /* Processing is very late but the change will now be accepted */
@ -178,7 +189,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan1) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan2) { TEST_F(DebounceTest, OneKeyDelayedScan2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late but the change will now be accepted even with a 1 scan delay */ /* Processing is very late but the change will now be accepted even with a 1 scan delay */
@ -190,7 +202,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan2) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan3) { TEST_F(DebounceTest, OneKeyDelayedScan3) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late but the change will now be accepted even with a 1ms delay */ /* Processing is very late but the change will now be accepted even with a 1ms delay */
@ -202,7 +215,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan3) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan4) { TEST_F(DebounceTest, OneKeyDelayedScan4) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is a bit late but the change will now be accepted */ /* Processing is a bit late but the change will now be accepted */
@ -213,7 +227,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan4) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan5) { TEST_F(DebounceTest, OneKeyDelayedScan5) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late but the change will now be accepted even with a 1 scan delay */ /* Processing is very late but the change will now be accepted even with a 1 scan delay */
@ -225,7 +240,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan5) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan6) { TEST_F(DebounceTest, OneKeyDelayedScan6) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late but the change will now be accepted even with a 1ms delay */ /* Processing is very late but the change will now be accepted even with a 1ms delay */

View File

@ -19,7 +19,8 @@
#include "debounce_test_common.h" #include "debounce_test_common.h"
TEST_F(DebounceTest, OneKeyShort1) { TEST_F(DebounceTest, OneKeyShort1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -32,7 +33,8 @@ TEST_F(DebounceTest, OneKeyShort1) {
} }
TEST_F(DebounceTest, OneKeyShort2) { TEST_F(DebounceTest, OneKeyShort2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -45,7 +47,8 @@ TEST_F(DebounceTest, OneKeyShort2) {
} }
TEST_F(DebounceTest, OneKeyShort3) { TEST_F(DebounceTest, OneKeyShort3) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -58,7 +61,8 @@ TEST_F(DebounceTest, OneKeyShort3) {
} }
TEST_F(DebounceTest, OneKeyShort4) { TEST_F(DebounceTest, OneKeyShort4) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -71,7 +75,8 @@ TEST_F(DebounceTest, OneKeyShort4) {
} }
TEST_F(DebounceTest, OneKeyShort5) { TEST_F(DebounceTest, OneKeyShort5) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -83,7 +88,8 @@ TEST_F(DebounceTest, OneKeyShort5) {
} }
TEST_F(DebounceTest, OneKeyShort6) { TEST_F(DebounceTest, OneKeyShort6) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -95,7 +101,8 @@ TEST_F(DebounceTest, OneKeyShort6) {
} }
TEST_F(DebounceTest, OneKeyBouncing1) { TEST_F(DebounceTest, OneKeyBouncing1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
{2, {{0, 1, DOWN}}, {}}, {2, {{0, 1, DOWN}}, {}},
@ -110,7 +117,8 @@ TEST_F(DebounceTest, OneKeyBouncing1) {
} }
TEST_F(DebounceTest, OneKeyBouncing2) { TEST_F(DebounceTest, OneKeyBouncing2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Change twice in the same time period */ /* Change twice in the same time period */
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
@ -135,7 +143,8 @@ TEST_F(DebounceTest, OneKeyBouncing2) {
} }
TEST_F(DebounceTest, OneKeyLong) { TEST_F(DebounceTest, OneKeyLong) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{25, {{0, 1, UP}}, {{0, 1, UP}}}, {25, {{0, 1, UP}}, {{0, 1, UP}}},
@ -146,7 +155,8 @@ TEST_F(DebounceTest, OneKeyLong) {
} }
TEST_F(DebounceTest, TwoRowsShort) { TEST_F(DebounceTest, TwoRowsShort) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
{2, {{2, 0, DOWN}}, {{2, 0, DOWN}}}, {2, {{2, 0, DOWN}}, {{2, 0, DOWN}}},
@ -167,7 +177,8 @@ TEST_F(DebounceTest, TwoRowsShort) {
} }
TEST_F(DebounceTest, TwoKeysOverlap) { TEST_F(DebounceTest, TwoKeysOverlap) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
{1, {{0, 1, UP}}, {}}, {1, {{0, 1, UP}}, {}},
/* Press a second key during the first debounce */ /* Press a second key during the first debounce */
@ -190,7 +201,8 @@ TEST_F(DebounceTest, TwoKeysOverlap) {
} }
TEST_F(DebounceTest, TwoKeysSimultaneous1) { TEST_F(DebounceTest, TwoKeysSimultaneous1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}, {0, 2, DOWN}}, {{0, 1, DOWN}, {0, 2, DOWN}}}, {0, {{0, 1, DOWN}, {0, 2, DOWN}}, {{0, 1, DOWN}, {0, 2, DOWN}}},
{20, {{0, 1, UP}}, {{0, 1, UP}}}, {20, {{0, 1, UP}}, {{0, 1, UP}}},
{21, {{0, 2, UP}}, {}}, {21, {{0, 2, UP}}, {}},
@ -202,7 +214,8 @@ TEST_F(DebounceTest, TwoKeysSimultaneous1) {
} }
TEST_F(DebounceTest, TwoKeysSimultaneous2) { TEST_F(DebounceTest, TwoKeysSimultaneous2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}, {0, 2, DOWN}}, {{0, 1, DOWN}, {0, 2, DOWN}}}, {0, {{0, 1, DOWN}, {0, 2, DOWN}}, {{0, 1, DOWN}, {0, 2, DOWN}}},
{20, {{0, 1, UP}, {0, 2, UP}}, {{0, 1, UP}, {0, 2, UP}}}, {20, {{0, 1, UP}, {0, 2, UP}}, {{0, 1, UP}, {0, 2, UP}}},
}); });
@ -210,7 +223,8 @@ TEST_F(DebounceTest, TwoKeysSimultaneous2) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan1) { TEST_F(DebounceTest, OneKeyDelayedScan1) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late but the change will now be accepted */ /* Processing is very late but the change will now be accepted */
@ -221,7 +235,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan1) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan2) { TEST_F(DebounceTest, OneKeyDelayedScan2) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late but the change will now be accepted even with a 1 scan delay */ /* Processing is very late but the change will now be accepted even with a 1 scan delay */
@ -233,7 +248,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan2) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan3) { TEST_F(DebounceTest, OneKeyDelayedScan3) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late but the change will now be accepted even with a 1ms delay */ /* Processing is very late but the change will now be accepted even with a 1ms delay */
@ -245,7 +261,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan3) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan4) { TEST_F(DebounceTest, OneKeyDelayedScan4) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is a bit late but the change will now be accepted */ /* Processing is a bit late but the change will now be accepted */
@ -256,7 +273,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan4) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan5) { TEST_F(DebounceTest, OneKeyDelayedScan5) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late but the change will now be accepted even with a 1 scan delay */ /* Processing is very late but the change will now be accepted even with a 1 scan delay */
@ -268,7 +286,8 @@ TEST_F(DebounceTest, OneKeyDelayedScan5) {
} }
TEST_F(DebounceTest, OneKeyDelayedScan6) { TEST_F(DebounceTest, OneKeyDelayedScan6) {
addEvents({ /* Time, Inputs, Outputs */ addEvents({
/* Time, Inputs, Outputs */
{0, {{0, 1, DOWN}}, {{0, 1, DOWN}}}, {0, {{0, 1, DOWN}}, {{0, 1, DOWN}}},
/* Processing is very late but the change will now be accepted even with a 1ms delay */ /* Processing is very late but the change will now be accepted even with a 1ms delay */

View File

@ -74,8 +74,7 @@ enum steno_keycodes {
}; };
#ifdef STENO_COMBINEDMAP #ifdef STENO_COMBINEDMAP
enum steno_combined_keycodes enum steno_combined_keycodes {
{
STN_S3 = QK_STENO_COMB, STN_S3 = QK_STENO_COMB,
STN_TKL, STN_TKL,
STN_PWL, STN_PWL,

View File

@ -18,7 +18,6 @@
#include "process_combo.h" #include "process_combo.h"
#include "action_tapping.h" #include "action_tapping.h"
#ifdef COMBO_COUNT #ifdef COMBO_COUNT
__attribute__((weak)) combo_t key_combos[COMBO_COUNT]; __attribute__((weak)) combo_t key_combos[COMBO_COUNT];
uint16_t COMBO_LEN = COMBO_COUNT; uint16_t COMBO_LEN = COMBO_COUNT;
@ -62,14 +61,13 @@ static queued_record_t key_buffer[COMBO_KEY_BUFFER_LENGTH];
typedef struct { typedef struct {
uint16_t combo_index; uint16_t combo_index;
} queued_combo_t; } queued_combo_t;
static uint8_t combo_buffer_write= 0; static uint8_t combo_buffer_write = 0;
static uint8_t combo_buffer_read = 0; static uint8_t combo_buffer_read = 0;
static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH]; static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH];
#define INCREMENT_MOD(i) i = (i + 1) % COMBO_BUFFER_LENGTH #define INCREMENT_MOD(i) i = (i + 1) % COMBO_BUFFER_LENGTH
#define COMBO_KEY_POS ((keypos_t){.col=254, .row=254}) #define COMBO_KEY_POS ((keypos_t){.col = 254, .row = 254})
#ifndef EXTRA_SHORT_COMBOS #ifndef EXTRA_SHORT_COMBOS
/* flags are their own elements in combo_t struct. */ /* flags are their own elements in combo_t struct. */
@ -77,31 +75,54 @@ static queued_combo_t combo_buffer[COMBO_BUFFER_LENGTH];
# define COMBO_DISABLED(combo) (combo->disabled) # define COMBO_DISABLED(combo) (combo->disabled)
# define COMBO_STATE(combo) (combo->state) # define COMBO_STATE(combo) (combo->state)
# define ACTIVATE_COMBO(combo) do {combo->active = true;}while(0) # define ACTIVATE_COMBO(combo) \
# define DEACTIVATE_COMBO(combo) do {combo->active = false;}while(0) do { \
# define DISABLE_COMBO(combo) do {combo->disabled = true;}while(0) combo->active = true; \
# define RESET_COMBO_STATE(combo) do { \ } while (0)
# define DEACTIVATE_COMBO(combo) \
do { \
combo->active = false; \
} while (0)
# define DISABLE_COMBO(combo) \
do { \
combo->disabled = true; \
} while (0)
# define RESET_COMBO_STATE(combo) \
do { \
combo->disabled = false; \ combo->disabled = false; \
combo->state = 0; \ combo->state = 0; \
}while(0) } while (0)
#else #else
/* flags are at the two high bits of state. */ /* flags are at the two high bits of state. */
# define COMBO_ACTIVE(combo) (combo->state & 0x80) # define COMBO_ACTIVE(combo) (combo->state & 0x80)
# define COMBO_DISABLED(combo) (combo->state & 0x40) # define COMBO_DISABLED(combo) (combo->state & 0x40)
# define COMBO_STATE(combo) (combo->state & 0x3F) # define COMBO_STATE(combo) (combo->state & 0x3F)
# define ACTIVATE_COMBO(combo) do {combo->state |= 0x80;}while(0) # define ACTIVATE_COMBO(combo) \
# define DEACTIVATE_COMBO(combo) do {combo->state &= ~0x80;}while(0) do { \
# define DISABLE_COMBO(combo) do {combo->state |= 0x40;}while(0) combo->state |= 0x80; \
# define RESET_COMBO_STATE(combo) do {combo->state &= ~0x7F;}while(0) } while (0)
# define DEACTIVATE_COMBO(combo) \
do { \
combo->state &= ~0x80; \
} while (0)
# define DISABLE_COMBO(combo) \
do { \
combo->state |= 0x40; \
} while (0)
# define RESET_COMBO_STATE(combo) \
do { \
combo->state &= ~0x7F; \
} while (0)
#endif #endif
static inline void release_combo(uint16_t combo_index, combo_t *combo) { static inline void release_combo(uint16_t combo_index, combo_t *combo) {
if (combo->keycode) { if (combo->keycode) {
keyrecord_t record = { keyrecord_t record = {
.event = { .event =
{
.key = COMBO_KEY_POS, .key = COMBO_KEY_POS,
.time = timer_read()|1, .time = timer_read() | 1,
.pressed = false, .pressed = false,
}, },
.keycode = combo->keycode, .keycode = combo->keycode,
@ -123,13 +144,12 @@ static inline bool _get_combo_must_hold(uint16_t combo_index, combo_t *combo) {
#elif defined(COMBO_MUST_HOLD_PER_COMBO) #elif defined(COMBO_MUST_HOLD_PER_COMBO)
return get_combo_must_hold(combo_index, combo); return get_combo_must_hold(combo_index, combo);
#elif defined(COMBO_MUST_HOLD_MODS) #elif defined(COMBO_MUST_HOLD_MODS)
return (KEYCODE_IS_MOD(combo->keycode) || return (KEYCODE_IS_MOD(combo->keycode) || (combo->keycode >= QK_MOMENTARY && combo->keycode <= QK_MOMENTARY_MAX));
(combo->keycode >= QK_MOMENTARY && combo->keycode <= QK_MOMENTARY_MAX));
#endif #endif
return false; return false;
} }
static inline uint16_t _get_wait_time(uint16_t combo_index, combo_t *combo ) { static inline uint16_t _get_wait_time(uint16_t combo_index, combo_t *combo) {
if (_get_combo_must_hold(combo_index, combo) if (_get_combo_must_hold(combo_index, combo)
#ifdef COMBO_MUST_TAP_PER_COMBO #ifdef COMBO_MUST_TAP_PER_COMBO
|| get_combo_must_tap(combo_index, combo) || get_combo_must_tap(combo_index, combo)
@ -144,7 +164,6 @@ static inline uint16_t _get_wait_time(uint16_t combo_index, combo_t *combo ) {
} }
static inline uint16_t _get_combo_term(uint16_t combo_index, combo_t *combo) { static inline uint16_t _get_combo_term(uint16_t combo_index, combo_t *combo) {
#if defined(COMBO_TERM_PER_COMBO) #if defined(COMBO_TERM_PER_COMBO)
return get_combo_term(combo_index, combo); return get_combo_term(combo_index, combo);
#endif #endif
@ -175,7 +194,7 @@ static inline void dump_key_buffer(void) {
key_buffer_next = key_buffer_i + 1; key_buffer_next = key_buffer_i + 1;
queued_record_t *qrecord = &key_buffer[key_buffer_i]; queued_record_t *qrecord = &key_buffer[key_buffer_i];
keyrecord_t *record = &qrecord->record; keyrecord_t * record = &qrecord->record;
if (IS_NOEVENT(record->event)) { if (IS_NOEVENT(record->event)) {
continue; continue;
@ -242,7 +261,9 @@ void apply_combo(uint16_t combo_index, combo_t *combo) {
/* Apply combo's result keycode to the last chord key of the combo and /* Apply combo's result keycode to the last chord key of the combo and
* disable the other keys. */ * disable the other keys. */
if (COMBO_DISABLED(combo)) { return; } if (COMBO_DISABLED(combo)) {
return;
}
// state to check against so we find the last key of the combo from the buffer // state to check against so we find the last key of the combo from the buffer
#if defined(EXTRA_EXTRA_LONG_COMBOS) #if defined(EXTRA_EXTRA_LONG_COMBOS)
@ -254,9 +275,8 @@ void apply_combo(uint16_t combo_index, combo_t *combo) {
#endif #endif
for (uint8_t key_buffer_i = 0; key_buffer_i < key_buffer_size; key_buffer_i++) { for (uint8_t key_buffer_i = 0; key_buffer_i < key_buffer_size; key_buffer_i++) {
queued_record_t *qrecord = &key_buffer[key_buffer_i]; queued_record_t *qrecord = &key_buffer[key_buffer_i];
keyrecord_t *record = &qrecord->record; keyrecord_t * record = &qrecord->record;
uint16_t keycode = qrecord->keycode; uint16_t keycode = qrecord->keycode;
uint8_t key_count = 0; uint8_t key_count = 0;
@ -283,19 +303,15 @@ void apply_combo(uint16_t combo_index, combo_t *combo) {
// by making it a TICK event. // by making it a TICK event.
record->event.time = 0; record->event.time = 0;
} }
} }
drop_combo_from_buffer(combo_index); drop_combo_from_buffer(combo_index);
} }
static inline void apply_combos(void) { static inline void apply_combos(void) {
// Apply all buffered normal combos. // Apply all buffered normal combos.
for (uint8_t i = combo_buffer_read; for (uint8_t i = combo_buffer_read; i != combo_buffer_write; INCREMENT_MOD(i)) {
i != combo_buffer_write;
INCREMENT_MOD(i)) {
queued_combo_t *buffered_combo = &combo_buffer[i]; queued_combo_t *buffered_combo = &combo_buffer[i];
combo_t *combo = &key_combos[buffered_combo->combo_index]; combo_t * combo = &key_combos[buffered_combo->combo_index];
#ifdef COMBO_MUST_TAP_PER_COMBO #ifdef COMBO_MUST_TAP_PER_COMBO
if (get_combo_must_tap(buffered_combo->combo_index, combo)) { if (get_combo_must_tap(buffered_combo->combo_index, combo)) {
@ -310,7 +326,7 @@ static inline void apply_combos(void) {
clear_combos(); clear_combos();
} }
combo_t* overlaps(combo_t *combo1, combo_t *combo2) { combo_t *overlaps(combo_t *combo1, combo_t *combo2) {
/* Checks if the combos overlap and returns the combo that should be /* Checks if the combos overlap and returns the combo that should be
* dropped from the combo buffer. * dropped from the combo buffer.
* The combo that has less keys will be dropped. If they have the same * The combo that has less keys will be dropped. If they have the same
@ -369,12 +385,9 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *
// disable readied combos that overlap with this combo // disable readied combos that overlap with this combo
combo_t *drop = NULL; combo_t *drop = NULL;
for (uint8_t combo_buffer_i = combo_buffer_read; for (uint8_t combo_buffer_i = combo_buffer_read; combo_buffer_i != combo_buffer_write; INCREMENT_MOD(combo_buffer_i)) {
combo_buffer_i != combo_buffer_write;
INCREMENT_MOD(combo_buffer_i)) {
queued_combo_t *qcombo = &combo_buffer[combo_buffer_i]; queued_combo_t *qcombo = &combo_buffer[combo_buffer_i];
combo_t *buffered_combo = &key_combos[qcombo->combo_index]; combo_t * buffered_combo = &key_combos[qcombo->combo_index];
if ((drop = overlaps(buffered_combo, combo))) { if ((drop = overlaps(buffered_combo, combo))) {
DISABLE_COMBO(drop); DISABLE_COMBO(drop);
@ -387,13 +400,12 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *
INCREMENT_MOD(combo_buffer_read); INCREMENT_MOD(combo_buffer_read);
} }
} }
} }
if (drop != combo) { if (drop != combo) {
// save this combo to buffer // save this combo to buffer
combo_buffer[combo_buffer_write] = (queued_combo_t){ combo_buffer[combo_buffer_write] = (queued_combo_t){
.combo_index=combo_index, .combo_index = combo_index,
}; };
INCREMENT_MOD(combo_buffer_write); INCREMENT_MOD(combo_buffer_write);
@ -401,7 +413,6 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *
longest_term = _get_wait_time(combo_index, combo); longest_term = _get_wait_time(combo_index, combo);
} }
} // if timer elapsed end } // if timer elapsed end
} }
} else { } else {
// chord releases // chord releases
@ -424,10 +435,7 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *
# endif # endif
} }
#endif #endif
} else if (COMBO_ACTIVE(combo) } else if (COMBO_ACTIVE(combo) && ONLY_ONE_KEY_IS_DOWN(COMBO_STATE(combo)) && KEY_NOT_YET_RELEASED(COMBO_STATE(combo), key_index)) {
&& ONLY_ONE_KEY_IS_DOWN(COMBO_STATE(combo))
&& KEY_NOT_YET_RELEASED(COMBO_STATE(combo), key_index)
) {
/* last key released */ /* last key released */
release_combo(combo_index, combo); release_combo(combo_index, combo);
key_is_part_of_combo = true; key_is_part_of_combo = true;
@ -435,9 +443,7 @@ static bool process_single_combo(combo_t *combo, uint16_t keycode, keyrecord_t *
#ifdef COMBO_PROCESS_KEY_RELEASE #ifdef COMBO_PROCESS_KEY_RELEASE
process_combo_key_release(combo_index, combo, key_index, keycode); process_combo_key_release(combo_index, combo, key_index, keycode);
#endif #endif
} else if (COMBO_ACTIVE(combo) } else if (COMBO_ACTIVE(combo) && KEY_NOT_YET_RELEASED(COMBO_STATE(combo), key_index)) {
&& KEY_NOT_YET_RELEASED(COMBO_STATE(combo), key_index)
) {
/* first or middle key released */ /* first or middle key released */
key_is_part_of_combo = true; key_is_part_of_combo = true;

View File

@ -174,11 +174,10 @@ bool process_steno(uint16_t keycode, keyrecord_t *record) {
return false; return false;
#ifdef STENO_COMBINEDMAP #ifdef STENO_COMBINEDMAP
case QK_STENO_COMB ... QK_STENO_COMB_MAX: case QK_STENO_COMB ... QK_STENO_COMB_MAX: {
{
uint8_t result; uint8_t result;
result = process_steno(combinedmap_first[keycode-QK_STENO_COMB], record); result = process_steno(combinedmap_first[keycode - QK_STENO_COMB], record);
result &= process_steno(combinedmap_second[keycode-QK_STENO_COMB], record); result &= process_steno(combinedmap_second[keycode - QK_STENO_COMB], record);
return result; return result;
} }
#endif #endif

View File

@ -145,12 +145,13 @@ void reset_keyboard(void) {
/* Convert record into usable keycode via the contained event. */ /* Convert record into usable keycode via the contained event. */
uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) { uint16_t get_record_keycode(keyrecord_t *record, bool update_layer_cache) {
#ifdef COMBO_ENABLE #ifdef COMBO_ENABLE
if (record->keycode) { return record->keycode; } if (record->keycode) {
return record->keycode;
}
#endif #endif
return get_event_keycode(record->event, update_layer_cache); return get_event_keycode(record->event, update_layer_cache);
} }
/* Convert event into usable keycode. Checks the layer cache to ensure that it /* Convert event into usable keycode. Checks the layer cache to ensure that it
* retains the correct keycode after a layer change, if the key is still pressed. * retains the correct keycode after a layer change, if the key is still pressed.
* "update_layer_cache" is to ensure that it only updates the layer cache when * "update_layer_cache" is to ensure that it only updates the layer cache when