diff --git a/source/c_softpwm.c b/source/c_softpwm.c index 08fb10e..d5fadc4 100644 --- a/source/c_softpwm.c +++ b/source/c_softpwm.c @@ -241,8 +241,12 @@ int softpwm_start(const char *key, float duty, float freq, int polarity) if (get_gpio_number(key, &gpio) < 0) return -1; - if (gpio_export(gpio) < 0) - return -1; + if (gpio_export(gpio) < 0) { + char err[2000]; + snprintf(err, sizeof(err), "Error setting up softpwm on pin %d, maybe already exported? (%s)", gpio, get_error_msg()); + add_error_msg(err); + return -1; + } if (gpio_set_direction(gpio, OUTPUT) < 0) return -1; diff --git a/source/py_softpwm.c b/source/py_softpwm.c index 514c2ae..e2f91d7 100644 --- a/source/py_softpwm.c +++ b/source/py_softpwm.c @@ -80,8 +80,14 @@ static PyObject *py_start_channel(PyObject *self, PyObject *args, PyObject *kwar return NULL; } - if (!softpwm_start(key, duty_cycle, frequency, polarity)) - return NULL; + if (softpwm_start(key, duty_cycle, frequency, polarity) < 0) + { + printf("softpwm_start failed"); + char err[2000]; + snprintf(err, sizeof(err), "Error starting softpwm on pin %s (%s)", key, get_error_msg()); + PyErr_SetString(PyExc_RuntimeError, err); + return NULL; + } Py_RETURN_NONE; }