1
0
mirror of https://github.com/xtacocorex/CHIP_IO synced 2025-07-20 12:53:22 +00:00

Adds runtime err if softpwm fails for Issue #16

This commit is contained in:
Brady L. Hurlburt
2016-07-28 12:49:28 +00:00
parent 40ae9a5cdc
commit 1e3e801e60
2 changed files with 14 additions and 4 deletions

View File

@ -241,8 +241,12 @@ int softpwm_start(const char *key, float duty, float freq, int polarity)
if (get_gpio_number(key, &gpio) < 0) if (get_gpio_number(key, &gpio) < 0)
return -1; return -1;
if (gpio_export(gpio) < 0) 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; return -1;
}
if (gpio_set_direction(gpio, OUTPUT) < 0) if (gpio_set_direction(gpio, OUTPUT) < 0)
return -1; return -1;

View File

@ -80,8 +80,14 @@ static PyObject *py_start_channel(PyObject *self, PyObject *args, PyObject *kwar
return NULL; return NULL;
} }
if (!softpwm_start(key, duty_cycle, frequency, polarity)) 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; return NULL;
}
Py_RETURN_NONE; Py_RETURN_NONE;
} }