]> Pileus Git - ~andy/csm213a-hw/blob - yue/TSI/TSISensor.h
Add sensors code from Yue
[~andy/csm213a-hw] / yue / TSI / TSISensor.h
1 /* Freescale Semiconductor Inc.
2  * (c) Copyright 2004-2005 Freescale Semiconductor, Inc.
3  * (c) Copyright 2001-2004 Motorola, Inc. 
4  *
5  * mbed Microcontroller Library
6  * (c) Copyright 2009-2012 ARM Limited.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
9  * and associated documentation files (the "Software"), to deal in the Software without
10  * restriction, including without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all copies or
15  * substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
18  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23
24 #ifndef TSISENSOR_H
25 #define TSISENSOR_H
26
27 /**
28 * TSISensor example
29 *
30 * @code
31 * #include "mbed.h"
32 * #include "TSISensor.h"
33
34 * int main(void) {
35 *     PwmOut led(LED_GREEN);
36 *     TSISensor tsi;
37 *     
38 *     while (true) {
39 *         led = 1.0 - tsi.readPercentage();
40 *         wait(0.1);
41 *     }
42 * }
43 * @endcode
44 */
45 class TSISensor {
46 public:
47     /**
48      *   Initialize the TSI Touch Sensor
49      */
50     TSISensor();
51
52     /**
53      * Read Touch Sensor percentage value
54      *
55      * @returns percentage value between [0 ... 1]
56      */
57     float readPercentage();
58
59     /**
60      * Read Touch Sensor distance
61      *
62      * @returns distance in mm. The value is between [0 ... 40]
63      */
64     uint8_t readDistance();
65     uint16_t readValue(uint8_t);
66     void TSISensor_reset(void);
67
68 private:
69     void sliderRead(void);
70     void selfCalibration(void);
71 };
72
73 #endif