wheelencoder: Initial implementation

This driver was developed for the DFRobot Wheel Encoder, though it
could be used for any counting time-based task using a digital i/o pin
to generate interrupts.

http://www.dfrobot.com/index.php?route=product/product&product_id=98

If you want to use more than one encoder, simply create a class
instance for each one.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: sisinty sasmita patra <sisinty.s.patra@intel.com>
This commit is contained in:
Jon Trulson
2015-08-27 16:57:16 -06:00
committed by sisinty sasmita patra
parent 60cfe88e37
commit b0625e11f1
10 changed files with 443 additions and 0 deletions

View File

@ -135,6 +135,7 @@ add_executable (lsm9ds0-example lsm9ds0.cxx)
add_executable (eboled-example eboled.cxx)
add_executable (hyld9767-example hyld9767.cxx)
add_executable (mg811-example mg811.cxx)
add_executable (wheelencoder-example wheelencoder.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -243,6 +244,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/pn532)
include_directories (${PROJECT_SOURCE_DIR}/src/lsm9ds0)
include_directories (${PROJECT_SOURCE_DIR}/src/hyld9767)
include_directories (${PROJECT_SOURCE_DIR}/src/mg811)
include_directories (${PROJECT_SOURCE_DIR}/src/wheelencoder)
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@ -379,3 +381,4 @@ target_link_libraries (lsm9ds0-example lsm9ds0 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (eboled-example i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (hyld9767-example hyld9767 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (mg811-example mg811 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (wheelencoder-example wheelencoder ${CMAKE_THREAD_LIBS_INIT})

View File

@ -0,0 +1,69 @@
/*
* 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 <iostream>
#include <signal.h>
#include "wheelencoder.h"
using namespace std;
int shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a DFRobot Wheel Encoder on digital pin D2
upm::WheelEncoder* sensor = new upm::WheelEncoder(2);
// set the counter to 0 and start counting
sensor->clearCounter();
sensor->startCounter();
while (shouldRun)
{
// output milliseconds passed and current sensor count
cout << "Millis: " << sensor->getMillis() << " Count: "
<< sensor->counter() << endl;
sleep(1);
}
sensor->stopCounter();
//! [Interesting]
cout << "Exiting..." << endl;
delete sensor;
return 0;
}