Skip to content
Snippets Groups Projects
Commit 41c52655 authored by moon2's avatar moon2 :speech_balloon:
Browse files

captouch: fix false negatives from .calibration_active()

parent 2d81adb7
No related branches found
No related tags found
1 merge request!623captouch: fix false negatives from .calibration_active()
Pipeline #12529 passed
......@@ -158,17 +158,18 @@ static void _on_data(void *user, uint16_t *data, size_t len) {
if (chip->seq_position == 0) {
// Deal with calibration pending flag, possibly starting calibration.
if (chip->calibration_pending) {
if (chip->calibration_cycles == 0) {
if (!chip->calibration_active) {
ESP_LOGI(TAG, "%s: calibration starting...", chip->name);
chip->calibration_cycles = _AD7147_CALIB_CYCLES;
chip->calibration_active = true;
}
chip->calibration_pending = false;
}
if (chip->calibration_cycles > 0) {
if (chip->calibration_active) {
// Deal with active calibration.
chip->calibration_cycles--;
if (chip->calibration_cycles == 0) {
if (chip->calibration_cycles <= 0) {
// Calibration measurements done. Calculate average amb data for
// each channel.
for (size_t i = 0; i < chip->nchannels; i++) {
......@@ -206,6 +207,7 @@ static void _on_data(void *user, uint16_t *data, size_t len) {
chip->name, rerun);
chip->calibration_cycles = _AD7147_CALIB_CYCLES;
} else {
chip->calibration_active = false;
ESP_LOGI(TAG, "%s: calibration done.", chip->name);
}
}
......
......@@ -61,8 +61,9 @@ typedef struct {
ad7147_hw_t dev;
bool failed;
bool calibration_pending;
size_t calibration_cycles;
volatile bool calibration_pending;
volatile bool calibration_active;
int8_t calibration_cycles;
} ad7147_chip_t;
// Call to initialize the chip at a given address. Structure must be zeroed, and
......@@ -75,4 +76,4 @@ esp_err_t flow3r_bsp_ad7147_chip_init(ad7147_chip_t *chip,
// Call to poll the chip and perform any necessary actions. Can be called from
// an interrupt.
esp_err_t flow3r_bsp_ad7147_chip_process(ad7147_chip_t *chip);
\ No newline at end of file
esp_err_t flow3r_bsp_ad7147_chip_process(ad7147_chip_t *chip);
......@@ -378,7 +378,7 @@ void flow3r_bsp_captouch_calibrate() {
}
bool flow3r_bsp_captouch_calibrating() {
bool bot = _bot.calibration_pending || _bot.calibration_cycles > 0;
bool top = _top.calibration_pending || _top.calibration_cycles > 0;
bool bot = _bot.calibration_pending || _bot.calibration_active;
bool top = _top.calibration_pending || _top.calibration_active;
return bot || top;
}
......@@ -83,6 +83,4 @@ flow3r_bsp_captouch_petal_pad_state_t *flow3r_bsp_captouch_pad_for_petal(
void flow3r_bsp_captouch_calibrate();
// Returns true if captouch is currently calibrating.
//
// TODO(q3k): this seems glitchy, investigate.
bool flow3r_bsp_captouch_calibrating();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment