summaryrefslogtreecommitdiff
path: root/atmel-samd
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2017-10-01 14:43:42 -0400
committerScott Shawcroft <scott@tannewt.org>2017-10-02 11:15:51 -0700
commit7f744128826b8328aaa6434fdcb8f0a272c87d72 (patch)
treef83374d475e9d42e472c7a4645759a44f40c67bb /atmel-samd
parentb2dcc5bb6c50f9b6eb3c294c98df8a5880167fd8 (diff)
Make touch more sensitive. Add .raw_value and .threshold attributes.
Diffstat (limited to 'atmel-samd')
-rw-r--r--atmel-samd/Makefile2
-rw-r--r--atmel-samd/common-hal/touchio/TouchIn.c21
2 files changed, 21 insertions, 2 deletions
diff --git a/atmel-samd/Makefile b/atmel-samd/Makefile
index 1e5fe110d..501851ab1 100644
--- a/atmel-samd/Makefile
+++ b/atmel-samd/Makefile
@@ -137,7 +137,7 @@ CFLAGS += -Os -ggdb -DNDEBUG -DENABLE_MICRO_TRACE_BUFFER -DMICROPY_DEBUG_MODULES
else
# -finline-limit can shrink the image size. -finline-limit=80 or so is similar to not having it on.
# There is no simple default value, though.
-CFLAGS += -Os -DNDEBUG -flto -finline-limit=49
+CFLAGS += -Os -DNDEBUG -flto -finline-limit=39
endif
ifneq ($(FROZEN_DIR),)
diff --git a/atmel-samd/common-hal/touchio/TouchIn.c b/atmel-samd/common-hal/touchio/TouchIn.c
index 3575de3ed..ddfd1055a 100644
--- a/atmel-samd/common-hal/touchio/TouchIn.c
+++ b/atmel-samd/common-hal/touchio/TouchIn.c
@@ -71,7 +71,14 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self,
adafruit_ptc_init(PTC, &self->config);
- self->threshold = 2 * get_raw_reading(self);
+ // Initial values for pins will vary, depending on what peripherals the pins
+ // share on-chip.
+ //
+ // Set a "touched" threshold not too far above the initial value.
+ // For simple finger touch, the values may vary as much as a factor of two,
+ // but for touches using fruit or other objects, the difference is much less.
+
+ self->threshold = get_raw_reading(self) + 100;
}
void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) {
@@ -87,3 +94,15 @@ bool common_hal_touchio_touchin_get_value(touchio_touchin_obj_t *self) {
uint16_t reading = get_raw_reading(self);
return reading > self->threshold;
}
+
+uint16_t common_hal_touchio_touchin_get_raw_value(touchio_touchin_obj_t *self) {
+ return get_raw_reading(self);
+}
+
+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) {
+ self->threshold = new_threshold;
+}