|
| 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 |
0 commit comments