Home | History | Annotate | Download | only in javascript
      1 /*jslint node:true, vars:true, bitwise:true, unparam:true */
      2 /*jshint unused:true */
      3 /*
      4 * Author: Zion Orent <zorent (at) ics.com>
      5 * Copyright (c) 2014 Intel Corporation.
      6 *
      7 * Permission is hereby granted, free of charge, to any person obtaining
      8 * a copy of this software and associated documentation files (the
      9 * "Software"), to deal in the Software without restriction, including
     10 * without limitation the rights to use, copy, modify, merge, publish,
     11 * distribute, sublicense, and/or sell copies of the Software, and to
     12 * permit persons to whom the Software is furnished to do so, subject to
     13 * the following conditions:
     14 *
     15 * The above copyright notice and this permission notice shall be
     16 * included in all copies or substantial portions of the Software.
     17 *
     18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     25 */
     26 
     27 // Load heart rate sensor module
     28 var heartRateSensor = require('jsupm_groveehr');
     29 // Instantiate a Grove Ear-clip Heart Rate sensor on digital pin D2
     30 var myHeartRateSensor = new heartRateSensor.GroveEHR(2);
     31 
     32 // set the beat counter to 0, init the clock and start counting beats
     33 myHeartRateSensor.clearBeatCounter();
     34 myHeartRateSensor.initClock();
     35 myHeartRateSensor.startBeatCounter();
     36 
     37 var millis, beats, hr;
     38 var myInterval = setInterval(function()
     39 {
     40 	// we grab these just for display purposes in this example
     41 	millis = myHeartRateSensor.getMillis();
     42 	beats = myHeartRateSensor.beatCounter();
     43 
     44 	// heartRate() requires that at least 5 seconds pass before
     45 	// returning anything other than 0
     46 	hr = myHeartRateSensor.heartRate();
     47 
     48 	// output milliseconds passed, beat count, and computed heart rate
     49 	console.log("Millis: " + millis + " Beats: " + beats +
     50 	            " Heart Rate: " + hr);
     51 }, 1000);
     52 
     53 // Print message when exiting
     54 process.on('SIGINT', function()
     55 {
     56 	clearInterval(myInterval);
     57 	myHeartRateSensor.stopBeatCounter();
     58 	myHeartRateSensor = null
     59 	heartRateSensor.cleanUp();
     60 	heartRateSensor = null;
     61 
     62 	console.log("Exiting");
     63 	process.exit(0);
     64 });
     65