Touchin.c - fix clean up in constructor before exception is thrown

When the constructor value reading times out, an exception is thrown, but the digital pin is not de-initialised. Make sure to run the clean up, so user could catch the exception and retry using the same pin.
This commit is contained in:
Hanns Holger Rutz 2022-08-10 21:49:18 +02:00 committed by GitHub
parent c2a45c1f27
commit 92231e88ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 0 deletions

View File

@ -78,6 +78,7 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self, const mcu
uint16_t raw_reading = get_raw_reading(self);
if (raw_reading == TIMEOUT_TICKS) {
common_hal_touchio_touchin_deinit(self);
mp_raise_ValueError(translate("No pulldown on pin; 1Mohm recommended"));
}
self->threshold = raw_reading * 1.05 + 100;