diff options
| author | Dan Halbert <halbert@halwitz.org> | 2019-08-19 23:40:34 -0400 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2019-08-19 23:40:34 -0400 |
| commit | cccbbd956dbc976a4c059f11dfa1410341a51dc1 (patch) | |
| tree | 3f71018cfe52b99393afe2bb008b2aaf8b5369d6 /shared-module | |
| parent | e2a4c76a3745c512eb85ca5555ec35e5f7d52769 (diff) | |
Detect lack of pulldown; check for pin in use
Diffstat (limited to 'shared-module')
| -rw-r--r-- | shared-module/touchio/TouchIn.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/shared-module/touchio/TouchIn.c b/shared-module/touchio/TouchIn.c index 056556c90..88d12b8b8 100644 --- a/shared-module/touchio/TouchIn.c +++ b/shared-module/touchio/TouchIn.c @@ -67,12 +67,17 @@ static uint16_t get_raw_reading(touchio_touchin_obj_t *self) { } void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self, const mcu_pin_obj_t *pin) { + claim_pin(pin); self->digitalinout = m_new_obj(digitalio_digitalinout_obj_t); self->digitalinout->base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(self->digitalinout, pin); - self->threshold = get_raw_reading(self) * 1.05 + 100; + uint16_t raw_reading = get_raw_reading(self); + if (raw_reading == TIMEOUT_TICKS) { + mp_raise_ValueError(translate("No pulldown on pin; 1Mohm recommended")); + } + self->threshold = raw_reading * 1.05 + 100; } bool common_hal_touchio_touchin_deinited(touchio_touchin_obj_t* self) { |
