TSI button support. You may custom the tsi channel of the button and button number.

Dependents:   FRDM_KL25Z_TSI_Touch

Fork of TSI by Mbed

Committer:
shaoziyang
Date:
Thu May 21 16:29:40 2015 +0000
Revision:
4:4b7c5856807e
Parent:
2:507b1f67804b
TSI button support.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 1:4dd9262cac47 1 /* Freescale Semiconductor Inc.
samux 1:4dd9262cac47 2 * (c) Copyright 2004-2005 Freescale Semiconductor, Inc.
samux 1:4dd9262cac47 3 * (c) Copyright 2001-2004 Motorola, Inc.
samux 1:4dd9262cac47 4 *
samux 1:4dd9262cac47 5 * mbed Microcontroller Library
samux 1:4dd9262cac47 6 * (c) Copyright 2009-2012 ARM Limited.
samux 1:4dd9262cac47 7 *
samux 1:4dd9262cac47 8 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
samux 1:4dd9262cac47 9 * and associated documentation files (the "Software"), to deal in the Software without
samux 1:4dd9262cac47 10 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
samux 1:4dd9262cac47 11 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
samux 1:4dd9262cac47 12 * Software is furnished to do so, subject to the following conditions:
samux 1:4dd9262cac47 13 *
samux 1:4dd9262cac47 14 * The above copyright notice and this permission notice shall be included in all copies or
samux 1:4dd9262cac47 15 * substantial portions of the Software.
samux 1:4dd9262cac47 16 *
samux 1:4dd9262cac47 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
samux 1:4dd9262cac47 18 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
samux 1:4dd9262cac47 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
samux 1:4dd9262cac47 20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
samux 1:4dd9262cac47 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
samux 1:4dd9262cac47 22 */
samux 1:4dd9262cac47 23
samux 1:4dd9262cac47 24 #ifndef TSISENSOR_H
samux 1:4dd9262cac47 25 #define TSISENSOR_H
samux 1:4dd9262cac47 26
shaoziyang 4:4b7c5856807e 27 #define SLIDER_LENGTH 40 //LENGTH in mm
shaoziyang 4:4b7c5856807e 28 #define ELECTRODE_NUM 2
shaoziyang 4:4b7c5856807e 29
shaoziyang 4:4b7c5856807e 30 /*Chose the correct TSI channel for the electrode number*/
shaoziyang 4:4b7c5856807e 31 #define ELECTRODE0 TSI_CH9
shaoziyang 4:4b7c5856807e 32 #define ELECTRODE1 TSI_CH10
shaoziyang 4:4b7c5856807e 33 #define ELECTRODE2 TSI_CH13
shaoziyang 4:4b7c5856807e 34 #define ELECTRODE3 TSI_CH1
shaoziyang 4:4b7c5856807e 35 #define ELECTRODE4 TSI_CH2
shaoziyang 4:4b7c5856807e 36 #define ELECTRODE5 TSI_CH3
shaoziyang 4:4b7c5856807e 37 #define ELECTRODE6 TSI_CH4
shaoziyang 4:4b7c5856807e 38 #define ELECTRODE7 TSI_CH5
shaoziyang 4:4b7c5856807e 39 #define ELECTRODE8 TSI_CH6
shaoziyang 4:4b7c5856807e 40 #define ELECTRODE9 TSI_CH7
shaoziyang 4:4b7c5856807e 41 #define ELECTRODE10 TSI_CH8
shaoziyang 4:4b7c5856807e 42 #define ELECTRODE11 TSI_CH11
shaoziyang 4:4b7c5856807e 43 #define ELECTRODE12 TSI_CH12
shaoziyang 4:4b7c5856807e 44 #define ELECTRODE13 TSI_CH0
shaoziyang 4:4b7c5856807e 45 #define ELECTRODE14 TSI_CH14
shaoziyang 4:4b7c5856807e 46 #define ELECTRODE15 TSI_CH15
shaoziyang 4:4b7c5856807e 47
shaoziyang 4:4b7c5856807e 48 // TSI Channel THRESHOLD
shaoziyang 4:4b7c5856807e 49 #define THRESHOLD0 100
shaoziyang 4:4b7c5856807e 50 #define THRESHOLD1 100
shaoziyang 4:4b7c5856807e 51 #define THRESHOLD2 100
shaoziyang 4:4b7c5856807e 52 #define THRESHOLD3 100
shaoziyang 4:4b7c5856807e 53 #define THRESHOLD4 100
shaoziyang 4:4b7c5856807e 54 #define THRESHOLD5 100
shaoziyang 4:4b7c5856807e 55 #define THRESHOLD6 100
shaoziyang 4:4b7c5856807e 56 #define THRESHOLD7 100
shaoziyang 4:4b7c5856807e 57 #define THRESHOLD8 100
shaoziyang 4:4b7c5856807e 58 #define THRESHOLD9 100
shaoziyang 4:4b7c5856807e 59 #define THRESHOLD10 100
shaoziyang 4:4b7c5856807e 60 #define THRESHOLD11 100
shaoziyang 4:4b7c5856807e 61 #define THRESHOLD12 100
shaoziyang 4:4b7c5856807e 62 #define THRESHOLD13 100
shaoziyang 4:4b7c5856807e 63 #define THRESHOLD14 100
shaoziyang 4:4b7c5856807e 64 #define THRESHOLD15 100
shaoziyang 4:4b7c5856807e 65
shaoziyang 4:4b7c5856807e 66
samux 1:4dd9262cac47 67 /**
samux 1:4dd9262cac47 68 * TSISensor example
samux 1:4dd9262cac47 69 *
samux 1:4dd9262cac47 70 * @code
samux 1:4dd9262cac47 71 * #include "mbed.h"
samux 1:4dd9262cac47 72 * #include "TSISensor.h"
chris 2:507b1f67804b 73 *
samux 1:4dd9262cac47 74 * int main(void) {
chris 2:507b1f67804b 75 * PwmOut led(LED_GREEN);
chris 2:507b1f67804b 76 * TSISensor tsi;
chris 2:507b1f67804b 77 *
chris 2:507b1f67804b 78 * while (true) {
chris 2:507b1f67804b 79 * led = 1.0 - tsi.readPercentage();
chris 2:507b1f67804b 80 * wait(0.1);
chris 2:507b1f67804b 81 * }
samux 1:4dd9262cac47 82 * }
samux 1:4dd9262cac47 83 * @endcode
samux 1:4dd9262cac47 84 */
samux 1:4dd9262cac47 85 class TSISensor {
samux 1:4dd9262cac47 86 public:
samux 1:4dd9262cac47 87 /**
samux 1:4dd9262cac47 88 * Initialize the TSI Touch Sensor
samux 1:4dd9262cac47 89 */
samux 1:4dd9262cac47 90 TSISensor();
samux 1:4dd9262cac47 91
samux 1:4dd9262cac47 92 /**
samux 1:4dd9262cac47 93 * Read Touch Sensor percentage value
samux 1:4dd9262cac47 94 *
samux 1:4dd9262cac47 95 * @returns percentage value between [0 ... 1]
samux 1:4dd9262cac47 96 */
samux 1:4dd9262cac47 97 float readPercentage();
samux 1:4dd9262cac47 98
samux 1:4dd9262cac47 99 /**
samux 1:4dd9262cac47 100 * Read Touch Sensor distance
samux 1:4dd9262cac47 101 *
samux 1:4dd9262cac47 102 * @returns distance in mm. The value is between [0 ... 40]
samux 1:4dd9262cac47 103 */
samux 1:4dd9262cac47 104 uint8_t readDistance();
samux 1:4dd9262cac47 105
shaoziyang 4:4b7c5856807e 106 uint8_t Pressed(uint8_t ch);
shaoziyang 4:4b7c5856807e 107 float readTSI(uint8_t ch);
shaoziyang 4:4b7c5856807e 108 uint16_t readTSI_u16(uint8_t ch);
shaoziyang 4:4b7c5856807e 109
samux 1:4dd9262cac47 110 private:
samux 1:4dd9262cac47 111 void sliderRead(void);
samux 1:4dd9262cac47 112 void selfCalibration(void);
samux 1:4dd9262cac47 113 };
samux 1:4dd9262cac47 114
samux 1:4dd9262cac47 115 #endif