コード例 #1
0
ファイル: pwm.c プロジェクト: Hbrinj/mraa
mraa_result_t
mraa_pwm_write(mraa_pwm_context dev, float percentage)
{
    if (!dev) {
        syslog(LOG_ERR, "pwm: write: context is NULL");
        return MRAA_ERROR_INVALID_HANDLE;
    }

    if (IS_FUNC_DEFINED(dev, pwm_write_pre)) {
        if (dev->advance_func->pwm_write_pre(dev, percentage) != MRAA_SUCCESS) {
            syslog(LOG_ERR, "mraa_pwm_write (pwm%i): pwm_write_pre failed, see syslog", dev->pin);
            return MRAA_ERROR_UNSPECIFIED;
        }
    }

    if (dev->period == -1) {
        if (mraa_pwm_read_period(dev) <= 0)
            return MRAA_ERROR_NO_DATA_AVAILABLE;
    }

    if (percentage > 1.0f) {
        syslog(LOG_WARNING, "pwm_write: %i%% entered, defaulting to 100%%",(int) percentage * 100);
        return mraa_pwm_write_duty(dev, dev->period);
    }
    return mraa_pwm_write_duty(dev, percentage * dev->period);
}
コード例 #2
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;
}
コード例 #3
0
ファイル: pwm.c プロジェクト: ak1394/mraa
mraa_result_t
mraa_pwm_write(mraa_pwm_context dev, float percentage)
{
    if (percentage >= 1.0f) {
        return mraa_pwm_write_duty(dev, mraa_pwm_read_period(dev));
    }
    return mraa_pwm_write_duty(dev, percentage * mraa_pwm_read_period(dev));
}
コード例 #4
0
ファイル: pwm.c プロジェクト: Sayter99/mraa
mraa_result_t
mraa_pwm_write(mraa_pwm_context dev, float percentage)
{
    if (dev->period == -1) {
        if (mraa_pwm_read_period(dev) <= 0)
            return MRAA_ERROR_NO_DATA_AVAILABLE;
    }

    if (percentage > 1.0f) {
        syslog(LOG_WARNING, "pwm: number greater than 1 entered, defaulting to 100%%");
        return mraa_pwm_write_duty(dev, dev->period);
    }
    return mraa_pwm_write_duty(dev, percentage * dev->period);
}
コード例 #5
0
ファイル: pwm.c プロジェクト: cocasema/mraa
mraa_result_t
mraa_pwm_write(mraa_pwm_context dev, float percentage)
{
    if (!dev) {
        syslog(LOG_ERR, "pwm: write: context is NULL");
        return MRAA_ERROR_INVALID_HANDLE;
    }

    if (dev->period == -1) {
        if (mraa_pwm_read_period(dev) <= 0)
            return MRAA_ERROR_NO_DATA_AVAILABLE;
    }

    if (percentage > 1.0f) {
        syslog(LOG_WARNING, "pwm_write: %i%% entered, defaulting to 100%%",(int) percentage * 100);
        return mraa_pwm_write_duty(dev, dev->period);
    }
    return mraa_pwm_write_duty(dev, percentage * dev->period);
}
コード例 #6
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;
}
コード例 #7
0
ファイル: pwm.c プロジェクト: Hbrinj/mraa
mraa_result_t
mraa_pwm_pulsewidth_us(mraa_pwm_context dev, int us)
{
    return mraa_pwm_write_duty(dev, us * 1000);
}