Skip to content

Commit 387c9fb

Browse files
authored
modified touch sensor parameter and added datastreamer (#6)
- hardcoded detetction threshold and hysteresys threshold - better callibrated the touch sensors - added datastreamer
1 parent 0adf3e1 commit 387c9fb

10 files changed

+2074
-28
lines changed

src/Arduino_MCHPTouch.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ bool QtouchClass::begin()
3232
// set starting measure time to 0 and change the analog resolution to 10
3333
touch_time.current_time_ms = 0;
3434
analogReadResolution(10);
35+
if (DEF_TOUCH_DATA_STREAMER_ENABLE == 1) {
36+
Serial1.begin(115200);
37+
}
3538
return true;
3639
}
3740

@@ -61,7 +64,7 @@ void QtouchClass::poll()
6164
{
6265
// set time flag to 1 and starting time millis()
6366
touch_time.time_to_measure_touch = 1;
64-
touch_time.current_time_ms = touch_time.current_time_ms + millis();
67+
touch_time.current_time_ms = millis();// touch_time.current_time_ms + millis();
6568

6669
// trigger a new measure
6770
touch_sensors_measure();

src/Arduino_MCHPTouch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <Arduino.h>
1313
#include "touch_api_SAMD.h"
14-
14+
#include "DataStreamer.h"
1515
class QtouchClass
1616
{
1717

src/DataStreamer.cpp

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/* This source file is part of the ATMEL QTouch Library 5.0.1 */
2+
/* Software provided by Microchip under the license agreement
3+
“Microchip Touch Library License Agreement - Arduino 082420
4+
(part of this downloaded package) */
5+
6+
/**
7+
*
8+
* \file
9+
*
10+
* \brief This file contains the SAMD QTouch library initialization,
11+
* sensor configuration and measurement routines.
12+
*
13+
* - Userguide: QTouch Library Peripheral Touch Controller User Guide.
14+
* - Support: https://www.microchip.com/support/
15+
*
16+
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
17+
*
18+
* \asf_license_start
19+
*
20+
* \page License
21+
*
22+
* Subject to your compliance with these terms, you may use Microchip
23+
* software and any derivatives exclusively with Microchip products.
24+
* It is your responsibility to comply with third party license terms applicable
25+
* to your use of third party software (including open source software) that
26+
* may accompany Microchip software.
27+
*
28+
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
29+
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
30+
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
31+
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
32+
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
33+
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
34+
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
35+
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
36+
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
37+
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
38+
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
39+
*
40+
* \asf_license_stop
41+
*
42+
*/
43+
44+
/*----------------------------------------------------------------------------
45+
include files
46+
----------------------------------------------------------------------------*/
47+
#include <Arduino.h>
48+
#include "DataStreamer.h"
49+
#include "touch_api_SAMD.h"
50+
51+
#if (DEF_TOUCH_DATA_STREAMER_ENABLE == 1u)
52+
53+
/*----------------------------------------------------------------------------
54+
* defines
55+
*----------------------------------------------------------------------------*/
56+
57+
/*----------------------------------------------------------------------------
58+
global variables
59+
----------------------------------------------------------------------------*/
60+
extern qtm_acquisition_control_t qtlib_acq_set1;
61+
extern qtm_touch_key_control_t qtlib_key_set1;
62+
extern qtm_touch_key_config_t qtlib_key_configs_set1[DEF_SELFCAP_NUM_SENSORS];
63+
64+
extern uint8_t module_error_code;
65+
66+
/*----------------------------------------------------------------------------
67+
prototypes
68+
----------------------------------------------------------------------------*/
69+
70+
71+
/*============================================================================
72+
void datastreamer_output(void)
73+
------------------------------------------------------------------------------
74+
Purpose: Forms the datastreamer frame based on the configured modules, Tranmits
75+
the frame as single packet through UART port.
76+
Input : none
77+
Output : none
78+
Notes :
79+
============================================================================*/
80+
void DataStreamer::datastreamerOutput(void)
81+
{
82+
touch_time.time_to_measure_touch = 1;
83+
touch_time.current_time_ms = millis();// touch_time.current_time_ms + millis();
84+
85+
// trigger a new measure
86+
touch_sensors_measure();
87+
88+
// check if a measure is done
89+
if ((p_selfcap_measure_data->measurement_done_touch == 1u))
90+
{
91+
p_selfcap_measure_data->measurement_done_touch == 0u;
92+
}
93+
94+
int16_t temp_int_calc;
95+
uint16_t u16temp_output;
96+
uint8_t u8temp_output;
97+
volatile uint16_t count_bytes_out;
98+
99+
100+
// Frame Start
101+
for (count_bytes_out = 0u; count_bytes_out < 5; count_bytes_out++) {
102+
/* Signals */
103+
u16temp_output = get_sensor_node_signal(count_bytes_out);
104+
105+
106+
/* Reference */
107+
u16temp_output = get_sensor_node_reference(count_bytes_out);
108+
109+
110+
/* Touch delta */
111+
temp_int_calc = get_sensor_node_signal(count_bytes_out);
112+
temp_int_calc -= get_sensor_node_reference(count_bytes_out);
113+
u16temp_output = (uint16_t)(temp_int_calc);
114+
115+
Serial.print("touch_"+String(count_bytes_out) + "_delta:");
116+
Serial.print(temp_int_calc);
117+
Serial.print(" ");
118+
/* Comp Caps */
119+
u16temp_output = get_sensor_cc_val(count_bytes_out);
120+
121+
122+
123+
/* State */
124+
u8temp_output = get_sensor_state(count_bytes_out);
125+
/* Threshold */
126+
127+
128+
Serial.print("threshold:");
129+
Serial.print(p_selfcap_measure_data->p_sensors[count_bytes_out].threshold);
130+
Serial.print(" ");
131+
}
132+
Serial.println();
133+
}
134+
135+
#endif

src/DataStreamer.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* This source file is part of the ATMEL QTouch Library 5.0.1 */
2+
/* Software provided by Microchip under the license agreement
3+
“Microchip Touch Library License Agreement - Arduino 082420
4+
(part of this downloaded package) */
5+
6+
/**
7+
*
8+
* \file
9+
*
10+
* \brief This file contains the SAMD QTouch library initialization,
11+
* sensor configuration and measurement routines.
12+
*
13+
* - Userguide: QTouch Library Peripheral Touch Controller User Guide.
14+
* - Support: https://www.microchip.com/support/
15+
*
16+
* Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.
17+
*
18+
* \asf_license_start
19+
*
20+
* \page License
21+
*
22+
* Subject to your compliance with these terms, you may use Microchip
23+
* software and any derivatives exclusively with Microchip products.
24+
* It is your responsibility to comply with third party license terms applicable
25+
* to your use of third party software (including open source software) that
26+
* may accompany Microchip software.
27+
*
28+
* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
29+
* WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
30+
* INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
31+
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
32+
* LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
33+
* LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
34+
* SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
35+
* POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
36+
* ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
37+
* RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
38+
* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
39+
*
40+
* \asf_license_stop
41+
*
42+
*/
43+
44+
#ifndef __DATASTREAMER_H_
45+
#define __DATASTREAMER_H_
46+
47+
/*----------------------------------------------------------------------------
48+
* include files
49+
*----------------------------------------------------------------------------*/
50+
#include "Arduino.h"
51+
#include "touch_config_samd.h"
52+
53+
54+
55+
//#if (DEF_TOUCH_DATA_STREAMER_ENABLE == 1u)
56+
57+
/*----------------------------------------------------------------------------
58+
* defines
59+
*----------------------------------------------------------------------------*/
60+
61+
/*----------------------------------------------------------------------------
62+
* prototypes
63+
*----------------------------------------------------------------------------*/
64+
65+
class DataStreamer {
66+
public:
67+
void datastreamerOutput(void);
68+
};
69+
//extern
70+
//#endif
71+
72+
#endif

0 commit comments

Comments
 (0)