Skip to content

Commit b3f2bfb

Browse files
committed
Add the ability to set sensitivity for each channel separately. #1
Squashed commit of the following: commit 92c7caf23deb1558fca2dcc68f34f666a011dad3 Author: Alessandro Ranellucci <[email protected]> Date: Tue Jan 12 15:31:20 2021 +0100 Rename setSensorsSensitivityChannel() to setSensorsSensitivity(). #1 commit cdf69f9 Author: marqdevx <[email protected]> Date: Tue Jan 12 15:18:58 2021 +0100 Update src/Arduino_MCHPTouch.h Co-authored-by: Alessandro Ranellucci <[email protected]> commit b51abcf Author: marqdevx <[email protected]> Date: Mon Jan 11 13:26:31 2021 +0100 Update version to 1.1.0 Update version to 1.1.0 commit c200d9a Author: marqdevx <[email protected]> Date: Mon Dec 28 10:17:45 2020 +0100 Update examples/setCustomSensitivity/setCustomSensitivity.ino Co-authored-by: per1234 <[email protected]> commit 01612e7 Author: marqdevx <[email protected]> Date: Mon Dec 28 10:15:24 2020 +0100 Update examples/setCustomSensitivity/setCustomSensitivity.ino Co-authored-by: per1234 <[email protected]> commit 504779a Author: marqdevx <[email protected]> Date: Mon Dec 28 10:15:03 2020 +0100 Update examples/setCustomSensitivity/setCustomSensitivity.ino Co-authored-by: per1234 <[email protected]> commit e5df053 Author: marqdevx <[email protected]> Date: Wed Dec 23 11:41:12 2020 +0100 Added custom sensitivity example commit 4d2c11c Author: marqdevx <[email protected]> Date: Wed Dec 23 11:36:19 2020 +0100 added individual sens config * Added the feature to customize each channel configuration (5 channels by default, meant to be used in the MKR IoT Carrier)
1 parent 12670d2 commit b3f2bfb

File tree

6 files changed

+90
-11
lines changed

6 files changed

+90
-11
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Arduino_MCHPTouch - Sensor data read Example
3+
This example shows how to configure and read data
4+
from touch sensor buttons on MKR IoT Carrier and
5+
6+
prints updates to the Serial Monitor.
7+
8+
The circuit:
9+
- Arduino MKR board;
10+
11+
- MKR IoT carrier.
12+
13+
This example code is in the public domain.
14+
*/
15+
#include "Arduino_MCHPTouch.h"
16+
17+
void setup()
18+
{
19+
Serial.begin(9600);
20+
while (!Serial)
21+
;
22+
//Set custom sens on X channel
23+
//TOUCH.setSensorsSensitivity(*channel*, *newSensitivity*);
24+
TOUCH.setSensorsSensitivity(0, 98);
25+
// Qtouch initialization
26+
if (!TOUCH.begin())
27+
{
28+
Serial.println("Error in sensors initialization!");
29+
while (1)
30+
;
31+
}
32+
Serial.println("Touch initialization Done!");
33+
}
34+
35+
void loop()
36+
{
37+
// polling the sensor for new measure
38+
TOUCH.poll();
39+
40+
// Checks if new data are available
41+
if (TOUCH.available())
42+
{
43+
//reads sensors
44+
45+
Serial.print("Sensor 1 status: ");
46+
Serial.println(TOUCH.read(0));
47+
Serial.print("Sensor 2 status: ");
48+
Serial.println(TOUCH.read(1));
49+
Serial.print("Sensor 3 status: ");
50+
Serial.println(TOUCH.read(2));
51+
Serial.print("Sensor 4 status: ");
52+
Serial.println(TOUCH.read(3));
53+
Serial.print("Sensor 5 status: ");
54+
Serial.println(TOUCH.read(4));
55+
Serial.println();
56+
}
57+
delay(100);
58+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Arduino_MCHPTouch
2-
version=1.0.0
2+
version=1.1.0
33
author=Arduino
44
maintainer=Arduino <[email protected]>
55
sentence=A library for the Atmel touch sensors

src/Arduino_MCHPTouch.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int QtouchClass::read(int sensor_id)
8686

8787
/*******************************************************************************
8888
* Function Name : setSensorsSensitivity
89-
* Description : Sets the sensors sensitivity value
89+
* Description : Sets all the sensors sensitivity value
9090
* Input : newSens - new configure Sensitivity value
9191
* Return : NONE
9292
*******************************************************************************/
@@ -95,6 +95,17 @@ void QtouchClass::setSensorsSensitivity(unsigned int newSens)
9595
setSensitivity(newSens);
9696
}
9797

