groveultrasonic: Initial implementation

This module was developed and tested on a Grove Ultrasonic Ranger module.

http://www.seeedstudio.com/wiki/Grove_-_Ultrasonic_Ranger

Signed-off-by: Jun Kato <i@junkato.jp>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jun Kato
2015-10-23 15:13:34 +09:00
committed by Mihai Tudor Panu
parent dc97adf578
commit 2eb6ebd3bd
8 changed files with 339 additions and 0 deletions

View File

@ -154,6 +154,7 @@ add_executable (adxrs610-example adxrs610.cxx)
add_executable (bma220-example bma220.cxx)
add_executable (dfrph-example dfrph.cxx)
add_executable (mcp9808-example mcp9808.cxx)
add_executable (groveultrasonic-example groveultrasonic.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -272,6 +273,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/adxrs610)
include_directories (${PROJECT_SOURCE_DIR}/src/bma220)
include_directories (${PROJECT_SOURCE_DIR}/src/dfrph)
include_directories (${PROJECT_SOURCE_DIR}/src/mcp9808)
include_directories (${PROJECT_SOURCE_DIR}/src/groveultrasonic)
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@ -427,3 +429,4 @@ target_link_libraries (adxrs610-example adxrs610 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (bma220-example bma220 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (dfrph-example dfrph ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (mcp9808-example mcp9808 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveultrasonic-example groveultrasonic ${CMAKE_THREAD_LIBS_INIT})

View File

@ -0,0 +1,58 @@
/*
* Author: Jun Kato <i@junkato.jp>
* Copyright (c) 2015 Jun Kato.
*
* Thanks to Seeed Studio for a working arduino sketch
*
* 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 "groveultrasonic.h"
#include <signal.h>
#include <stdlib.h>
#include <sys/time.h>
upm::GroveUltraSonic *sonar = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
sonar->m_doWork = 1;
}
}
int
main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
// upm::GroveUltraSonic *sonar = NULL;
sonar = new upm::GroveUltraSonic(2);
printf("width = %d\n", sonar->getDistance());
delete sonar;
//! [Interesting]
printf("exiting application\n");
return 0;
}