mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
otp538u: Initial implementation
This module was tested on the Grove non-contact IR Temperature Sensor. The tables included are only valid for a distance of 9cm. 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
1f3d074261
commit
f13216752e
@ -85,6 +85,7 @@ add_executable (cjq4435-example cjq4435.cxx)
|
||||
add_executable (adxl335-example adxl335.cxx)
|
||||
add_executable (hmtrp-example hmtrp.cxx)
|
||||
add_executable (nunchuck-example nunchuck.cxx)
|
||||
add_executable (otp538u-example otp538u.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
@ -155,6 +156,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/cjq4435)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/adxl335)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmtrp)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/nunchuck)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/otp538u)
|
||||
|
||||
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -243,3 +245,4 @@ target_link_libraries (cjq4435-example cjq4435 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (adxl335-example adxl335 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (hmtrp-example hmtrp ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (nunchuck-example nunchuck ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (otp538u-example otp538u ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
64
examples/javascript/otp538u.js
Normal file
64
examples/javascript/otp538u.js
Normal file
@ -0,0 +1,64 @@
|
||||
/*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.
|
||||
*/
|
||||
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
var OTP538U_AREF = 5.0;
|
||||
|
||||
var tempIRSensor_lib = require('jsupm_otp538u');
|
||||
|
||||
// Instantiate a OTP538U on analog pins A0 and A1
|
||||
// A0 is used for the Ambient Temperature and A1 is used for the
|
||||
// Object temperature.
|
||||
var tempIRSensor_obj = new tempIRSensor_lib.OTP538U(0, 1, OTP538U_AREF);
|
||||
|
||||
|
||||
function checkTemp()
|
||||
{
|
||||
var outputStr = "Ambient temp: " +
|
||||
roundNum(tempIRSensor_obj.ambientTemperature(), 2) +
|
||||
" C, Object temp: " +
|
||||
roundNum(tempIRSensor_obj.objectTemperature(), 2) +
|
||||
" C";
|
||||
console.log(outputStr);
|
||||
}
|
||||
|
||||
var myInterval = setInterval(checkTemp, 1000);
|
||||
|
||||
function roundNum(num, decimalPlaces)
|
||||
{
|
||||
var extraNum = (1 / (Math.pow(10, decimalPlaces) * 1000));
|
||||
return (Math.round((num + extraNum) *
|
||||
(Math.pow(10, decimalPlaces))) / Math.pow(10, decimalPlaces));
|
||||
}
|
||||
|
||||
// When exiting: clear interval and print message
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
clearInterval(myInterval);
|
||||
console.log("Exiting...");
|
||||
process.exit(0);
|
||||
});
|
71
examples/otp538u.cxx
Normal file
71
examples/otp538u.cxx
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2014 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 <iostream>
|
||||
#include <iomanip>
|
||||
#include <signal.h>
|
||||
#include "otp538u.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
// analog voltage, usually 3.3 or 5.0
|
||||
#define OTP538U_AREF 5.0
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a OTP538U on analog pins A0 and A1
|
||||
// A0 is used for the Ambient Temperature and A1 is used for the
|
||||
// Object tempewrature.
|
||||
upm::OTP538U *temps = new upm::OTP538U(0, 1, OTP538U_AREF);
|
||||
|
||||
// Output ambient and object temperatures
|
||||
while (shouldRun)
|
||||
{
|
||||
cout << "Ambient temp: " << std::fixed << setprecision(2)
|
||||
<< temps->ambientTemperature()
|
||||
<< " C, Object temp: " << temps->objectTemperature()
|
||||
<< " C" << endl;
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete temps;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user