PWM class
PWM wrapper functions for Linux userspace sysfs PWMs.
Example usage:
var pwm = PWM(0, 0); // chip 0, channel 0
pwm.setFrequency(PWM.freq1kHz); // 1kHz
pwm.setDutyCycle(PWM.dutyHalf); // 50% duty cycle
pwm.enable();
// ... use PWM
pwm.dispose();
c-periphery PWM documentation.
- Inheritance
-
- Object
- IsolateAPI
- PWM
Constructors
- PWM(int chip, int channel)
- PWM.isolate(String json)
Properties
Methods
-
disable(
) → void - Disables the PWM output.
-
dispose(
) → void - Releases all internal native resources.
-
enable(
) → void - Enables the PWM output.
-
fromJson(
String json) → IsolateAPI -
override
-
getChannel(
) → int - Returns the channel number of the PWM handle.
-
getChip(
) → int - Return the chip number of the PWM handle.
-
getDutyCycle(
) → double - Gets the duty cycle as a ratio between 0.0 to 1.0 in second of the PWM.
-
getDutyCycleNs(
) → int - Gets the duty cycle in nanoseconds of the PWM.
-
getDutyCyclePercent(
) → double - Gets duty cycle as a percentage (0-100)
-
getEnabled(
) → bool -
getErrno(
) → int - Returns the libc errno of the last failure that occurred.
-
getFrequency(
) → double - Gets the frequency in Hz of the PWM.
-
getFrequencyKHz(
) → double - Gets frequency in kHz
-
getFrequencyMHz(
) → double - Gets frequency in MHz
-
getHandle(
) → int -
override
-
getPeriod(
) → double - Gets the period in seconds of the PWM.
-
getPeriodNs(
) → int - Gets the period in nanoseconds of the PWM.
-
getPolarity(
) → Polarity - Returns the polarity of the PWM.
-
getPWMinfo(
) → String - Returns a string representation of the PWM handle.
-
isIsolate(
) → bool -
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setDutyCycle(
double dutyCycle) → void -
Sets the
dutyCycleas a ratio between 0.0 to 1.0 in second of the PWM. -
setDutyCycleNs(
int nanoseconds) → void -
Sets the duty cycle in
nanosecondsof the PWM. -
setDutyCyclePercent(
double percent) → void - Sets duty cycle as a percentage (0-100)
-
setEnabled(
bool flag) → void - Sets the output state of the PWM.
-
setFrequency(
double frequency) → void -
Sets the
frequencyin Hz of the PWM. -
setFrequencyKHz(
double frequencyKHz) → void - Sets frequency in kHz
-
setFrequencyMHz(
double frequencyMHz) → void - Sets frequency in MHz
-
setHandle(
int handle) → void -
override
-
setPeriod(
double seconds) → void -
Sets the period in
secondsof the PWM. -
setPeriodNs(
int nanoseconds) → void -
Sets the period in
nanosecondsof the PWM. -
setPolarity(
Polarity polarity) → void -
Sets the output
polarityof the PWM. -
toJson(
) → String -
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
getPWMerrorCode(
int value) → PWMerrorCode -
Converts the native error code
valueto PWMerrorCode.
Constants
- duty0Percent → const double
- Common duty cycles (0.0 to 1.0)
- duty25Percent → const double
- duty50Percent → const double
- duty75Percent → const double
- duty100Percent → const double
- dutyFull → const double
- dutyHalf → const double
- dutyOff → const double
- Alternative naming for duty cycles
- dutyQuarter → const double
- dutyThreeQuarters → const double
- freq1kHz → const double
- Common PWM frequencies in Hz
- freq1MHz → const double
- freq10kHz → const double
- freq100kHz → const double