Beispiel #1
0
// python function cleanup(channel)
static PyObject *py_cleanup(PyObject *self, PyObject *args, PyObject *kwargs)
{
    char key[8];
    char *channel;
    static char *kwlist[] = {"channel", NULL};

    clear_error_msg();

    // Channel is optional
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &channel)) {
        return NULL;
    }

    // The !channel fixes issues #50
    if (channel == NULL || strcmp(channel, "\0") == 0) {
        softpwm_cleanup();
    } else {
        if (!get_key(channel, key)) {
            softpwm_cleanup();
        }
        softpwm_disable(key);
    }

    Py_RETURN_NONE;
}
Beispiel #2
0
static void power_down(uint8_t wdto)
{
#ifdef PROTOCOL_LUFA
    if (USB_DeviceState == DEVICE_STATE_Configured) return;
#endif
    wdt_timeout = wdto;

    // Watchdog Interrupt Mode
    wdt_intr_enable(wdto);

    // TODO: more power saving
    // See PicoPower application note
    // - I/O port input with pullup
    // - prescale clock
    // - BOD disable
    // - Power Reduction Register PRR

#ifdef SUSPEND_ACTION
    suspend_power_down_action();
#endif

#ifdef SOFTPWM_LED_ENABLE
    softpwm_disable();
#endif

    set_sleep_mode(SLEEP_MODE_PWR_DOWN);
    sleep_enable();
    sei();
    sleep_cpu();
    sleep_disable();

    // Disable watchdog after sleep
    wdt_disable();
}
Beispiel #3
0
// python function stop(channel)
static PyObject *py_stop_channel(PyObject *self, PyObject *args, PyObject *kwargs)
{
    char key[8];
    char *channel;
    int gpio;
    int allowed = -1;

    clear_error_msg();

    if (!PyArg_ParseTuple(args, "s", &channel))
        return NULL;

    if (!get_key(channel, key)) {
        PyErr_SetString(PyExc_ValueError, "Invalid PWM key or name.");
        return NULL;
    }

    // check to ensure gpio is one of the allowed pins
    // Not protecting the call as if the get_key() fails, we won't make it here
    get_gpio_number(channel, &gpio);

    // Check to see if GPIO is allowed on the hardware
    // A 1 means we're good to go
    allowed = gpio_allowed(gpio);
    if (allowed == -1) {
        char err[2000];
        snprintf(err, sizeof(err), "Error determining hardware. (%s)", get_error_msg());
        PyErr_SetString(PyExc_ValueError, err);
        return NULL;
    } else if (allowed == 0) {
        char err[2000];
        snprintf(err, sizeof(err), "GPIO %d not available on current Hardware", gpio);
        PyErr_SetString(PyExc_ValueError, err);
        return NULL;
    }

    softpwm_disable(key);

    Py_RETURN_NONE;
}
Beispiel #4
0
void softpwm_cleanup(void)
{
    while (exported_pwms != NULL) {
        softpwm_disable(exported_pwms->key);
    }
}