diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index 3010db03299..d855a3345ca 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -35,7 +35,7 @@ typedef struct { uint16_t extremum; int16_t offset; bool is_analog; - bool dynamic_actuation_bool; + bool continuous_dynamic_actuation; // uint16_t SMA_buffer[1<<(SMA_FILTER_SAMPLE_EXPONENT)]; uint8_t SMA_samplesExponent; uint8_t SMA_samples; diff --git a/keyboards/momokai/tap_trio_pro/lut.c b/keyboards/momokai/tap_trio_pro/lut.c index 38f4dbbcaba..5954e2bbac8 100644 --- a/keyboards/momokai/tap_trio_pro/lut.c +++ b/keyboards/momokai/tap_trio_pro/lut.c @@ -13,17 +13,17 @@ SPDX-License-Identifier: GPL-2.0-or-later */ # define MAX(x, y) (((x) > (y)) ? (x) : (y)) #endif -// /* Equation parameters for the sensor-magnet linearity mapping */ -// const double lut_a = 0.200347177016; -// const double lut_b = 0.00955994866154; -// const double lut_c = 6.01110636956; -// const double lut_d = 1966.74076381; -/* Equation parameters for the sensor-magnet linearity mapping */ -const double lut_a = -366.805673399; -const double lut_b = 0.00617870508512; -const double lut_c = -1.49468890703; -const double lut_d = 2094.38794157; +// /* Equation parameters for the sensor-magnet linearity mapping */ +// const double lut_a = -366.805673399; +// const double lut_b = 0.00617870508512; +// const double lut_c = -1.49468890703; +// const double lut_d = 2094.38794157; + +const double lut_a = -0.203212; +const double lut_b = 0.00955995; +const double lut_c = 5.99691; +const double lut_d = 2122.25924; uint16_t distance_to_adc(uint16_t distance) { double intermediate = lut_a * exp(lut_b * distance + lut_c) + lut_d; diff --git a/keyboards/momokai/tap_trio_pro/matrix.c b/keyboards/momokai/tap_trio_pro/matrix.c index b0e1a59be2a..adfd5479883 100644 --- a/keyboards/momokai/tap_trio_pro/matrix.c +++ b/keyboards/momokai/tap_trio_pro/matrix.c @@ -11,6 +11,8 @@ #include "debounce.h" #include "scanfunctions.h" #include "sma.c" +#include "quantum/matrix.h" + #ifndef MATRIX_INPUT_PRESSED_STATE # define MATRIX_INPUT_PRESSED_STATE 0 @@ -27,6 +29,30 @@ static uint16_t restAdcValue = 0; matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values matrix_row_t matrix[MATRIX_ROWS]; // debounced values +static inline uint8_t readMatrixPin(pin_t pin) { + if (pin != NO_PIN) { + return (gpio_read_pin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1; + } else { + return 1; + } +} + +void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { + // Start with a clear matrix row + matrix_row_t current_row_value = 0; + + matrix_row_t row_shifter = MATRIX_ROW_SHIFTER; + for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) { + pin_t pin = matrix_pins[current_row][col_index]; + current_row_value |= readMatrixPin(pin) ? 0 : row_shifter; + } + + // Update the matrix + current_matrix[current_row] = current_row_value; +} + + + // Setup only rows 1, leave row 0 untouched (for analog) void matrix_init_pins(void) { for (int row = 0; row < MATRIX_ROWS; row++) { @@ -56,10 +82,6 @@ void matrix_init_custom(void) { get_sensor_offsets(); } -// User-defined overridable functions -__attribute__((weak)) void matrix_init_pins(void); -__attribute__((weak)) void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row); -__attribute__((weak)) void matrix_read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col, matrix_row_t row_shifter); @@ -70,7 +92,7 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) { memcpy(previous_matrix, current_matrix, sizeof(previous_matrix)); for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) { - if (!keys[current_row][0].is_analog) { + if (current_row == 1) { matrix_read_cols_on_row(current_matrix, current_row); } else { for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) { @@ -105,9 +127,4 @@ uint8_t matrix_scan(void) { return (uint8_t)changed; } -__attribute__((weak)) void matrix_init_kb(void) { matrix_init_user(); } -__attribute__((weak)) void matrix_scan_kb(void) { matrix_scan_user(); } -__attribute__((weak)) void matrix_init_user(void) {} -__attribute__((weak)) void matrix_scan_user(void) {} - diff --git a/keyboards/momokai/tap_trio_pro/psudocode b/keyboards/momokai/tap_trio_pro/psudocode index 27c083297ec..46242d619ac 100644 --- a/keyboards/momokai/tap_trio_pro/psudocode +++ b/keyboards/momokai/tap_trio_pro/psudocode @@ -48,7 +48,7 @@ matrix scanning: 4. if a new peak is observed, update it in the key structure peak here is a up or down, since keeping track of both doesn't make sense - +https://www.desmos.com/calculator/qtbbjbsyvi diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c index 0a0e37a9b7c..e2959d11a9e 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.c +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -35,12 +35,12 @@ void deregister_key(matrix_row_t *current_row, uint8_t current_col) { } void matrix_read_cols_static_actuation(matrix_row_t *current_row, uint8_t current_col, hybrid_key_t *key) { - if (*current_row & (1 << current_col)) { //if the key is currently pressed - if (key->value < MAX(g_config.actuation_point - g_config.release_hysteresis, 0)) { + if (*current_row & (1 << current_col)) { + if (key->value <= MAX(g_config.actuation_point - g_config.release_hysteresis, 0)) { deregister_key(current_row, current_col); } - } else { //if the key is currently not pressed - if (key->value > MIN(g_config.actuation_point + g_config.press_hysteresis, 255)) { + } else { + if (key->value >= MIN(g_config.actuation_point + g_config.press_hysteresis, CALIBRATION_RANGE)) { register_key(current_row, current_col); } } @@ -53,13 +53,14 @@ if the key is pressed, the extremum is the lowest value reached, if the key is not pressed, the extremum is the highest value reached. */ void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hybrid_key_t *key) { - if (key->dynamic_actuation_bool) { + if (key->value > g_config.actuation_point) { + /* In DA zone? */ if (*current_row & (1 << current_col)) { /* Key is pressed Is key still moving down? */ if (key->value > key->extremum) { update_extremum(key); - } else if (key->value < key->extremum - g_config.release_sensitivity) { + } else if (key->value <= MAX(key->extremum - g_config.release_sensitivity, 0)) { /* Has key moved up enough to be released? */ deregister_key(current_row, current_col); update_extremum(key); @@ -69,32 +70,31 @@ void matrix_read_cols_dynamic_actuation(matrix_row_t *current_row, uint8_t curre Is the key still moving up? */ if (key->value < key->extremum) { update_extremum(key); - } else if (key->value > key->extremum + g_config.press_sensitivity) { + } else if (key->value >= MIN(key->extremum + g_config.press_sensitivity, CALIBRATION_RANGE)) { /* Has key moved down enough to be pressed? */ register_key(current_row, current_col); update_extremum(key); } } - if (key->value < g_config.actuation_point - 5) { - deregister_key(current_row, current_col); + } else { + /* Out of DA zone + Always deregister key */ + deregister_key(current_row, current_col); + if (key->value > key->extremum) { update_extremum(key); - key->dynamic_actuation_bool = false; } - } else if (key->value > g_config.actuation_point) { - register_key(current_row, current_col); - update_extremum(key); - key->dynamic_actuation_bool = true; } } void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, uint8_t current_col, hybrid_key_t *key) { - if (key->dynamic_actuation_bool) { + if (key->continuous_dynamic_actuation) { if (*current_row & (1 << current_col)) { /* Key is pressed Is key still moving down? */ if (key->value > key->extremum) { update_extremum(key); - } else if (key->value < key->extremum - g_config.release_sensitivity) { + + } else if (key->value <= MAX(key->extremum - g_config.release_sensitivity, 0)) { /* Has key moved up enough to be released? */ deregister_key(current_row, current_col); update_extremum(key); @@ -104,7 +104,7 @@ void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, ui Is the key still moving up? */ if (key->value < key->extremum) { update_extremum(key); - } else if (key->value > key->extremum + g_config.press_sensitivity) { + } else if (key->value >= MIN(key->extremum + g_config.press_sensitivity, CALIBRATION_RANGE)) { /* Has key moved down enough to be pressed? */ register_key(current_row, current_col); update_extremum(key); @@ -113,11 +113,11 @@ void matrix_read_cols_continuous_dynamic_actuation(matrix_row_t *current_row, ui if (key->value == 0) { deregister_key(current_row, current_col); update_extremum(key); - key->dynamic_actuation_bool = false; + key->continuous_dynamic_actuation = false; } } else if (key->value > g_config.actuation_point) { register_key(current_row, current_col); update_extremum(key); - key->dynamic_actuation_bool = true; + key->continuous_dynamic_actuation = true; } } diff --git a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c index 914015fef8b..71864860b51 100644 --- a/keyboards/momokai/tap_trio_pro/tap_trio_pro.c +++ b/keyboards/momokai/tap_trio_pro/tap_trio_pro.c @@ -53,12 +53,12 @@ bool debug_print(void) { // uprintf("%s", buffer); - int raw_analog_value[3]; - for (uint8_t col = 0; col < MATRIX_COLS; col++) { + // int raw_analog_value[3]; + // for (uint8_t col = 0; col < MATRIX_COLS; col++) { - raw_analog_value[col] = analogReadPin(matrix_pins[0][col]); - } - printf("raw_analog_value = %d, %d, %d\n", raw_analog_value[0], raw_analog_value[1], raw_analog_value[2]); + // raw_analog_value[col] = analogReadPin(matrix_pins[0][col]); + // } + // printf("raw_analog_value = %d, %d, %d\n", raw_analog_value[0], raw_analog_value[1], raw_analog_value[2]); return true; }