暂无描述

at42qt1070.cxx 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Author: Jon Trulson <jtrulson@ics.com>
  3. * Copyright (c) 2015 Intel Corporation.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. #include <unistd.h>
  25. #include <signal.h>
  26. #include <iostream>
  27. #include "at42qt1070.h"
  28. using namespace std;
  29. int shouldRun = true;
  30. void sig_handler(int signo)
  31. {
  32. if (signo == SIGINT)
  33. shouldRun = false;
  34. }
  35. void printButtons(upm::AT42QT1070 *touch)
  36. {
  37. bool buttonPressed = false;
  38. uint8_t buttons = touch->getButtons();
  39. cout << "Buttons Pressed: ";
  40. for (int i=0; i<7; i++)
  41. {
  42. if (buttons & (1 << i))
  43. {
  44. cout << i << " ";
  45. buttonPressed = true;
  46. }
  47. }
  48. if (!buttonPressed)
  49. cout << "None";
  50. cout << endl;
  51. if (touch->isCalibrating())
  52. cout << "Calibration is occurring." << endl;
  53. if (touch->isOverflowed())
  54. cout << "Overflow was detected." << endl;
  55. }
  56. int main(int argc, char **argv)
  57. {
  58. signal(SIGINT, sig_handler);
  59. //! [Interesting]
  60. // Instantiate an AT42QT1070 on I2C bus 0
  61. upm::AT42QT1070 *touch = new upm::AT42QT1070(AT42QT1070_I2C_BUS,
  62. AT42QT1070_DEFAULT_I2C_ADDR);
  63. while (shouldRun)
  64. {
  65. touch->updateState();
  66. printButtons(touch);
  67. usleep(100000);
  68. }
  69. //! [Interesting]
  70. cout << "Exiting..." << endl;
  71. delete touch;
  72. return 0;
  73. }