/// <summary> The method called when data value has been changed. </summary> protected override void ValueChanged() { if (Mode == wclWeDoRgbLightMode.lmAbsolute) { Color NewColor; if (!GetColorFromByteArray(Value, out NewColor)) { return; } if (NewColor.Equals(FColor)) { return; } FColor = NewColor; DoColorChanged(); } else { if (Mode == wclWeDoRgbLightMode.lmDiscrete) { wclWeDoColor NewColorIndex = (wclWeDoColor)AsInteger; if (NewColorIndex != FColorIndex) { FColorIndex = NewColorIndex; DoColorChanged(); } } } }
/// <summary> Sets the index of the currently selected color (discrete mode). </summary> /// <param name="Index"> The color index. </param> /// <returns> If the method completed with success the returning value is /// <see cref="wclErrors.WCL_E_SUCCESS" />. If the method failed the returning value is /// one of the Bluetooth Framework error code. </returns> public Int32 SetColorIndex(wclWeDoColor Index) { if (!Attached) { return(wclBluetoothErrors.WCL_E_BLUETOOTH_DEVICE_NOT_INSTALLED); } if (Mode != wclWeDoRgbLightMode.lmDiscrete) { return(wclErrors.WCL_E_INVALID_ARGUMENT); } FColorIndex = Index; return(Hub.Io.WriteColorIndex((Byte)Index, ConnectionId)); }
/// <summary> Creates new RGB light device object. </summary> /// <param name="Hub"> The Hub object that owns the device. If this parameter is <c>null</c> /// the <seealso cref="wclEInvalidArgument"/> exception raises. </param> /// <param name="ConnectionId"> The device's Connection ID. </param> /// <seealso cref="wclWeDoHub"/> /// <exception cref="wclEInvalidArgument"> The exception raises when the <c>Hub</c> /// parameter is <c>null</c>. </exception> public wclWeDoRgbLight(wclWeDoHub Hub, Byte ConnectionId) : base(Hub, ConnectionId) { AddValidDataFormat(new wclWeDoDataFormat(1, 1, (Byte)wclWeDoRgbLightMode.lmDiscrete, wclWeDoSensorDataUnit.suRaw)); AddValidDataFormat(new wclWeDoDataFormat(1, 1, (Byte)wclWeDoRgbLightMode.lmDiscrete, wclWeDoSensorDataUnit.suPercentage)); AddValidDataFormat(new wclWeDoDataFormat(1, 4, (Byte)wclWeDoRgbLightMode.lmDiscrete, wclWeDoSensorDataUnit.suSi)); AddValidDataFormat(new wclWeDoDataFormat(3, 1, (Byte)wclWeDoRgbLightMode.lmAbsolute, wclWeDoSensorDataUnit.suRaw)); AddValidDataFormat(new wclWeDoDataFormat(3, 1, (Byte)wclWeDoRgbLightMode.lmAbsolute, wclWeDoSensorDataUnit.suPercentage)); AddValidDataFormat(new wclWeDoDataFormat(3, 4, (Byte)wclWeDoRgbLightMode.lmAbsolute, wclWeDoSensorDataUnit.suSi)); DefaultInputFormat = new wclWeDoInputFormat(ConnectionId, wclWeDoIoDeviceType.iodRgb, (Byte)wclWeDoRgbLightMode.lmDiscrete, 1, wclWeDoSensorDataUnit.suRaw, true, 0, 1); FColor = DefaultColor; FColorIndex = DefaultColorIndex; OnColorChanged = null; OnModeChanged = null; }