mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
hcsr04: 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:
parent
1f1c303937
commit
8d38bd0bcc
@ -24,6 +24,8 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <functional>
|
||||
@ -47,8 +49,9 @@ HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *)) {
|
||||
|
||||
m_triggerPinCtx = mraa_gpio_init (triggerPin);
|
||||
if (m_triggerPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", triggerPin);
|
||||
exit (1);
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_pwm_init() failed, invalid pin?");
|
||||
return;
|
||||
}
|
||||
|
||||
mraa_gpio_dir(m_triggerPinCtx, MRAA_GPIO_OUT);
|
||||
@ -56,8 +59,9 @@ HCSR04::HCSR04 (uint8_t triggerPin, uint8_t echoPin, void (*fptr)(void *)) {
|
||||
|
||||
m_echoPinCtx = mraa_gpio_init(echoPin);
|
||||
if (m_echoPinCtx == NULL) {
|
||||
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", echoPin);
|
||||
exit (1);
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": mraa_gpio_init() failed, invalid pin?");
|
||||
return;
|
||||
}
|
||||
|
||||
mraa_gpio_dir(m_echoPinCtx, MRAA_GPIO_IN);
|
||||
|
Loading…
x
Reference in New Issue
Block a user