TSISensor.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifndef TSISENSOR_H
  24. #define TSISENSOR_H
  25. /**
  26. * TSISensor example
  27. *
  28. * @code
  29. * #include "mbed.h"
  30. * #include "TSISensor.h"
  31. *
  32. * int main(void) {
  33. * DigitalOut led(LED_GREEN);
  34. * TSISensor tsi;
  35. *
  36. * while (true) {
  37. * printf("slider percentage: %f%\r\n", tsi.readPercentage());
  38. * printf("slider distance: %dmm\r\n", tsi.readDistance());
  39. * wait(1);
  40. * led = !led;
  41. * }
  42. * }
  43. * @endcode
  44. */
  45. class TSISensor {
  46. public:
  47. /**
  48. * Initialize the TSI Touch Sensor
  49. */
  50. TSISensor();
  51. /**
  52. * Read Touch Sensor percentage value
  53. *
  54. * @returns percentage value between [0 ... 1]
  55. */
  56. float readPercentage();
  57. /**
  58. * Read Touch Sensor distance
  59. *
  60. * @returns distance in mm. The value is between [0 ... 40]
  61. */
  62. uint8_t readDistance();
  63. private:
  64. void sliderRead(void);
  65. void selfCalibration(void);
  66. };
  67. #endif