WFS: Added water flow sensor without grove dependency

Signed-off-by: Sisinty Sasmita Patra <sisinty.s.patra@intel.com>
This commit is contained in:
Sisinty Sasmita Patra
2016-09-14 11:37:08 -07:00
committed by Noel Eck
parent 81e4eb07bf
commit b65908ea24
13 changed files with 563 additions and 0 deletions

View File

@ -212,6 +212,7 @@ add_example (zfm20)
add_example (zfm20-register)
add_example (uln200xa)
add_example (grovewfs)
add_example (wfs)
add_example (isd1820)
add_example (sx6119)
add_example (si114x)

78
examples/c++/wfs.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 "wfs.hpp"
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 Water Flow Sensor on digital pin D2
upm::WFS* flow = new upm::WFS(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;
}

View File

@ -72,6 +72,7 @@ add_example(GroveVDivSample grovevdiv)
add_example(WaterSample water)
add_example(GroveWaterSample grovewater)
add_example(GroveWFSSample grovewfs)
add_example(WFSSample wfs)
add_example(GUVAS12DSample guvas12d)
add_example(H3LIS331DLSample h3lis331dl)
add_example(HCSR04Sample hcsr04)

View File

@ -0,0 +1,44 @@
/*
* Author: Stefan Andritoiu <stefan.andritoiu@intel.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.
*/
//NOT TESTED!!!
public class WFSSample {
public static void main(String[] args) throws InterruptedException {
// ! [Interesting]
// Instantiate a Water Flow Sensor on digital pin D2
upm_wfs.WFS flow = new upm_wfs.WFS(2);
flow.clearFlowCounter();
flow.startFlowCounter();
while (true) {
System.out.print("Millis: " + flow.getMillis() + " FlowCount: " + flow.flowCounter());
System.out.println(" Flow Rate: " + flow.flowRate() + " LPM");
Thread.sleep(2000);
}
// ! [Interesting]
}
}

View File

@ -0,0 +1,66 @@
/*
* Author: Zion Orent <zorent@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.
*/
var waterFlow_lib = require('jsupm_wfs');
// Instantiate a Grove Water Flow Sensor on digital pin D2
var myWaterFlow_obj = new waterFlow_lib.WFS(2);
// set the flow counter to 0 and start counting
myWaterFlow_obj.clearFlowCounter();
myWaterFlow_obj.startFlowCounter();
var millis, flowCount, fr;
var myInterval = setInterval(function()
{
// we grab these (millis and flowCount) just for display
// purposes in this example
millis = myWaterFlow_obj.getMillis();
flowCount = myWaterFlow_obj.flowCounter();
fr = myWaterFlow_obj.flowRate();
// output milliseconds passed, flow count, and computed flow rate
outputStr = "Millis: " + millis + " Flow Count: " + flowCount +
" Flow Rate: " + fr + " LPM";
console.log(outputStr);
// best to gather data for at least one second for reasonable
// results.
}, 2000);
// When exiting: clear interval and print message
process.on('SIGINT', function()
{
clearInterval(myInterval);
myWaterFlow_obj.stopFlowCounter();
myWaterFlow_obj = null
waterFlow_lib.cleanUp();
waterFlow_lib = null;
console.log("Exiting");
process.exit(0);
});

64
examples/python/wfs.py Normal file
View File

@ -0,0 +1,64 @@
#!/usr/bin/python
# Author: Zion Orent <zorent@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.
import time, sys, signal, atexit
import pyupm_wfs as upmwfs
# Instantiate a Water Flow Sensor on digital pin D2
myWaterFlow = upmwfs.WFS(2)
## Exit handlers ##
# This stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit,
# including functions from myWaterFlow
def exitHandler():
myWaterFlow.stopFlowCounter()
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
# set the flow counter to 0 and start counting
myWaterFlow.clearFlowCounter()
myWaterFlow.startFlowCounter()
while (1):
# we grab these (millis and flowCount) just for display
# purposes in this example
millis = myWaterFlow.getMillis()
flowCount = myWaterFlow.flowCounter()
fr = myWaterFlow.flowRate()
# output milliseconds passed, flow count, and computed flow rate
outputStr = "Millis: {0} Flow Count: {1} Flow Rate: {2} LPM".format(
millis, flowCount, fr)
print outputStr
time.sleep(2)