- java.lang.Object
-
- com.pi4j.common.IdentityBase
-
- com.pi4j.io.IOBase<Pwm,PwmConfig,PwmProvider>
-
- com.pi4j.io.pwm.PwmBase
-
- All Implemented Interfaces:
Describable
,Identity
,Lifecycle
,Extension
,IO<Pwm,PwmConfig,PwmProvider>
,OnOff<Pwm>
,OnOffRead<Pwm>
,OnOffWrite<Pwm>
,Pwm
public abstract class PwmBase extends IOBase<Pwm,PwmConfig,PwmProvider> implements Pwm
Abstract PwmBase class.
- Version:
- $Id: $Id
- Author:
- Robert Savage (http://www.savagehomeautomation.com)
-
-
Constructor Summary
Constructors Constructor Description PwmBase(PwmProvider provider, PwmConfig config)
Constructor for PwmBase.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Pwm
addPreset(PwmPreset preset)
Add a new PwmPreset to this PWM instance.Pwm
applyPreset(String name)
Apply/recall a PwmPreset by name to this PWM instance.PwmPreset
deletePreset(String name)
Delete/remove a PwmPreset by name from this PWM instance.int
getActualFrequency()
Get the actual frequency value in Hertz (number of cycles per second) applied by the PWM signal generator after the PWM signal is turned 'ON'.float
getDutyCycle()
Get the duty-cycle value as a decimal value that represents the percentage of the ON vs OFF time of the PWM signal for each period.int
getFrequency()
Get the configured frequency value in Hertz (number of cycles per second) that the PWM signal generator should attempt to output when the PWM signal is turned 'ON'.PwmPreset
getPreset(String name)
Get a single PwmPreset from this PWM instance by the preset's name.Map<String,PwmPreset>
getPresets()
Get all the PwmPreset instances assigned to this PWM instance.Pwm
initialize(Context context)
initialize.boolean
isOn()
Get the PWM signal ON/ENABLED state.void
setDutyCycle(Number dutyCycle)
Set the duty-cycle value as a decimal value that represents the percentage of the ON vs OFF time of the PWM signal for each period.void
setFrequency(int frequency)
Set the configured frequency value in Hertz (number of cycles per second) that the PWM signal generator should use when the PWM signal is turned 'ON'.Pwm
shutdown(Context context)
shutdown.-
Methods inherited from class com.pi4j.common.IdentityBase
description, id, metadata, name
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.pi4j.common.Identity
description, getDescription, getId, getMetadata, getName, id, metadata, name
-
-
-
-
Constructor Detail
-
PwmBase
public PwmBase(PwmProvider provider, PwmConfig config)
Constructor for PwmBase.
- Parameters:
provider
- aPwmProvider
object.config
- aPwmConfig
object.
-
-
Method Detail
-
getDutyCycle
public float getDutyCycle() throws IOException
Get the duty-cycle value as a decimal value that represents the percentage of the ON vs OFF time of the PWM signal for each period. The duty-cycle range is valid from 0 to 100 including factional values. (Values above 50% mean the signal will remain HIGH more time than LOW.) Example: A value of 50 represents a duty-cycle where half of the time period the signal is LOW and the other half is HIGH.- Specified by:
getDutyCycle
in interfacePwm
- Returns:
- duty-cycle value expressed as a percentage (rage: 0-100)
- Throws:
IOException
- if fails to communicate with the PWM pin
-
getFrequency
public int getFrequency() throws IOException
Get the configured frequency value in Hertz (number of cycles per second) that the PWM signal generator should attempt to output when the PWM signal is turned 'ON'. Please note that certain PWM signal generators may be limited to specific frequency bands and may not generate all possible explicit frequency values. After enabling the PWM signal using the 'on(..) method, you can check the 'Pwm::frequency()' or 'Pwm::getFrequency()' properties to determine what frequency the PWM generator actually applied.- Specified by:
getFrequency
in interfacePwm
- Returns:
- the configured frequency (Hz) that is used when turning the PWM signal to the 'ON' state.
- Throws:
IOException
- if fails to communicate with the PWM pin
-
getActualFrequency
public int getActualFrequency() throws IOException
Get the actual frequency value in Hertz (number of cycles per second) applied by the PWM signal generator after the PWM signal is turned 'ON'. Please note that certain PWM signal generators may be limited to specific frequency bands and may not generate all possible explicit frequency values. After enabling the PWM signal using the 'on(...)' method, you can call this method to determine what frequency the PWM generator actually applied.- Specified by:
getActualFrequency
in interfacePwm
- Returns:
- the actual frequency (Hz) applied by the PWM generator when the PWM signal is set to the 'ON' state.
- Throws:
IOException
- if fails to communicate with the PWM pin
-
setDutyCycle
public void setDutyCycle(Number dutyCycle) throws IOException
Set the duty-cycle value as a decimal value that represents the percentage of the ON vs OFF time of the PWM signal for each period. The duty-cycle range is valid from 0 to 100 including factional values. This method will not update a live PWM signal, but rather stage the duty-cycle value for subsequent call to the 'Pwm::On()' method. Call 'Pwm::On()' if you wish to make a live/ immediate change to the duty-cycle on an existing PWM signal. (Values above 50% mean the signal will remain HIGH more time than LOW.) Example: A value of 50 represents a duty-cycle where half of the time period the signal is LOW and the other half is HIGH.- Specified by:
setDutyCycle
in interfacePwm
- Parameters:
dutyCycle
- duty-cycle value expressed as a percentage (rage: 0-100)- Throws:
IOException
- if fails to communicate with the PWM pin
-
setFrequency
public void setFrequency(int frequency) throws IOException
Set the configured frequency value in Hertz (number of cycles per second) that the PWM signal generator should use when the PWM signal is turned 'ON'. Note: This method will not update a live PWM signal, but rather stage the frequency value for subsequent call to the 'Pwm::On()' method. Call 'Pwm::On()' if you wish to make a live/immediate change to the duty-cycle on an existing PWM signal.- Specified by:
setFrequency
in interfacePwm
- Parameters:
frequency
- the number of cycles per second (Hertz)- Throws:
IOException
- if fails to communicate with the PWM pin
-
isOn
public boolean isOn()
Get the PWM signal ON/ENABLED state.
-
initialize
public Pwm initialize(Context context) throws InitializeException
initialize.
- Specified by:
initialize
in interfaceLifecycle
- Overrides:
initialize
in classIOBase<Pwm,PwmConfig,PwmProvider>
- Parameters:
context
- aContext
object.- Returns:
- a T object.
- Throws:
InitializeException
- if an error occurs during initialization.
-
shutdown
public Pwm shutdown(Context context) throws ShutdownException
shutdown.
- Specified by:
shutdown
in interfaceLifecycle
- Overrides:
shutdown
in classIOBase<Pwm,PwmConfig,PwmProvider>
- Parameters:
context
- aContext
object.- Returns:
- a T object.
- Throws:
ShutdownException
- if an error occurs during shutdown.
-
getPresets
public Map<String,PwmPreset> getPresets()
Get all the PwmPreset instances assigned to this PWM instance.- Specified by:
getPresets
in interfacePwm
- Returns:
- a map of PwmPresets indexed/cataloged by preset name.
-
getPreset
public PwmPreset getPreset(String name)
Get a single PwmPreset from this PWM instance by the preset's name.
-
deletePreset
public PwmPreset deletePreset(String name)
Delete/remove a PwmPreset by name from this PWM instance.- Specified by:
deletePreset
in interfacePwm
- Parameters:
name
- preset name string- Returns:
- the deleted PWM Preset instance
-
addPreset
public Pwm addPreset(PwmPreset preset)
Add a new PwmPreset to this PWM instance. You can create new PWM preset instance using the 'PwmPreset::newBuilder(name)' static factory method.
-
applyPreset
public Pwm applyPreset(String name) throws IOException
Apply/recall a PwmPreset by name to this PWM instance. This will update the PWM signal with the configured PWM frequency and duty-cycle defined in the preset object.- Specified by:
applyPreset
in interfacePwm
- Parameters:
name
- preset name string- Returns:
- the deleted PWM Preset instance
- Throws:
IOException
- if fails to communicate with the PWM pin
-
-