2015-04-03 12:51:57 -06:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
|
|
|
* Copyright (c) 2015 Intel Corporation.
|
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2015-04-03 12:51:57 -06:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2015-04-03 12:51:57 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2017-08-30 15:00:29 -07:00
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "isd1820.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2015-04-03 12:51:57 -06:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
2015-04-03 12:51:57 -06:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
|
|
|
// Instantiate a ISD1820 on digital pins 2 (play) and 3 (record)
|
|
|
|
// This example was tested on the Grove Recorder.
|
|
|
|
|
|
|
|
upm::ISD1820 recorder(2, 3);
|
|
|
|
|
|
|
|
// if an argument was specified (any argument), go into record mode,
|
|
|
|
// else playback a previously recorded sample
|
|
|
|
|
|
|
|
cout << "Supply any argument to the command line to record." << endl;
|
|
|
|
cout << "Running this example without arguments will play back any " << endl;
|
|
|
|
cout << "previously recorded sound." << endl;
|
|
|
|
cout << "There is approximately 10 seconds of recording time." << endl;
|
2015-04-03 12:51:57 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << endl;
|
2015-04-03 12:51:57 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
bool doRecord = false;
|
2015-04-03 12:51:57 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
if (argc > 1)
|
|
|
|
doRecord = true;
|
2015-04-03 12:51:57 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// depending on what was selected, do it, and upm_delay for 15 seconds
|
2015-04-03 12:51:57 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
if (doRecord)
|
|
|
|
recorder.record(true);
|
|
|
|
else
|
|
|
|
recorder.play(true);
|
2015-04-03 12:51:57 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// There are about 10 seconds of recording/playback time, so we will
|
|
|
|
// upm_delay for a little extra time.
|
|
|
|
cout << "Sleeping for 15 seconds..." << endl;
|
|
|
|
upm_delay(15);
|
2015-04-03 12:51:57 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// now, turn off whatever we were doing.
|
2015-04-03 12:51:57 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
if (doRecord)
|
|
|
|
recorder.record(false);
|
|
|
|
else
|
|
|
|
recorder.play(false);
|
2015-04-03 12:51:57 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2015-04-03 12:51:57 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting..." << endl;
|
2015-04-03 12:51:57 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
return 0;
|
2015-04-03 12:51:57 -06:00
|
|
|
}
|