98+
/*******************************************************************************
99+
* Function Name : setSensorsSensitivity
100+
* Description : Sets a sensor sensitivity value
101+
* Input : newSens - new configure Sensitivity value , btn_channel - channel to apply that Sensitivity
102+
* Return : NONE
103+
*******************************************************************************/
104+
void QtouchClass::setSensorsSensitivity(unsigned int newSens, unsigned int btn_channel)
105+
{
106+
setSensitivityChannel(newSens, btn_channel);
107+
}
108+
98109
/*******************************************************************************
99110
* Function Name : setSensorsHysteresis
100111
* Description : Set the sensors hysteresis value

src/Arduino_MCHPTouch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class QtouchClass
2323
int available();
2424
int read(int sensor_id);
2525
void setSensorsSensitivity(unsigned int newSens);
26+
void setSensorsSensitivity(unsigned int newSens ,unsigned int btn_channel);
2627
void setSensorsHysteresis(hysteresis_t newHyst);
2728
unsigned int getSensorsSensitivity();
2829
hysteresis_t getSensorsHysteresis();

src/touch.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ touch_measure_data_t *p_selfcap_measure_data = NULL;
8888

8989
/**
9090
* Default variables for the sensor config, then they are changed with
91-
* setHysteresis() and setSensivity() before the init
91+
* setHysteresis() , setSensitivity() and setSensitivityChannel before the init
9292
*/
9393
unsigned int _sensitivity = 5u;
94-
hysteresis_t _hysteresis = HYST_6_25;
94+
unsigned int _sensitivity_ch[5] = {5u , 5u, 5u, 5u, 5u};
95+
96+
hysteresis_t _hysteresis = HYST_50;
9597

9698
/*----------------------------------------------------------------------------
9799
* static variables
@@ -335,7 +337,7 @@ touch_ret_t touch_sensors_config(void)
335337
sensor_id_t sensor_id;
336338

337339
touch_ret = touch_selfcap_sensor_config(SENSOR_TYPE_KEY, CHANNEL_0,
338-
CHANNEL_0, NO_AKS_GROUP,_sensitivity,
340+
CHANNEL_0, NO_AKS_GROUP,_sensitivity_ch[0],
339341
_hysteresis, RES_1_BIT,
340342
&sensor_id);
341343
if (touch_ret != TOUCH_SUCCESS) {
@@ -344,7 +346,7 @@ touch_ret = touch_selfcap_sensor_config(SENSOR_TYPE_KEY, CHANNEL_0,
344346
}
345347

346348
touch_ret = touch_selfcap_sensor_config(SENSOR_TYPE_KEY, CHANNEL_1,
347-
CHANNEL_1, NO_AKS_GROUP, _sensitivity,
349+
CHANNEL_1, NO_AKS_GROUP, _sensitivity_ch[1],
348350
_hysteresis, RES_1_BIT,
349351
&sensor_id);
350352
if (touch_ret != TOUCH_SUCCESS) {
@@ -353,7 +355,7 @@ touch_ret = touch_selfcap_sensor_config(SENSOR_TYPE_KEY, CHANNEL_0,
353355
}
354356

355357
touch_ret = touch_selfcap_sensor_config(SENSOR_TYPE_KEY, CHANNEL_2,
356-
CHANNEL_2, NO_AKS_GROUP, _sensitivity,
358+
CHANNEL_2, NO_AKS_GROUP, _sensitivity_ch[2],
357359
_hysteresis, RES_1_BIT,
358360
&sensor_id);
359361
if (touch_ret != TOUCH_SUCCESS) {
@@ -362,7 +364,7 @@ touch_ret = touch_selfcap_sensor_config(SENSOR_TYPE_KEY, CHANNEL_0,
362364
}
363365

364366
touch_ret = touch_selfcap_sensor_config(SENSOR_TYPE_KEY, CHANNEL_3,
365-
CHANNEL_3, NO_AKS_GROUP, _sensitivity,
367+
CHANNEL_3, NO_AKS_GROUP, _sensitivity_ch[3],
366368
_hysteresis, RES_1_BIT,
367369
&sensor_id);
368370
if (touch_ret != TOUCH_SUCCESS) {
@@ -371,7 +373,7 @@ touch_ret = touch_selfcap_sensor_config(SENSOR_TYPE_KEY, CHANNEL_0,
371373
}
372374

373375
touch_ret = touch_selfcap_sensor_config(SENSOR_TYPE_KEY, CHANNEL_4,
374-
CHANNEL_4, NO_AKS_GROUP, _sensitivity,
376+
CHANNEL_4, NO_AKS_GROUP, _sensitivity_ch[4],
375377
_hysteresis, RES_1_BIT,
376378
&sensor_id);
377379
if (touch_ret != TOUCH_SUCCESS) {
@@ -408,12 +410,18 @@ void setHysteresis(hysteresis_t newHyst){
408410

409411
void setSensitivity(unsigned int newSens){
410412
_sensitivity = newSens;
413+
for (int i = 0; i < 5; i++){
414+
_sensitivity_ch[i] = _sensitivity;
415+
}
416+
}
417+
void setSensitivityChannel(unsigned int newSens, unsigned int btn_channel){
418+
_sensitivity_ch[btn_channel] = newSens;
411419
}
412420

413421
hysteresis_t getHysteresis() {
414-
return _hysteresis;
422+
return _hysteresis;
415423
}
416424

417425
unsigned int getSensitivity() {
418-
return _sensitivity;
426+
return _sensitivity;
419427
}

src/touch_api_SAMD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,7 @@ void touch_sensors_update_time(void);
984984
* */
985985
void setHysteresis(hysteresis_t newHyst);
986986
void setSensitivity(unsigned int newSens);
987+
void setSensitivityChannel(unsigned int newSens, unsigned int btn_channel);
987988
hysteresis_t getHysteresis();
988989
unsigned int getSensitivity();
989990

0 commit comments

Comments
 (0)