mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
at42qt1070: Initial implementation
This module implementes support for the Grove QTouch sensor. Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Zion Orent <zorent@ics.com> Signed-off-by: John Van Drasek <john.r.van.drasek@intel.com>
This commit is contained in:

committed by
John Van Drasek

parent
518d80cdcd
commit
de66c8de56
@ -96,6 +96,7 @@ add_executable (grovegsr-example grovegsr.cxx)
|
||||
add_executable (ina132-example ina132.cxx)
|
||||
add_executable (l298-example l298.cxx)
|
||||
add_executable (l298-stepper-example l298-stepper.cxx)
|
||||
add_executable (at42qt1070-example at42qt1070.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
@ -173,6 +174,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/groveo2)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grovegsr)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ina132)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/l298)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/at42qt1070)
|
||||
|
||||
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -270,3 +272,4 @@ target_link_libraries (grovegsr-example grovegsr ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (ina132-example ina132 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (l298-example l298 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (l298-stepper-example l298 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (at42qt1070-example at42qt1070 ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
90
examples/c++/at42qt1070.cxx
Normal file
90
examples/c++/at42qt1070.cxx
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2015 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#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);
|
||||
|
||||
//! [Interesting]
|
||||
// Instantiate an AT42QT1070 on I2C bus 0
|
||||
|
||||
upm::AT42QT1070 *touch = new upm::AT42QT1070(AT42QT1070_I2C_BUS,
|
||||
AT42QT1070_DEFAULT_I2C_ADDR);
|
||||
|
||||
while (shouldRun)
|
||||
{
|
||||
touch->updateState();
|
||||
printButtons(touch);
|
||||
usleep(100000);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting..." << endl;
|
||||
|
||||
delete touch;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user