pulsesensor: throw exception(s) on fatal errors

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson 2015-09-11 10:38:23 -06:00 committed by Mihai Tudor Panu
parent 5e9d9f4e66
commit 60a3f6cd7e

View File

@ -22,6 +22,8 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <string>
#include <stdexcept>
#include <unistd.h>
#include <stdlib.h>
#include "pulsensor.h"
@ -29,7 +31,12 @@
void init_pulsensor (pulsensor_context * ctx, callback_handler handler) {
ctx->callback = handler;
ctx->pin_ctx = mraa_aio_init(0);
if ( !(ctx->pin_ctx = mraa_aio_init(0)) )
{
throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_aio_init() failed, invalid pin?");
return;
}
ctx->sample_counter = 0;
ctx->last_beat_time = 0;