1

コマンドラインからルートとして問題なく実行できecho 100 > /sys/class/soft_pwm/pwm-35/duty_cycleますが、ルートとして実行しているときにQt 5コードを同じように実行することはできません。以下はコードです - 私は何を間違っていますか? ありがとう。

/**
 * Set the PWM on the Red / Green LEDs
 * @param percent
 */
void LedController::setLedPwm(int percent) {

    // Cap the percent
    if ( percent > 90 ) {
        percent = 90;
    }
    if ( percent < 25 ) {
        percent = 25;
    }

    // Scale to usable percent
    percent = abs(percent - 100);

    QFile file1("/sys/class/soft_pwm/pwm-35/duty_cycle");
    if (!file1.open(QIODevice::WriteOnly | QIODevice::Text)) {
        qDebug() << "LedController: Cannot set LED PWM for Red/Green LEDs [ 35 ]...";
        return;
    }
    QDataStream in1(&file1);
    QString toWrite1 = QString("%1\n").arg(percent);
    qDebug() << "LedController: PWM Led [ 35 ]" << toWrite1;
    in1 << toWrite1;
    file1.close();

    QFile file2("/sys/class/soft_pwm/pwm-39/duty_cycle");
    if (!file2.open(QIODevice::WriteOnly | QIODevice::Text)) {
        qDebug() << "LedController: Cannot set LED PWM for Red/Green LEDs [ 39 ]...";
        return;
    }
    QDataStream in2(&file2);
    QString toWrite2 = QString("%1\n").arg(percent);
    qDebug() << "LedController: PWM Led [ 35 ]" << toWrite2;
    in2 << toWrite1;
    file2.close();

}
4

1 に答える 1