C# Class Emlid.WindowsIot.Hardware.Components.NxpPca9685.NxpPca9685Device

PCA9685 PWM LED driver (hardware device), connected via I2C.
The PCA9685 is a 16 channel, 12-bit PWM LED controller with I2C bus connection.

This class enables direct control of the device intended for internal use. If exposed to other users, it should wrapped by a thread safe class which coordinates access and deals with object lifetime (dispose). See http://www.nxp.com/documents/data_sheet/PCA9685.pdf for more information.

Inheritance: DisposableObject
Afficher le fichier Open project: emlid/Navio-SDK-Windows-IoT

Private Properties

Свойство Type Description
NxpPca9685Device System
OnChannelChanged void

Méthodes publiques

Méthode Description
CalculateFrequency ( byte preScale, int clockSpeed ) : float

Calculates the effective frequency from a NxpPca9685Register.PreScale value and clock speed.

CalculatePreScale ( float frequency, int clockSpeed ) : byte

Calculates the NxpPca9685Register.PreScale value from a desired frequency and clock speed.

Due to scaling only certain frequencies are possible. To get the resulting frequency from the desired frequency it is necessary to re-calcualte the effective frequency back from the pre-scale, i.e. call CalculateFrequency.

Clear ( ) : void

Clears all channels cleanly, then updates all Channels.

To "cleanly" clear the channels, it is necessary to first ensure they are not disabled, set them to zero, then disable them. Otherwise the ON value and the low OFF value remain because writes are ignored when the OFF channel bit 12 is already set.

GetChannelAddress ( int index ) : byte

Gets the register address of a channel by index.

ReadAll ( ) : void

Reads all values from the device and updates properties.

ReadChannel ( int index ) : NxpPca9685Channel

Reads a whole channel value (on and off), and updates it in Channels.

ReadChannelOff ( int index ) : int

Reads the PWM "off" (falling) value of a channel, and updates it in Channels.

ReadChannelOn ( int index ) : int

Reads the PWM "on" (rising) value of a channel, and updates it in Channels.

ReadFrequency ( ) : float

Reads the pre-scale register and calculates the Frequency (and related properties) based on ClockSpeed.

ReadMode1 ( ) : NxpPca9685Mode1Bits

Reads the current value of the NxpPca9685Register.Mode1 register.

ReadMode2 ( ) : NxpPca9685Mode2Bits

Reads the current value of the NxpPca9685Register.Mode2 register.

Restart ( ) : void

Restarts the device with default options, then updates all properties.

Restart ( NxpPca9685Mode1Bits options ) : void

Restarts the device with additional options specified, then updates all properties.

Sleep ( ) : bool

Enters sleep mode.

Sets the NxpPca9685Register.Mode1 register NxpPca9685Mode1Bits.Sleep bit then waits for ModeSwitchDelay to allow the oscillator to stop.

Wake ( ) : bool

Leaves sleep mode.

Clears the NxpPca9685Register.Mode1 register NxpPca9685Mode1Bits.Sleep bit then waits for ModeSwitchDelay to allow the oscillator to start.

WriteChannel ( int index, NxpPca9685ChannelValue value ) : NxpPca9685Channel

Writes the "on" and "off" values of a channel together, and updates it in Channels.

WriteChannelLength ( int index, int length, int delay ) : NxpPca9685Channel

Calculates the "on" and "off" values of a channel from length (and optional delay), then writes them together, and updates it in Channels.

WriteChannelMilliseconds ( int index, float length, float delay ) : NxpPca9685Channel

Calculates the "on" and "off" values of a channel from milliseconds (and optional delay), then writes them together, and updates it in Channels.

WriteChannelOff ( int index, int value ) : void

Writes the PWM "off" (falling) value of a channel.

WriteChannelOn ( int index, int value ) : void

Writes the PWM "on" (rising) value of a channel.

WriteFrequency ( float frequency ) : float

Calculates the pre-scale value from the frequency (according to ClockSpeed) then writes that register, then calls ReadFrequency to update properties. Note the actual frequency may differ to the requested frequency due to clock scale (rounding).

The pre-scale can only be set during sleep mode. This method enters Sleep if necessary, then only if the device was awake before, calls Wake afterwards. It's important not to start output unexpectedly to avoid damage, i.e. if the device was sleeping before, the frequency is changed without starting the oscillator.

Méthodes protégées

Méthode Description
Dispose ( bool disposing ) : void

DisposableObject.Dispose(bool).

ReadAllChannels ( ) : void

Reads all channels and updates Channels.

Private Methods

Méthode Description
NxpPca9685Device ( Windows.Devices.I2c.I2cDevice device, int clockSpeed ) : System
OnChannelChanged ( object sender, EventArgs arguments ) : void

Writes channel values to the device when the Channels member changes.

Method Details

CalculateFrequency() public static méthode

Calculates the effective frequency from a NxpPca9685Register.PreScale value and clock speed.
public static CalculateFrequency ( byte preScale, int clockSpeed ) : float
preScale byte Pre-scale value from which to calculate frequency.
clockSpeed int Clock speed with with to calcualte the frequency.
Résultat float

CalculatePreScale() public static méthode

Calculates the NxpPca9685Register.PreScale value from a desired frequency and clock speed.
Due to scaling only certain frequencies are possible. To get the resulting frequency from the desired frequency it is necessary to re-calcualte the effective frequency back from the pre-scale, i.e. call CalculateFrequency.
/// Thrown when an invalid frequency is used which causes the result to overflow a byte value. ///
public static CalculatePreScale ( float frequency, int clockSpeed ) : byte
frequency float /// Desired frequency. /// Must be between and to get a valid result. ///
clockSpeed int
Résultat byte

