123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
-
-
- #include <unistd.h>
- #include <signal.h>
- #include <iostream>
- #include "at42qt1070.h"
-
- using namespace std;
-
- int shouldRun = true;
-
- void sig_handler(int signo)
- {
- if (signo == SIGINT)
- shouldRun = false;
- }
-
- void printButtons(upm::AT42QT1070 *touch)
- {
- bool buttonPressed = false;
- uint8_t buttons = touch->getButtons();
-
- cout << "Buttons Pressed: ";
- for (int i=0; i<7; i++)
- {
- if (buttons & (1 << i))
- {
- cout << i << " ";
- buttonPressed = true;
- }
- }
-
- if (!buttonPressed)
- cout << "None";
-
- cout << endl;
-
- if (touch->isCalibrating())
- cout << "Calibration is occurring." << endl;
-
- if (touch->isOverflowed())
- cout << "Overflow was detected." << endl;
- }
-
- int main(int argc, char **argv)
- {
- signal(SIGINT, sig_handler);
-
-
-
-
- upm::AT42QT1070 *touch = new upm::AT42QT1070(AT42QT1070_I2C_BUS,
- AT42QT1070_DEFAULT_I2C_ADDR);
-
- while (shouldRun)
- {
- touch->updateState();
- printButtons(touch);
- usleep(100000);
- }
-
-
-
- cout << "Exiting..." << endl;
-
- delete touch;
- return 0;
- }
|