hcsr04: Added new sonar module (not working properly yet)

Signed-off-by: Kiveisha Yevgeniy <yevgeniy.kiveisha@intel.com>
This commit is contained in:
Kiveisha Yevgeniy
2014-06-04 14:57:19 +00:00
parent 356b1dd43c
commit 23d847e380
8 changed files with 244 additions and 0 deletions

View File

@ -9,6 +9,7 @@ add_executable (seg-lcd 4digitdisplay.cxx)
add_executable (nrf_transmitter nrf_transmitter.cxx)
add_executable (nrf_receiver nrf_receiver.cxx)
add_executable (es08a es08a.cxx)
add_executable (son-hcsr04 hcsr04.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -18,6 +19,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/ledbar)
include_directories (${PROJECT_SOURCE_DIR}/src/4digitdisplay)
include_directories (${PROJECT_SOURCE_DIR}/src/nrf24l01)
include_directories (${PROJECT_SOURCE_DIR}/src/servo)
include_directories (${PROJECT_SOURCE_DIR}/src/hcsr04)
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
@ -30,3 +32,4 @@ target_link_libraries (seg-lcd 4digitdisplay ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf_transmitter nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf_receiver nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (es08a servo ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (son-hcsr04 hcsr04 ${CMAKE_THREAD_LIBS_INIT})

61
examples/hcsr04.cxx Normal file
View File

@ -0,0 +1,61 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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 "hcsr04.h"
#include <signal.h>
#include <stdlib.h>
#include <sys/time.h>
upm::HCSR04 *sonar = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
sonar->m_doWork = 1;
}
}
void
interrupt (void) {
sonar->ackEdgeDetected ();
}
int
main(int argc, char **argv)
{
sonar = new upm::HCSR04(5, 7, &interrupt);
signal(SIGINT, sig_handler);
printf ("width = %d\n", sonar->getDistance());
std::cout << "exiting application" << std::endl;
delete sonar;
return 0;
}