Automatically set a default threshold for touchio.TouchIn channels

This commit is contained in:
Nick Moore 2019-01-28 18:22:57 +11:00
parent 539aaf08b5
commit 294b026aca

View File

@ -77,6 +77,8 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self,
const mcu_pin_obj_t *pin) { const mcu_pin_obj_t *pin) {
self->pin = pin; self->pin = pin;
claim_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) { 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; 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; self->threshold = new_threshold;
} }