From 294b026aca2dfbcef3f8abae9054d6f04c60a61f Mon Sep 17 00:00:00 2001 From: Nick Moore Date: Mon, 28 Jan 2019 18:22:57 +1100 Subject: [PATCH] Automatically set a default threshold for touchio.TouchIn channels --- ports/nrf/common-hal/touchio/TouchIn.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ports/nrf/common-hal/touchio/TouchIn.c b/ports/nrf/common-hal/touchio/TouchIn.c index 5d8d640e07..ba50b17b0c 100644 --- a/ports/nrf/common-hal/touchio/TouchIn.c +++ b/ports/nrf/common-hal/touchio/TouchIn.c @@ -77,6 +77,8 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self, const mcu_pin_obj_t *pin) { self->pin = pin; claim_pin(pin); + + self->threshold = get_raw_reading(self) * 1.05 + 100; } bool common_hal_touchio_touchin_deinited(touchio_touchin_obj_t* self) { @@ -108,6 +110,7 @@ uint16_t common_hal_touchio_touchin_get_threshold(touchio_touchin_obj_t *self) { return self->threshold; } -void common_hal_touchio_touchin_set_threshold(touchio_touchin_obj_t *self, uint16_t new_threshold) { +void common_hal_touchio_touchin_set_threshold(touchio_touchin_obj_t *self, + uint16_t new_threshold) { self->threshold = new_threshold; }