2014-12-18 16:10:50 -07:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
|
|
|
* Copyright (c) 2014 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.
|
2014-12-18 16:10:50 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2014-12-18 16:10:50 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
|
2016-09-13 11:10:13 -07:00
|
|
|
#include "ehr.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2014-12-18 16:10:50 -07:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int shouldRun = true;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
2014-12-18 16:10:50 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
2014-12-18 16:10:50 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main()
|
2014-12-18 16:10:50 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
signal(SIGINT, sig_handler);
|
2014-12-18 16:10:50 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
|
|
|
// Instantiate a Ear-clip Heart Rate sensor on digital pin D2
|
|
|
|
upm::EHR heart(2);
|
2014-12-18 16:10:50 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// set the beat counter to 0, init the clock and start counting beats
|
|
|
|
heart.clearBeatCounter();
|
|
|
|
heart.initClock();
|
|
|
|
heart.startBeatCounter();
|
2014-12-18 16:10:50 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
while (shouldRun) {
|
|
|
|
// we grab these just for display purposes in this example
|
|
|
|
uint32_t millis = heart.getMillis();
|
|
|
|
uint32_t beats = heart.beatCounter();
|
2014-12-18 16:10:50 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// heartRate() requires that at least 5 seconds pass before
|
|
|
|
// returning anything other than 0
|
|
|
|
int hr = heart.heartRate();
|
2014-12-18 16:10:50 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// output milliseconds passed, beat count, and computed heart rate
|
|
|
|
cout << "Millis: " << millis << " Beats: " << beats;
|
|
|
|
cout << " Heart Rate: " << hr << endl;
|
|
|
|
|
|
|
|
upm_delay(1);
|
2014-12-18 16:10:50 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
heart.stopBeatCounter();
|
|
|
|
//! [Interesting]
|
2014-12-18 16:10:50 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting..." << endl;
|
2014-12-18 16:10:50 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
return 0;
|
|
|
|
}
|