From c21c431b7b2a3a75e9e94128a8c0f99d8899e476 Mon Sep 17 00:00:00 2001 From: Robert Wolterman Date: Sat, 25 Feb 2017 12:48:36 -0600 Subject: [PATCH] pwm1 works on the chip pro, commit to allow me to reset all the changes that broke stuff on the normal chip --- source/c_pwm.c | 10 ++++++++-- source/py_pwm.c | 8 +++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/source/c_pwm.c b/source/c_pwm.c index 67b006a..f496ffa 100644 --- a/source/c_pwm.c +++ b/source/c_pwm.c @@ -52,6 +52,7 @@ SOFTWARE. struct pwm_exp { char key[KEYLEN+1]; /* leave room for terminating NUL byte */ + int iscpro; int gpio; int initialized; int period_fd; @@ -412,6 +413,10 @@ int pwm_start(const char *key, float duty, float freq, int polarity) struct pwm_exp *new_pwm, *pwm; int gpio = 0; int initialized = 0; + int iscpro = 0; + + // Figure out if we are a CPro + iscpro = is_this_chippro(); // Figure out which pin we are if (strcmp(key,"U13_18") == 0) { @@ -501,6 +506,7 @@ int pwm_start(const char *key, float duty, float freq, int polarity) strncpy(new_pwm->key, key, KEYLEN); /* can leave string unterminated */ new_pwm->key[KEYLEN] = '\0'; /* terminate string */ new_pwm->gpio = gpio; + new_pwm->iscpro = iscpro; new_pwm->initialized = initialized; new_pwm->period_fd = period_fd; new_pwm->duty_fd = duty_fd; @@ -522,7 +528,7 @@ int pwm_start(const char *key, float duty, float freq, int polarity) int rtnval = 0; // Always set polarity first - if (ISCHIPPRO == 1) { + if (iscpro == 1) { rtnval = pwm_set_polarity(key, polarity); } rtnval = pwm_set_enable(key, ENABLE); @@ -557,7 +563,7 @@ int pwm_disable(const char *key) pwm_set_frequency(key, 0); pwm_set_duty_cycle(key, 0); pwm_set_enable(key, DISABLE); - if (ISCHIPPRO == 1) { + if (pwm->iscpro == 1) { pwm_set_polarity(key, 0); } diff --git a/source/py_pwm.c b/source/py_pwm.c index 7ab7a54..6019b36 100644 --- a/source/py_pwm.c +++ b/source/py_pwm.c @@ -76,13 +76,11 @@ static int init_module(void) // python function value = is_chip_pro static PyObject *py_is_chip_pro(PyObject *self, PyObject *args) { + int is_cpro; PyObject *py_value; - if (!module_setup) { - init_module(); - } - - py_value = Py_BuildValue("i", ISCHIPPRO); + is_cpro = is_this_chippro(); + py_value = Py_BuildValue("i", is_cpro); return py_value; }