mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-07-27 19:41:16 +00:00
cleanup code, add raw value output
This commit is contained in:
parent
8781b54ee1
commit
20e7dae92a
@ -10,7 +10,7 @@
|
|||||||
#define DEBUG_ENABLE
|
#define DEBUG_ENABLE
|
||||||
// #define DEBUG_MATRIX_SCAN_RATE
|
// #define DEBUG_MATRIX_SCAN_RATE
|
||||||
|
|
||||||
#define ADC_RESOLUTION 12
|
#define ADC_RESOLUTION 8
|
||||||
|
|
||||||
#define CALIBRATION_RANGE 255
|
#define CALIBRATION_RANGE 255
|
||||||
|
|
||||||
|
@ -1,28 +1,34 @@
|
|||||||
/* Copyright 2023 RephlexZero (@RephlexZero)
|
/* Copyright 2023 RephlexZero (@RephlexZero) 2024 peepeetee (@peepeetee)
|
||||||
SPDX-License-Identifier: GPL-2.0-or-later */
|
SPDX-License-Identifier: GPL-2.0-or-later */
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "scanfunctions.h"
|
#include "scanfunctions.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
/* Equation parameters for the sensor-magnet linearity mapping */
|
/* Equation parameters for the sensor-magnet linearity mapping */
|
||||||
const double a = 16654600.6755;
|
const double a = 0.200347177016;
|
||||||
const double b = -0.00955994866577;
|
const double b = 0.00955994866154;
|
||||||
const double c = -1278.75103145;
|
const double c = 6.01110636956;
|
||||||
const double d = 16652478.4163;
|
const double d = 1966.74076381;
|
||||||
|
|
||||||
uint16_t distance_to_adc(uint8_t distance) {
|
uint16_t distance_to_adc(uint8_t distance) {
|
||||||
distance = MIN(MAX(distance, 0), 255);
|
double intermediate = a * exp(b * distance + c) + d;
|
||||||
return a * (1 - exp(-b * (distance + c))) - d;
|
uint16_t adc = (uint16_t) MAX(0, MIN(intermediate, 4095));
|
||||||
|
return adc;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t adc_to_distance(uint16_t adc) {
|
uint8_t adc_to_distance(uint16_t adc) {
|
||||||
return MIN(MAX(((log(1 - ((adc + d) / a)) / -b) - c), 0), 255);
|
if (adc <= d) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
double intermediate = (log((adc - d) / a) - c) / b;
|
||||||
|
uint8_t distance = (uint8_t) MAX(0, MIN(intermediate, 255));
|
||||||
|
return distance;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t lut[4096] = {0};
|
uint8_t lut[ADC_RESOLUTION_MAX] = {0};
|
||||||
|
|
||||||
void generate_lut(void) {
|
void generate_lut(void) {
|
||||||
for (uint16_t i = 0; i < a - d; i++) {
|
for (uint16_t i = 0; i < ADC_RESOLUTION_MAX; i++) {
|
||||||
lut[i] = adc_to_distance(i);
|
lut[i] = adc_to_distance(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,6 +212,11 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
|
|||||||
// matrix_row_t is an alias for u_int8_t
|
// matrix_row_t is an alias for u_int8_t
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
memcpy(previous_matrix, current_matrix, sizeof(previous_matrix));
|
memcpy(previous_matrix, current_matrix, sizeof(previous_matrix));
|
||||||
|
|
||||||
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
||||||
|
@ -34,28 +34,35 @@ void bootmagic_lite(void) {
|
|||||||
# ifdef DEBUG_ENABLE
|
# ifdef DEBUG_ENABLE
|
||||||
deferred_token debug_token;
|
deferred_token debug_token;
|
||||||
bool debug_print(void) {
|
bool debug_print(void) {
|
||||||
uint8_t hall_effect_rows = 1;
|
// uint8_t hall_effect_rows = 1;
|
||||||
char buffer[hall_effect_rows * MATRIX_COLS * 5 + MATRIX_ROWS * 2];
|
// char buffer[hall_effect_rows * MATRIX_COLS * 5 + MATRIX_ROWS * 2];
|
||||||
buffer[0] = '\0';
|
// buffer[0] = '\0';
|
||||||
|
|
||||||
// for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
// // for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||||
uint8_t row = 1;
|
// uint8_t row = 1;
|
||||||
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
|
// for (uint8_t col = 0; col < MATRIX_COLS; col++) {
|
||||||
hybrid_key_t *key = &keys[row][col];
|
// hybrid_key_t *key = &keys[row][col];
|
||||||
char temp[6];
|
// char temp[6];
|
||||||
snprintf(temp, sizeof(temp), "%5u", key->value);
|
// snprintf(temp, sizeof(temp), "%5u", key->value);
|
||||||
strcat(buffer, temp);
|
// strcat(buffer, temp);
|
||||||
}
|
// }
|
||||||
strcat(buffer, "\n");
|
// strcat(buffer, "\n");
|
||||||
// }
|
// // }
|
||||||
|
|
||||||
uprintf("%s", buffer);
|
// uprintf("%s", buffer);
|
||||||
|
|
||||||
|
int raw_analog_value[3];
|
||||||
|
for (uint8_t col = 0; col < MATRIX_COLS; col++) {
|
||||||
|
|
||||||
|
raw_analog_value[col] = analogReadPin(matrix_pins[1][col]);
|
||||||
|
}
|
||||||
|
printf("raw_analog_value = %d, %d, %d\n", raw_analog_value[0], raw_analog_value[1], raw_analog_value[2]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t debug_print_callback(uint32_t trigger_time, void *cb_arg) {
|
uint32_t debug_print_callback(uint32_t trigger_time, void *cb_arg) {
|
||||||
// debug_print();
|
debug_print();
|
||||||
return 25;
|
return 25;
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
Loading…
Reference in New Issue
Block a user