• Pwm
  • Pwm Class

    The class represent a pulse wide modulation file system interface. More...

    Header: #include <Pwm>
    Inherits:

    Public Types

    enum Polarity { PolarityNormal, PolarityInversed, PolarityInvalid }

    Public Functions

    Pwm(int chipNumber, QObject * parent = nullptr)
    ~Pwm()
    int chipNumber()
    bool disable()
    long dutyCycle()
    bool enable()
    bool exportPwm()
    double frequency()
    bool isEnabled()
    int percentage()
    long period()
    Pwm::Polarity polarity()
    bool setDutyCycle(long nanoSeconds)
    bool setFrequency(double kHz)
    bool setPercentage(int percentage)
    bool setPeriod(long nanoSeconds)
    bool setPolarity(Pwm::Polarity polarity)

    Static Public Members

    bool isAvailable()

    Detailed Description

    The class represent a pulse wide modulation file system interface.

    This class provides a convenient access to the linux kernel PWM (pulse wide modulation) file system.

    By default, this class will check in the system path /sys/class/pwm/ for any PWM chips. You can find the kernel documentation here.

    This class assumes a file system format where each hardware PWM chip has his own filepath.

    /sys/class/pwm/pwmchip0
    /sys/class/pwm/pwmchip1

    The number pwmchip0 represents the chipNumber.

    Member Type Documentation

    enum Pwm::Polarity

    ConstantValueDescription
    Pwm::PolarityNormal0Normal polarity. This is the default value.
    Pwm::PolarityInversed1Inversed polarity.
    Pwm::PolarityInvalid2The current polarity value is invalid.

    Member Function Documentation

    Pwm::Pwm(int chipNumber, QObject * parent = nullptr)

    Constructs a new Pwm interface for the given chipNumber (/sys/class/pwm/pwmchip<chipNumber>) with the given parent.

    Pwm::~Pwm()

    Destructor for this Pwm interface.

    int Pwm::chipNumber()

    Returns the chip number of this Pwm.

    The chip number indicates which file path will be used: /sys/class/pwm/pwmchip<chipNumber>.

    bool Pwm::disable()

    Returns true, if this Pwm interface has been disabled successfully.

    long Pwm::dutyCycle()

    Returns the duty cycle [ns] of the Pwm. The duty cycle is the active time of one period.

    See also setDutyCycle().

    bool Pwm::enable()

    Returns true, if this Pwm interface has been enabled successfully.

    bool Pwm::exportPwm()

    Returns true, if this Pwm interface has been exported successfully.

    double Pwm::frequency()

    Returns the frequency [kHz] of the Pwm.

    See also setFrequency().

    [static] bool Pwm::isAvailable()

    Returns true, if the path /sys/class/pwm exists and is not empty.

    bool Pwm::isEnabled()

    Returns true, if this Pwm interface is enabled.

    int Pwm::percentage()

    Returns the current percentage of this Pwm.

    See also setPercentage().

    long Pwm::period()

    Returns the period of this PWM.

    See also setPeriod().

    Pwm::Polarity Pwm::polarity()

    Returns the Polarity of this Pwm.

    See also setPolarity().

    bool Pwm::setDutyCycle(long nanoSeconds)

    Returns true, if the duty cycle [ns] of the Pwm has been set successfully to the given nanoSeconds. The duty cycle is the active time of one period.

    See also dutyCycle().

    bool Pwm::setFrequency(double kHz)

    Returns true, if the frequency [kHz] of this Pwm has been set successfully to the given kHz.

    See also frequency().

    bool Pwm::setPercentage(int percentage)

    Returns true, if the percentage of this Pwm has been set to percentage successfully.

    See also percentage().

    bool Pwm::setPeriod(long nanoSeconds)

    Returns true, if the period of this Pwm has been set to nanoSeconds successfully.

    See also period().

    bool Pwm::setPolarity(Pwm::Polarity polarity)

    Returns true, if the polarity of this Pwm has been set to polarity successfully.

    See also polarity().