/// <summary> /// Writes the "on" and "off" values of a channel together, and updates it in <see cref="Channels"/>. /// </summary> /// <param name="index">Zero based channel number (0-15) or 16 for the "all call" channel.</param> /// <param name="value"><see cref="NxpPca9685ChannelValue"/> to write.</param> /// <returns> /// Updated channel value or null when all channels were updated. /// </returns> public NxpPca9685Channel WriteChannel(int index, NxpPca9685ChannelValue value) { // Validate if (index <0 | index> ChannelCount) { throw new ArgumentOutOfRangeException(nameof(index)); } // Validate if (value.On > NxpPca9685ChannelValue.Maximum + 1 || value.Off > NxpPca9685ChannelValue.Maximum + 1) { throw new ArgumentOutOfRangeException(nameof(value)); } // Calculate register address var register = GetChannelAddress(index); // Convert and write value var bytes = value.ToByteArray(); Hardware.WriteJoinBytes(register, bytes); // Read and return result if (index < ChannelCount) { return(ReadChannel(index)); } ReadAllChannels(); return(null); }
/// <summary> /// Writes the "on" and "off" values of a channel together, and updates it in <see cref="Channels"/>. /// </summary> /// <param name="index">Zero based channel number (0-15) or 16 for the "all call" channel.</param> /// <param name="value"><see cref="NxpPca9685ChannelValue"/> to write.</param> /// <returns> /// Updated channel value or null when all channels were updated. /// </returns> public NxpPca9685Channel WriteChannel(int index, NxpPca9685ChannelValue value) { // Validate if (index < 0 | index > ChannelCount) throw new ArgumentOutOfRangeException(nameof(index)); // Validate if (value.On > NxpPca9685ChannelValue.Maximum + 1 || value.Off > NxpPca9685ChannelValue.Maximum + 1) throw new ArgumentOutOfRangeException(nameof(value)); // Calculate register address var register = GetChannelAddress(index); // Convert and write value var bytes = value.ToByteArray(); Hardware.WriteJoinBytes(register, bytes); // Read and return result if (index < ChannelCount) return ReadChannel(index); ReadAllChannels(); return null; }