C# Класс 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.

Наследование: DisposableObject
Показать файл Открыть проект

Private Properties

Свойство Тип Описание
NxpPca9685Device System
OnChannelChanged void

Открытые методы

Метод Описание
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.

Защищенные методы

Метод Описание
Dispose ( bool disposing ) : void

DisposableObject.Dispose(bool).

ReadAllChannels ( ) : void

Reads all channels and updates Channels.

Приватные методы

Метод Описание
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.

Описание методов

CalculateFrequency() публичный статический Метод

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.
Результат float

CalculatePreScale() публичный статический Метод

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
Результат byte

Clear() публичный Метод

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
Результат void

Dispose() защищенный Метод

DisposableObject.Dispose(bool).
protected Dispose ( bool disposing ) : void
disposing bool
Результат void

GetChannelAddress() публичный статический Метод

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.
Результат byte

ReadAll() публичный Метод

Reads all values from the device and updates properties.
public ReadAll ( ) : void
Результат void

ReadAllChannels() защищенный Метод

Reads all channels and updates Channels.
protected ReadAllChannels ( ) : void
Результат void

ReadChannel() публичный Метод

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).
Результат NxpPca9685Channel

ReadChannelOff() публичный Метод

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).
Результат int

ReadChannelOn() публичный Метод

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).
Результат int

ReadFrequency() публичный Метод

Reads the pre-scale register and calculates the Frequency (and related properties) based on ClockSpeed.
public ReadFrequency ( ) : float
Результат float

ReadMode1() публичный Метод

Reads the current value of the NxpPca9685Register.Mode1 register.
public ReadMode1 ( ) : NxpPca9685Mode1Bits
Результат NxpPca9685Mode1Bits

ReadMode2() публичный Метод

Reads the current value of the NxpPca9685Register.Mode2 register.
public ReadMode2 ( ) : NxpPca9685Mode2Bits
Результат NxpPca9685Mode2Bits

Restart() публичный Метод

Restarts the device with default options, then updates all properties.
public Restart ( ) : void
Результат void

Restart() публичный Метод

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. ///
Результат void

Sleep() публичный Метод

Enters sleep mode.
Sets the NxpPca9685Register.Mode1 register NxpPca9685Mode1Bits.Sleep bit then waits for ModeSwitchDelay to allow the oscillator to stop.
public Sleep ( ) : bool
Результат bool

Wake() публичный Метод

Leaves sleep mode.
Clears the NxpPca9685Register.Mode1 register NxpPca9685Mode1Bits.Sleep bit then waits for ModeSwitchDelay to allow the oscillator to start.
public Wake ( ) : bool
Результат bool

WriteChannel() публичный Метод

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.
Результат NxpPca9685Channel

WriteChannelLength() публичный Метод

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.
Результат NxpPca9685Channel

WriteChannelMilliseconds() публичный Метод

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).
Результат NxpPca9685Channel

WriteChannelOff() публичный Метод

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-.
Результат void

WriteChannelOn() публичный Метод

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-.
Результат void

WriteFrequency() публичный Метод

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.
Результат float