mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 17:31:13 +03:00
ldt0028: Added support for LDT0-028 PZT film-based sensors
Signed-off-by: Sarah Knepper <sarah.knepper@intel.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:

committed by
Brendan Le Foll

parent
931c8e8814
commit
c5369315e9
@ -44,6 +44,7 @@ add_executable (nrf_ble_broadcast-example ble_broadcast.cxx)
|
||||
add_executable (tsl2561-example tsl2561.cxx)
|
||||
add_executable (htu21d-example htu21d.cxx)
|
||||
add_executable (mpl3115a2-example mpl3115a2.cxx)
|
||||
add_executable (ldt0028-example ldt0028.cxx)
|
||||
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
|
||||
@ -79,6 +80,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/lol)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/tsl2561)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/htu21d)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/mpl3115a2)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src/ldt0028)
|
||||
|
||||
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
|
||||
@ -126,3 +128,4 @@ target_link_libraries (nrf_ble_broadcast-example nrf24l01 ${CMAKE_THREAD_LIBS_IN
|
||||
target_link_libraries (tsl2561-example tsl2561 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (htu21d-example htu21d ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (mpl3115a2-example mpl3115a2 ${CMAKE_THREAD_LIBS_INIT})
|
||||
target_link_libraries (ldt0028-example ldt0028 ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
82
examples/javascript/ldt0028.js
Normal file
82
examples/javascript/ldt0028.js
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Author: Sarah Knepper <sarah.knepper@intel.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.
|
||||
*/
|
||||
|
||||
// Load Grove module
|
||||
var sensorModule = require('jsupm_ldt0028');
|
||||
|
||||
var NUMBER_OF_SECONDS = 10;
|
||||
var MILLISECONDS_PER_SECOND = 1000;
|
||||
var SAMPLES_PER_SECOND = 50;
|
||||
var THRESHOLD = 100;
|
||||
|
||||
// Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0
|
||||
var sensor = new sensorModule.LDT0028(0);
|
||||
|
||||
// Read the signal every 20 milliseconds for 10 seconds
|
||||
console.log("For the next " + NUMBER_OF_SECONDS + " seconds, " +
|
||||
SAMPLES_PER_SECOND + " samples will be taken every second.");
|
||||
console.log("");
|
||||
var buffer = [];
|
||||
for (var i=0; i < NUMBER_OF_SECONDS * SAMPLES_PER_SECOND; i++) {
|
||||
buffer.push(sensor.getSample());
|
||||
delay(MILLISECONDS_PER_SECOND / SAMPLES_PER_SECOND );
|
||||
}
|
||||
|
||||
// Print the number of times the reading was greater than the threshold
|
||||
var count = 0;
|
||||
for (var i=0; i < NUMBER_OF_SECONDS * SAMPLES_PER_SECOND; i++) {
|
||||
if (buffer[i] > THRESHOLD) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
console.log(sensor.name() + " exceeded the threshold value of " +
|
||||
THRESHOLD + " a total of " + count + " times,");
|
||||
console.log("out of a total of " + NUMBER_OF_SECONDS*SAMPLES_PER_SECOND +
|
||||
" readings.");
|
||||
console.log("");
|
||||
|
||||
// Print a graphical representation of the average value sampled
|
||||
// each second for the past 10 seconds, using a scale factor of 15
|
||||
console.log("Now printing a graphical representation of the average reading ");
|
||||
console.log("each second for the last " + NUMBER_OF_SECONDS + " seconds.");
|
||||
var SCALE_FACTOR = 15;
|
||||
for (var i=0; i < NUMBER_OF_SECONDS; i++) {
|
||||
var sum = 0;
|
||||
for (var j=0; j < SAMPLES_PER_SECOND; j++) {
|
||||
sum += buffer[i*SAMPLES_PER_SECOND+j];
|
||||
}
|
||||
var average = sum / SAMPLES_PER_SECOND;
|
||||
var stars_to_print = Math.round(average / SCALE_FACTOR);
|
||||
var string = "(" + (" " + Math.round(average)).slice(-4) + ") | ";
|
||||
for (var j=0; j < stars_to_print; j++) {
|
||||
string += "*";
|
||||
}
|
||||
console.log(string);
|
||||
}
|
||||
|
||||
function delay( milliseconds ) {
|
||||
var startTime = Date.now();
|
||||
while (Date.now() - startTime < milliseconds);
|
||||
}
|
||||
|
90
examples/ldt0028.cxx
Normal file
90
examples/ldt0028.cxx
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Author: Sarah Knepper <sarah.knepper@intel.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 <cmath>
|
||||
#include "ldt0028.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
//! [Interesting]
|
||||
const int NUMBER_OF_SECONDS = 10;
|
||||
const int MICROSECONDS_PER_SECOND = 1000000;
|
||||
const int SAMPLES_PER_SECOND = 50;
|
||||
const int THRESHOLD = 100;
|
||||
|
||||
// Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0
|
||||
upm::LDT0028* sensor = new upm::LDT0028(0);
|
||||
|
||||
// Read the signal every 20 milliseconds for 10 seconds
|
||||
std::cout << "For the next " << NUMBER_OF_SECONDS << " seconds, "
|
||||
<< SAMPLES_PER_SECOND << " samples will be taken every second."
|
||||
<< std::endl << std::endl;
|
||||
uint16_t* buffer = new uint16_t[NUMBER_OF_SECONDS * SAMPLES_PER_SECOND];
|
||||
for (int i=0; i < NUMBER_OF_SECONDS * SAMPLES_PER_SECOND; i++) {
|
||||
buffer[i] = (uint16_t) sensor->getSample();
|
||||
usleep(MICROSECONDS_PER_SECOND / SAMPLES_PER_SECOND);
|
||||
}
|
||||
|
||||
// Print the number of times the reading was greater than the threshold
|
||||
int count = 0;
|
||||
for (int i=0; i < NUMBER_OF_SECONDS * SAMPLES_PER_SECOND; i++) {
|
||||
if (buffer[i] > THRESHOLD) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
std::cout << sensor->name() << " exceeded the threshold value of " <<
|
||||
THRESHOLD << " a total of " << count << " times," << std::endl
|
||||
<< "out of a total of " << NUMBER_OF_SECONDS*SAMPLES_PER_SECOND
|
||||
<< " readings." << std::endl << std::endl;
|
||||
|
||||
// Print a graphical representation of the average value sampled
|
||||
// each second for the past 10 seconds, using a scale factor of 15
|
||||
std::cout << "Now printing a graphical representation of the average reading "
|
||||
<< std::endl << "each second for the last "
|
||||
<< NUMBER_OF_SECONDS << " seconds." << std::endl;
|
||||
const int SCALE_FACTOR = 15;
|
||||
for (int i=0; i < NUMBER_OF_SECONDS; i++) {
|
||||
long sum = 0;
|
||||
for (int j=0; j < SAMPLES_PER_SECOND; j++) {
|
||||
sum += buffer[i*SAMPLES_PER_SECOND + j];
|
||||
}
|
||||
double average = (double) sum / (double) SAMPLES_PER_SECOND;
|
||||
int stars_to_print = (int) round(average / SCALE_FACTOR);
|
||||
std::cout << "(" << std::setw(4) << (int) round(average) << ") | ";
|
||||
for (int j=0; j<stars_to_print; j++) {
|
||||
std::cout << "*";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
// Delete the sensor object
|
||||
delete sensor;
|
||||
//! [Interesting]
|
||||
|
||||
return 0;
|
||||
}
|
66
examples/python/ldt0028.py
Normal file
66
examples/python/ldt0028.py
Normal file
@ -0,0 +1,66 @@
|
||||
# Author: Sarah Knepper <sarah.knepper@intel.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.
|
||||
|
||||
import time
|
||||
import array
|
||||
import pyupm_ldt0028 as ldt0028
|
||||
|
||||
NUMBER_OF_SECONDS = 10
|
||||
SAMPLES_PER_SECOND = 50
|
||||
THRESHOLD = 100
|
||||
|
||||
# Create the LDT0-028 Piezo Vibration Sensor object using AIO pin 0
|
||||
sensor = ldt0028.LDT0028(0)
|
||||
|
||||
# Read the signal every 20 milliseconds for 10 seconds
|
||||
print 'For the next', NUMBER_OF_SECONDS, 'seconds,', \
|
||||
SAMPLES_PER_SECOND, 'samples will be taken every second.\n'
|
||||
buffer = array.array('H')
|
||||
for i in range(0, NUMBER_OF_SECONDS * SAMPLES_PER_SECOND):
|
||||
buffer.append(sensor.getSample())
|
||||
time.sleep(1.0/SAMPLES_PER_SECOND)
|
||||
|
||||
# Print the number of times the reading was greater than the threshold
|
||||
count = 0
|
||||
for i in range(0, NUMBER_OF_SECONDS * SAMPLES_PER_SECOND):
|
||||
if buffer[i] > THRESHOLD:
|
||||
count += 1
|
||||
print sensor.name(), ' exceeded the threshold value of', \
|
||||
THRESHOLD, 'a total of', count, 'times,'
|
||||
print 'out of a total of', NUMBER_OF_SECONDS*SAMPLES_PER_SECOND, \
|
||||
'reading.\n'
|
||||
|
||||
# Print a graphical representation of the average value sampled
|
||||
# each second for the past 10 seconds, using a scale factor of 15
|
||||
print 'Now printing a graphical representation of the average reading '
|
||||
print 'each second for the last', NUMBER_OF_SECONDS, 'seconds.'
|
||||
SCALE_FACTOR = 15
|
||||
for i in range(0, NUMBER_OF_SECONDS):
|
||||
sum = 0
|
||||
for j in range(0, SAMPLES_PER_SECOND):
|
||||
sum += buffer[i*SAMPLES_PER_SECOND+j]
|
||||
average = sum / SAMPLES_PER_SECOND
|
||||
stars_to_print = int(round(average / SCALE_FACTOR))
|
||||
print '(' + repr(int(round(average))).rjust(4) + ') |', '*' * stars_to_print
|
||||
|
||||
# Delete the sensor object
|
||||
del sensor
|
Reference in New Issue
Block a user