コード例 #1
0
ファイル: pwm.c プロジェクト: cocasema/mraa
mraa_result_t
mraa_pwm_config_percent(mraa_pwm_context dev, int ms, float percentage)
{
    int old_dutycycle, old_period, status;

    if (!dev) {
        syslog(LOG_ERR, "pwm: config_percent: context is NULL");
        return MRAA_ERROR_INVALID_HANDLE;
    }

    old_dutycycle = mraa_pwm_read_duty(dev);
    old_period = mraa_pwm_read_period(dev);
    status = mraa_pwm_period_us(dev, ms * 1000);
    if (status != MRAA_SUCCESS) {
        mraa_pwm_write_duty(dev, old_dutycycle);
        return status;
    }
    status = mraa_pwm_write_duty(dev, 0);
    if (status != MRAA_SUCCESS) {
        return status;
    }
    status = mraa_pwm_pulsewidth_us(dev, (ms * 1000) * percentage);
    if (status != MRAA_SUCCESS) {
        mraa_pwm_write_duty(dev, old_dutycycle);
        mraa_pwm_write_period(dev, old_period);
        return status;
    }
    return MRAA_SUCCESS;
}
コード例 #2
0
ファイル: pwm.c プロジェクト: Sayter99/mraa
mraa_result_t
mraa_pwm_period_us(mraa_pwm_context dev, int us)
{
    if (us < plat->pwm_min_period || us > plat->pwm_max_period) {
        syslog(LOG_ERR, "pwm: period value outside platform range");
        return MRAA_ERROR_INVALID_PARAMETER;
    }
    return mraa_pwm_write_period(dev, us * 1000);
}
コード例 #3
0
ファイル: pwm.c プロジェクト: Intellifora/mraa
mraa_result_t
mraa_pwm_period_us(mraa_pwm_context dev, int us)
{
    int min, max;
    if (mraa_is_sub_platform_id(dev->chipid)) {
        min = plat->sub_platform->pwm_min_period;
        max = plat->sub_platform->pwm_max_period;
    } else {
        min = plat->pwm_min_period;
        max = plat->pwm_max_period;
    }
    if (us < min || us > max) {
        syslog(LOG_ERR, "pwm: period value outside platform range");
        return MRAA_ERROR_INVALID_PARAMETER;
    }
    return mraa_pwm_write_period(dev, us * 1000);
}
コード例 #4
0
ファイル: pwm.c プロジェクト: ak1394/mraa
mraa_result_t
mraa_pwm_config_percent(mraa_pwm_context dev, int ms ,float percentage)
{
    int old_dutycycle, old_period, status;
    old_dutycycle = mraa_pwm_read_duty(dev);
    old_period = mraa_pwm_read_period(dev);
    status = mraa_pwm_write_duty(dev, 0);
    if (status != MRAA_SUCCESS) {
        return status;
    }
    status = mraa_pwm_period_us(dev, ms*1000);
    if (status != MRAA_SUCCESS) {
        mraa_pwm_write_duty(dev, old_dutycycle);
        return status;
    }
    status = mraa_pwm_pulsewidth_us(dev, (ms*1000)*percentage);
    if (status != MRAA_SUCCESS) {
        mraa_pwm_write_duty(dev, old_dutycycle);
        mraa_pwm_write_period(dev, old_period);
        return status;
    }
    return MRAA_SUCCESS;
}