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) 2015 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 var recorder_lib = require("jsupm_isd1820"); 28 29 // Instantiate a ISD1820 on digital pins 2 (play) and 3 (record) 30 // This example was tested on the Grove Recorder. 31 var myRecorder = new recorder_lib.ISD1820(2, 3); 32 33 34 var doRecord = false; 35 36 if (process.argv.length > 2) 37 doRecord = true; 38 39 // if an argument was specified (any argument), go into record mode, 40 // else playback a previously recorded sample 41 console.log("Supply any argument to the command line to record."); 42 console.log("Running this example without arguments will play back "); 43 console.log("any previously recorded sound."); 44 console.log("There is approximately 10 seconds of recording time.\n"); 45 46 // depending on what was selected, do it, and sleep for 15 seconds 47 if (doRecord) 48 myRecorder.record(true); 49 else 50 myRecorder.play(true); 51 52 // There are about 10 seconds of recording/playback time, so we will 53 // sleep for a little extra time. 54 console.log("Sleeping for 15 seconds..."); 55 56 setTimeout(function() 57 { 58 // turn off whatever we were doing. 59 if (doRecord) 60 myRecorder.record(false); 61 else 62 myRecorder.play(false); 63 console.log("Exiting"); 64 myRecorder = null; 65 recorder_lib.cleanUp(); 66 recorder_lib = null; 67 process.exit(0); 68 }, 15 * 1000); 69