/// <summary> /// Creates an initialized instance. /// </summary> /// <param name="frequency"> /// <see cref="NxpPca9685Device.Frequency"/> for important information. /// Use <see cref="ServoFrequencyDefault"/> to support most analog servos. /// </param> /// <param name="clear">Clears all LED/PWM values.</param> /// <param name="restart"> /// Set true to restart the device which also enables the osciallator. /// When false, you have to call <see cref="NxpPca9685Device.Wake"/> or <see cref="Restart"/> later to enable the oscillator. /// </param> /// <param name="enable"> /// Set true to enable output, or false to continue with further initialization before enabling output. /// When false, you have to set it later before any output can occur. /// Defaults to false to prevent unexpected behaviour from damaging hardware. /// </param> public static NavioLedPwmDevice Initialize(float frequency, bool clear = true, bool restart = true, bool enable = false) { // Connect to I2C device var device = NavioHardwareProvider.ConnectI2c(I2cControllerIndex, I2cAddress, true, true); if (device == null) { // Initialization error throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.Strings.I2cErrorDeviceNotFound, I2cAddress, I2cControllerIndex)); } // Perform device initialization sequence... var navioDevice = new NavioLedPwmDevice(device); navioDevice.OutputEnabled = false; // Disable output navioDevice.WriteFrequency(frequency); // Set frequency if (clear) { navioDevice.Clear(); // Clear LED/PWM values when specified } if (restart) { navioDevice.Restart(); // Restart when specified } if (enable) { navioDevice.OutputEnabled = true; // Enable output when specified } // Return initialized device return(navioDevice); }
/// <summary> /// Creates an initialized instance. /// </summary> /// <param name="frequency"> /// <see cref="NxpPca9685Device.Frequency"/> for important information. /// Use <see cref="ServoFrequencyDefault"/> to support most analog servos. /// </param> /// <param name="clear">Clears all LED/PWM values.</param> /// <param name="restart"> /// Set true to restart the device which also enables the osciallator. /// When false, you have to call <see cref="NxpPca9685Device.Wake"/> or <see cref="Restart"/> later to enable the oscillator. /// </param> /// <param name="enable"> /// Set true to enable output, or false to continue with further initialization before enabling output. /// When false, you have to set it later before any output can occur. /// Defaults to false to prevent unexpected behaviour from damaging hardware. /// </param> public static NavioLedPwmDevice Initialize(float frequency, bool clear = true, bool restart = true, bool enable = false) { // Connect to I2C device var device = NavioHardwareProvider.ConnectI2c(I2cControllerIndex, I2cAddress); if (device == null) { // Initialization error throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.Strings.I2cErrorDeviceNotFound, I2cAddress, I2cControllerIndex)); } // Perform device initialization sequence... var navioDevice = new NavioLedPwmDevice(device); navioDevice.OutputEnabled = false; // Disable output navioDevice.WriteFrequency(frequency); // Set frequency if (clear) navioDevice.Clear(); // Clear LED/PWM values when specified if (restart) navioDevice.Restart(); // Restart when specified if (enable) navioDevice.OutputEnabled = true; // Enable output when specified // Return initialized device return navioDevice; }