Clear() public méthode

Clears all channels cleanly, then updates all Channels.
To "cleanly" clear the channels, it is necessary to first ensure they are not disabled, set them to zero, then disable them. Otherwise the ON value and the low OFF value remain because writes are ignored when the OFF channel bit 12 is already set.
public Clear ( ) : void
Résultat void

Dispose() protected méthode

DisposableObject.Dispose(bool).
protected Dispose ( bool disposing ) : void
disposing bool
Résultat void

GetChannelAddress() public static méthode

Gets the register address of a channel by index.
public static GetChannelAddress ( int index ) : byte
index int Zero based channel number (0-15) or 16 for the "all call" channel.
Résultat byte

ReadAll() public méthode

Reads all values from the device and updates properties.
public ReadAll ( ) : void
Résultat void

ReadAllChannels() protected méthode

Reads all channels and updates Channels.
protected ReadAllChannels ( ) : void
Résultat void

ReadChannel() public méthode

Reads a whole channel value (on and off), and updates it in Channels.
public ReadChannel ( int index ) : NxpPca9685Channel
index int Zero based channel number (0-15).
Résultat NxpPca9685Channel

ReadChannelOff() public méthode

Reads the PWM "off" (falling) value of a channel, and updates it in Channels.
public ReadChannelOff ( int index ) : int
index int Zero based channel number (0-15).
Résultat int

ReadChannelOn() public méthode

Reads the PWM "on" (rising) value of a channel, and updates it in Channels.
public ReadChannelOn ( int index ) : int
index int Zero based channel number (0-15).
Résultat int

ReadFrequency() public méthode

Reads the pre-scale register and calculates the Frequency (and related properties) based on ClockSpeed.
public ReadFrequency ( ) : float
Résultat float

ReadMode1() public méthode

Reads the current value of the NxpPca9685Register.Mode1 register.
public ReadMode1 ( ) : NxpPca9685Mode1Bits
Résultat NxpPca9685Mode1Bits

ReadMode2() public méthode

Reads the current value of the NxpPca9685Register.Mode2 register.
public ReadMode2 ( ) : NxpPca9685Mode2Bits
Résultat NxpPca9685Mode2Bits

Restart() public méthode

Restarts the device with default options, then updates all properties.
public Restart ( ) : void
Résultat void

Restart() public méthode

Restarts the device with additional options specified, then updates all properties.
public Restart ( NxpPca9685Mode1Bits options ) : void
options NxpPca9685Mode1Bits /// Optional mode 1 parameters to add to the final restart sequence. A logical OR is applied to this value and /// the standard , and /// bits. ///
Résultat void

Sleep() public méthode

Enters sleep mode.
Sets the NxpPca9685Register.Mode1 register NxpPca9685Mode1Bits.Sleep bit then waits for ModeSwitchDelay to allow the oscillator to stop.
public Sleep ( ) : bool
Résultat bool

Wake() public méthode

Leaves sleep mode.
Clears the NxpPca9685Register.Mode1 register NxpPca9685Mode1Bits.Sleep bit then waits for ModeSwitchDelay to allow the oscillator to start.
public Wake ( ) : bool
Résultat bool

WriteChannel() public méthode

Writes the "on" and "off" values of a channel together, and updates it in Channels.
public WriteChannel ( int index, NxpPca9685ChannelValue value ) : NxpPca9685Channel
index int Zero based channel number (0-15) or 16 for the "all call" channel.
value NxpPca9685ChannelValue to write.
Résultat NxpPca9685Channel

WriteChannelLength() public méthode

Calculates the "on" and "off" values of a channel from length (and optional delay), then writes them together, and updates it in Channels.
public WriteChannelLength ( int index, int length, int delay ) : NxpPca9685Channel
index int Zero based channel number (0-15) or 16 for the "all call" channel.
length int Pulse length in clock ticks.
delay int Optional delay in clock ticks.
Résultat NxpPca9685Channel

WriteChannelMilliseconds() public méthode

Calculates the "on" and "off" values of a channel from milliseconds (and optional delay), then writes them together, and updates it in Channels.
public WriteChannelMilliseconds ( int index, float length, float delay ) : NxpPca9685Channel
index int Zero based channel number (0-15) or 16 for the "all call" channel.
length float /// Pulse length in milliseconds. Cannot be greater than one clock interval (1000 / frequency). ///
delay float Optional delay in milliseconds. Cannot be greater than one clock interval (1000 / frequency).
Résultat NxpPca9685Channel

WriteChannelOff() public méthode

Writes the PWM "off" (falling) value of a channel.
Thrown when the is greater then .
public WriteChannelOff ( int index, int value ) : void
index int Zero based channel number (0-15) or 16 for the "all call" channel.
value int 12-bit channel value in the range 0-.
Résultat void

WriteChannelOn() public méthode

Writes the PWM "on" (rising) value of a channel.
Thrown when the is greater than .
public WriteChannelOn ( int index, int value ) : void
index int Zero based channel number (0-15) or 16 for the "all call" channel.
value int 12-bit channel value in the range 0-.
Résultat void

WriteFrequency() public méthode

Calculates the pre-scale value from the frequency (according to ClockSpeed) then writes that register, then calls ReadFrequency to update properties. Note the actual frequency may differ to the requested frequency due to clock scale (rounding).
The pre-scale can only be set during sleep mode. This method enters Sleep if necessary, then only if the device was awake before, calls Wake afterwards. It's important not to start output unexpectedly to avoid damage, i.e. if the device was sleeping before, the frequency is changed without starting the oscillator.
/// Thrown when is less than or greater than /// . ///
public WriteFrequency ( float frequency ) : float
frequency float Frequency to convert in Hz.
Résultat float