1/*jslint node:true, vars:true, bitwise:true, unparam:true */ 2/*jshint unused:true */ 3 4/* 5* Author: Zion Orent <zorent@ics.com> 6* Copyright (c) 2015 Intel Corporation. 7* 8* Permission is hereby granted, free of charge, to any person obtaining 9* a copy of this software and associated documentation files (the 10* "Software"), to deal in the Software without restriction, including 11* without limitation the rights to use, copy, modify, merge, publish, 12* distribute, sublicense, and/or sell copies of the Software, and to 13* permit persons to whom the Software is furnished to do so, subject to 14* the following conditions: 15* 16* The above copyright notice and this permission notice shall be 17* included in all copies or substantial portions of the Software. 18* 19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26*/ 27 28var waterFlow_lib = require('jsupm_grovewfs'); 29 30// Instantiate a Grove Water Flow Sensor on digital pin D2 31var myWaterFlow_obj = new waterFlow_lib.GroveWFS(2); 32 33// set the flow counter to 0 and start counting 34myWaterFlow_obj.clearFlowCounter(); 35myWaterFlow_obj.startFlowCounter(); 36 37 38var millis, flowCount, fr; 39var myInterval = setInterval(function() 40{ 41 // we grab these (millis and flowCount) just for display 42 // purposes in this example 43 millis = myWaterFlow_obj.getMillis(); 44 flowCount = myWaterFlow_obj.flowCounter(); 45 46 fr = myWaterFlow_obj.flowRate(); 47 48 // output milliseconds passed, flow count, and computed flow rate 49 outputStr = "Millis: " + millis + " Flow Count: " + flowCount + 50 " Flow Rate: " + fr + " LPM"; 51 console.log(outputStr); 52 53 // best to gather data for at least one second for reasonable 54 // results. 55}, 2000); 56 57 58// When exiting: clear interval and print message 59process.on('SIGINT', function() 60{ 61 clearInterval(myInterval); 62 myWaterFlow_obj.stopFlowCounter(); 63 myWaterFlow_obj = null 64 waterFlow_lib.cleanUp(); 65 waterFlow_lib = null; 66 67 console.log("Exiting"); 68 process.exit(0); 69}); 70