grovewfs: Initial implementation

This driver implements support for the Grove Water Flow sensor.  It
uses an integrated hall effect sensor, connected to a GPIO configured
as an interrupt, to compute water flow in LPM (Liters Per Minute).

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:
Jon Trulson
2015-03-23 17:05:39 -06:00
committed by John Van Drasek
parent 2a3485cf98
commit ce1e2fd606
9 changed files with 494 additions and 0 deletions

View File

@ -112,6 +112,7 @@ add_executable (tm1637-example tm1637.cxx)
add_executable (zfm20-example zfm20.cxx)
add_executable (zfm20-register-example zfm20-register.cxx)
add_executable (uln200xa-example uln200xa.cxx)
add_executable (grovewfs-example grovewfs.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -202,6 +203,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/waterlevel)
include_directories (${PROJECT_SOURCE_DIR}/src/tm1637)
include_directories (${PROJECT_SOURCE_DIR}/src/zfm20)
include_directories (${PROJECT_SOURCE_DIR}/src/uln200xa)
include_directories (${PROJECT_SOURCE_DIR}/src/grovewfs)
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@ -315,3 +317,4 @@ target_link_libraries (tm1637-example tm1637 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (zfm20-example zfm20 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (zfm20-register-example zfm20 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (uln200xa-example uln200xa ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (grovewfs-example grovewfs ${CMAKE_THREAD_LIBS_INIT})

78
examples/c++/grovewfs.cxx Normal file
View File

@ -0,0 +1,78 @@
/*
* 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 <signal.h>
#include "grovewfs.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 Grove Water Flow Sensor on digital pin D2
upm::GroveWFS* flow = new upm::GroveWFS(2);
// set the flow counter to 0 and start counting
flow->clearFlowCounter();
flow->startFlowCounter();
while (shouldRun)
{
// we grab these (,illis and flowCount) just for display
// purposes in this example
uint32_t millis = flow->getMillis();
uint32_t flowCount = flow->flowCounter();
float fr = flow->flowRate();
// output milliseconds passed, flow count, and computed flow rate
cout << "Millis: " << millis << " Flow Count: " << flowCount;
cout << " Flow Rate: " << fr << " LPM" << endl;
// best to gather data for at least one second for reasonable
// results.
sleep(2);
}
flow->stopFlowCounter();
//! [Interesting]
cout << "Exiting..." << endl;
delete flow;
return 0;
}