From 57c97b1c622f2d46a67d55196da5b6785ab8a133 Mon Sep 17 00:00:00 2001 From: CubicFX <167459298+CubicFX@users.noreply.github.com> Date: Wed, 21 Aug 2024 23:35:37 -0400 Subject: [PATCH] lut values --- keyboards/cubicfx/keypad/keypad.c | 2 +- keyboards/cubicfx/keypad/lut.c | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/keyboards/cubicfx/keypad/keypad.c b/keyboards/cubicfx/keypad/keypad.c index 4c8e0054c739..b24951944783 100644 --- a/keyboards/cubicfx/keypad/keypad.c +++ b/keyboards/cubicfx/keypad/keypad.c @@ -40,7 +40,7 @@ bool debug_print(void) { for (uint8_t col = 0; col < MATRIX_COLS; col++) { analog_key_t *key = &keys[currentRow][col]; if (key->raw) { - bufferPtr += snprintf(bufferPtr, sizeof(rowBuffer) - (bufferPtr - rowBuffer), "%5u ", key->raw); + bufferPtr += snprintf(bufferPtr, sizeof(rowBuffer) - (bufferPtr - rowBuffer), "%5u ", key->value); } else { bufferPtr += snprintf(bufferPtr, sizeof(rowBuffer) - (bufferPtr - rowBuffer), " null "); } diff --git a/keyboards/cubicfx/keypad/lut.c b/keyboards/cubicfx/keypad/lut.c index 0a349a01a897..7f193b7fa07a 100644 --- a/keyboards/cubicfx/keypad/lut.c +++ b/keyboards/cubicfx/keypad/lut.c @@ -4,10 +4,10 @@ SPDX-License-Identifier: GPL-2.0-or-later */ #include "scanfunctions.h" #include "util.h" - const double lut_a = 16654600.6755; // Lekker - const double lut_b = -0.00955994866577; - const double lut_c = -1278.75103145; - const double lut_d = 16652478.4163; + // const double lut_a = 16654600.6755; // Lekker + // const double lut_b = -0.00955994866577; + // const double lut_c = -1278.75103145; + // const double lut_d = 16652478.4163; /* Equation parameters for the sensor-magnet linearity mapping */ // const double lut_a = 0.200347177016; // Latenpow @@ -15,6 +15,11 @@ SPDX-License-Identifier: GPL-2.0-or-later */ // const double lut_c = 6.01110636956; // const double lut_d = 1966.74076381; + const double lut_a = 0.095; // Cubic + const double lut_b = 0.01; + const double lut_c = 0; + const double lut_d = 350; + uint16_t distance_to_adc(uint8_t distance) { double intermediate = lut_a * exp(lut_b * distance + lut_c) + lut_d; uint16_t adc = (uint16_t) MAX(0, MIN(intermediate, 4095));