mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +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;
|
||||
}
|
81
examples/javascript/at42qt1070.js
Normal file
81
examples/javascript/at42qt1070.js
Normal file
@ -0,0 +1,81 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
/*
|
||||
* Author: Zion Orent <zorent@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.
|
||||
*/
|
||||
|
||||
/* functions */
|
||||
function printButtons(touchObj)
|
||||
{
|
||||
var buttonPressed = false;
|
||||
var buttons = touchObj.getButtons();
|
||||
|
||||
process.stdout.write("Buttons Pressed: ");
|
||||
for (var i=0; i<7; i++)
|
||||
{
|
||||
if (buttons & (1 << i))
|
||||
{
|
||||
process.stdout.write(i + " ");
|
||||
buttonPressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!buttonPressed)
|
||||
process.stdout.write("None");
|
||||
|
||||
console.log(" ");
|
||||
|
||||
if (touchObj.isCalibrating())
|
||||
console.log("Calibration is occurring.");
|
||||
|
||||
if (touchObj.isOverflowed())
|
||||
console.log("Overflow was detected.");
|
||||
}
|
||||
|
||||
|
||||
/* Global code that runs on startup */
|
||||
|
||||
var touchSensor_lib = require('jsupm_at42qt1070');
|
||||
|
||||
var I2C_BUS = touchSensor_lib.AT42QT1070_I2C_BUS;
|
||||
var DEFAULT_I2C_ADDR = touchSensor_lib.AT42QT1070_DEFAULT_I2C_ADDR;
|
||||
// Instantiate an AT42QT1070 on I2C bus 0
|
||||
var mytouchSensor_obj = new touchSensor_lib.AT42QT1070(I2C_BUS,
|
||||
DEFAULT_I2C_ADDR);
|
||||
|
||||
var myInterval = setInterval(function()
|
||||
{
|
||||
mytouchSensor_obj.updateState();
|
||||
printButtons(mytouchSensor_obj);
|
||||
}, 100);
|
||||
|
||||
// Print message when exiting and clear interval/memory
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
clearInterval(myInterval);
|
||||
mytouchSensor_obj = null;
|
||||
touchSensor_lib.cleanUp();
|
||||
touchSensor_lib = null;
|
||||
console.log("Exiting");
|
||||
process.exit(0);
|
||||
});
|
Reference in New Issue
Block a user