diff --git a/keyboards/momokai/tap_trio_pro/analogkeys.h b/keyboards/momokai/tap_trio_pro/analogkeys.h index dd3b969060a..21178b12d12 100644 --- a/keyboards/momokai/tap_trio_pro/analogkeys.h +++ b/keyboards/momokai/tap_trio_pro/analogkeys.h @@ -16,6 +16,7 @@ typedef struct { uint8_t press_hysteresis; uint8_t release_hysteresis; } analog_config; /* 6 bytes */ +//size defined in config.h _Static_assert(sizeof(analog_config) == EECONFIG_KB_DATA_SIZE, "Size mismatch"); extern analog_config g_config; @@ -32,5 +33,6 @@ typedef struct { uint16_t *SMA_buffer; uint32_t SMA_sum; uint8_t SMA_index; + bool SMA_filled; } hybrid_key_t; extern hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS]; diff --git a/keyboards/momokai/tap_trio_pro/scanfunctions.c b/keyboards/momokai/tap_trio_pro/scanfunctions.c index f14af7b4173..02a698f6bcb 100644 --- a/keyboards/momokai/tap_trio_pro/scanfunctions.c +++ b/keyboards/momokai/tap_trio_pro/scanfunctions.c @@ -1,4 +1,4 @@ -/* Copyright 2023 RephlexZero (@RephlexZero) +/* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee) SPDX-License-Identifier: GPL-2.0-or-later */ #include "quantum.h" #include "analog.h" @@ -7,6 +7,7 @@ SPDX-License-Identifier: GPL-2.0-or-later */ extern pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS]; +//detects sensor offsets when the key is not pressed void get_sensor_offsets(void) { uint16_t rest_adc_value = distance_to_adc(0); for (uint8_t i = 0; i < MATRIX_ROWS; i++) { diff --git a/keyboards/momokai/tap_trio_pro/sma.c b/keyboards/momokai/tap_trio_pro/sma.c index 5b162ce80b8..eda3d229555 100644 --- a/keyboards/momokai/tap_trio_pro/sma.c +++ b/keyboards/momokai/tap_trio_pro/sma.c @@ -9,7 +9,10 @@ SPDX-License-Identifier: GPL-2.0-or-later */ void initialize_SMA_filter(hybrid_key_t key, uint8_t samplesExponent) { key.SMA_samplesExponent = samplesExponent; key.SMA_samples = 1 << samplesExponent; - key.SMA_buffer = malloc(key.SMA_samples*sizeof(uint16_t)); + key.SMA_buffer = malloc((key.SMA_samples)*sizeof(uint16_t)); + for (int i = 0; i < key.SMA_samples; i++) { + key.SMA_buffer[i] = 0; + } printf("%s\n", "SMA_buffer test print"); key.SMA_sum = 0; key.SMA_index = 0; @@ -19,6 +22,12 @@ uint16_t SMA_filter(hybrid_key_t key, uint16_t value) { key.SMA_sum = key.SMA_sum - key.SMA_buffer[key.SMA_index] + value; key.SMA_buffer[key.SMA_index] = value; key.SMA_index = (key.SMA_index + 1) % key.SMA_samples; + if (!key.SMA_filled) { + if (key.SMA_index == 0) { + key.SMA_filled = true; + } + } + printf("%s\n", "SMA_filter test print"); printf("%s\n", "SMA_sum and SMA_index:"); printf("%lu\n", key.SMA_sum);