exception: Add exceptions when context creation fails
* Exceptions only fired in constructor when it would initialise with a NULL context causing segfaults if used any further * Adds exception.i requirement to mraa.i for node.js and python support Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "pwm.h"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace mraa {
|
||||
|
||||
@@ -47,12 +48,20 @@ class Pwm {
|
||||
* if the pinmapper exported it
|
||||
*/
|
||||
Pwm(int pin, int chipid=-1, bool owner = true) {
|
||||
if (chipid == -1)
|
||||
if (chipid == -1) {
|
||||
m_pwm = mraa_pwm_init(pin);
|
||||
else
|
||||
}
|
||||
else {
|
||||
m_pwm = mraa_pwm_init_raw(pin, chipid);
|
||||
if (!owner)
|
||||
}
|
||||
|
||||
if (m_pwm == NULL) {
|
||||
throw std::invalid_argument("Error initialising PWM on pin");
|
||||
}
|
||||
|
||||
if (!owner) {
|
||||
mraa_pwm_owner(m_pwm, 0);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Pwm destructor
|
||||
|
||||
Reference in New Issue
Block a user