mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-23 16:12:07 +00:00
tuned, working
This commit is contained in:
parent
21fef7962b
commit
3d11feebf2
@ -6,12 +6,11 @@
|
||||
#define DYNAMIC_KEYMAP_LAYER_COUNT 1
|
||||
|
||||
#define EECONFIG_KB_DATA_SIZE 6
|
||||
|
||||
#define DEBUG_ENABLE
|
||||
// #define DEBUG_MATRIX_SCAN_RATE
|
||||
|
||||
#define ADC_RESOLUTION 12
|
||||
#define ADC_RESOLUTION_MAX 1 << 12
|
||||
#define ADC_RESOLUTION_MAX 4096 //1 << 12
|
||||
|
||||
#define CALIBRATION_RANGE 255
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* Copyright 2024 Jenna Fligor (@Ex-32)
|
||||
SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee)
|
||||
/* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee) 2024 Jenna Fligor (@Ex-32)
|
||||
SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
@ -14,37 +14,37 @@ SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#endif
|
||||
|
||||
// /* Equation parameters for the sensor-magnet linearity mapping */
|
||||
// const double a = 0.200347177016;
|
||||
// const double b = 0.00955994866154;
|
||||
// const double c = 6.01110636956;
|
||||
// const double d = 1966.74076381;
|
||||
// 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 a = 1;
|
||||
// const double b = 0.0061787;
|
||||
// const double c = 4.34;
|
||||
// const double d = 1935.43;
|
||||
// const double lut_a = 1;
|
||||
// const double lut_b = 0.0061787;
|
||||
// const double lut_c = 4.34;
|
||||
// const double lut_d = 1935.43;
|
||||
|
||||
const double a = 0.00609446727442;
|
||||
const double b = 4.40340283615;
|
||||
const double c = 2122.25923605;
|
||||
const double lut_a = 0.00609446727442;
|
||||
const double lut_b = 4.40340283615;
|
||||
const double lut_c = 2000;
|
||||
|
||||
uint16_t distance_to_adc(uint16_t distance) {
|
||||
// double intermediate = a * exp(b * distance + c) + d;
|
||||
double intermediate = ((-exp(a*distance + b)) + c);
|
||||
uint16_t adc = (uint16_t) MAX(0, MIN(intermediate, 4095));
|
||||
// double intermediate = lut_a * exp(lut_b * distance + lut_c) + lut_d;
|
||||
double intermediate = ((-exp(lut_a*distance + lut_b)) + lut_c);
|
||||
uint16_t adc = (uint16_t) MAX(0, MIN(intermediate, ADC_RESOLUTION_MAX -1));
|
||||
return adc;
|
||||
}
|
||||
|
||||
uint16_t adc_to_distance(uint16_t adc) {
|
||||
// if (adc <= d) {
|
||||
// if (adc <= lut_c) {
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
// double intermediate = ((log((adc - d) / a)) - c) / b;
|
||||
// double intermediate = ((log((adc - lut_d) / lut_a)) - lut_c) / lut_b;
|
||||
|
||||
double intermediate = ((log(c-adc)-b)/a);
|
||||
uint16_t distance = (uint16_t) MAX(0, MIN(intermediate, 255));
|
||||
double intermediate = ((log(lut_c-adc)-lut_b)/lut_a);
|
||||
uint16_t distance = (uint16_t) MAX(0, MIN(intermediate, 400));
|
||||
return distance;
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,11 @@ SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
extern uint16_t lut[4096];
|
||||
extern uint16_t lut[ADC_RESOLUTION_MAX];
|
||||
|
||||
const double lut_a;
|
||||
const double lut_b;
|
||||
const double lut_c;
|
||||
|
||||
uint16_t distance_to_adc(uint16_t distance);
|
||||
|
||||
|
@ -27,6 +27,9 @@ pin_t matrix_pins[MATRIX_ROWS][MATRIX_COLS] = DIRECT_PINS;
|
||||
|
||||
hybrid_key_t keys[MATRIX_ROWS][MATRIX_COLS] = {0};
|
||||
|
||||
static uint16_t pressedAdcValue = 0;
|
||||
static uint16_t restAdcValue = 0;
|
||||
|
||||
/* matrix state(1:on, 0:off) */
|
||||
matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values
|
||||
matrix_row_t matrix[MATRIX_ROWS]; // debounced values
|
||||
@ -85,7 +88,9 @@ void matrix_init_custom(void) {
|
||||
// }
|
||||
|
||||
generate_lut();
|
||||
get_sensor_offsets();
|
||||
pressedAdcValue = distance_to_adc(400);
|
||||
restAdcValue = distance_to_adc(0);
|
||||
// get_sensor_offsets();
|
||||
wait_ms(200); // Let ADC reach steady state
|
||||
get_sensor_offsets();
|
||||
}
|
||||
@ -220,7 +225,7 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
|
||||
key->value = lut[analogReadPin(matrix_pins[current_row][current_col]) + key->offset];
|
||||
// limits our options, I would like to change hybrid_key_t to include weather it is a hall effect key
|
||||
|
||||
key->value = MIN((key->value << 8) / lut[1100 + key->offset], 255);
|
||||
// key->value = MIN((key->value << 8) / lut[1100 + key->offset], 400);
|
||||
|
||||
switch (g_config.mode) {
|
||||
case dynamic_actuation:
|
||||
|
Loading…
Reference in New Issue
Block a user