Exemple #1
0
        /// <summary> Creates new voltage sensor 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 wclWeDoVoltageSensor(wclWeDoHub Hub, Byte ConnectionId)
            : base(Hub, ConnectionId)
        {
            DefaultInputFormat = new wclWeDoInputFormat(ConnectionId, wclWeDoIoDeviceType.iodVoltageSensor, 0, 30,
                                                        wclWeDoSensorDataUnit.suSi, true, 0, 1);

            OnVoltageChanged = null;
        }
Exemple #2
0
        /// <summary> Creates new color sensor 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 wclWeDoColorSensor(wclWeDoHub Hub, Byte ConnectionId)
            : base(Hub, ConnectionId)
        {
            AddValidDataFormat(new wclWeDoDataFormat(1, 1, 0, wclWeDoSensorDataUnit.suRaw));

            DefaultInputFormat = new wclWeDoInputFormat(ConnectionId, wclWeDoIoDeviceType.iodColorSensor,
                                                        0, 1, wclWeDoSensorDataUnit.suRaw, true, 0, 1);

            OnColorDetected = null;
        }
Exemple #3
0
 // The method called by IO Service when Input Format has been updated.
 internal void UpdateInputFormat(wclWeDoInputFormat Format)
 {
     if (FInputFormat == null || (Format != FInputFormat && FConnectionId == Format.ConnectionId))
     {
         wclWeDoInputFormat OldFormat = FInputFormat;
         FInputFormat = Format;
         InputFormatChanged(OldFormat);
         SendReadValueRequest();
     }
 }
Exemple #4
0
 private wclWeDoDataFormat DataFormatForInputFormat(wclWeDoInputFormat InputFormat)
 {
     foreach (wclWeDoDataFormat DataFormat in FValidDataFormats)
     {
         if (DataFormat.Mode == InputFormat.Mode && DataFormat.Unit == InputFormat.Unit)
         {
             if ((DataFormat.DataSetCount * DataFormat.DataSetSize) != InputFormat.NumberOfBytes)
             {
                 return(null);
             }
             return(DataFormat);
         }
     }
     return(null);
 }
Exemple #5
0
        private void InputFormatChanged(Byte[] Data)
        {
            wclWeDoInputFormat Format = wclWeDoInputFormat.FromBytesArray(Data);

            if (Format == null)
            {
                return;
            }

            // If we already have input format with an earlier revision, delete all those
            // as all known formats must have the same version.
            wclWeDoInputFormat AnyFormat = FInputFormats.Values.FirstOrDefault();

            // Clear if revisions are not equal.
            if (AnyFormat != null && AnyFormat.Revision != Format.Revision)
            {
                FInputFormats.Clear();
            }

            // Update input formats in local list.
            if (FInputFormats.ContainsKey(Format.ConnectionId))
            {
                FInputFormats[Format.ConnectionId] = Format;
            }
            else
            {
                FInputFormats.Add(Format.ConnectionId, Format);
            }

            // Check for missing Input Formats.
            if (FMissingInputFormats.ContainsKey(Format.ConnectionId))
            {
                FMissingInputFormats[Format.ConnectionId] = false;
            }
            else
            {
                FMissingInputFormats.Add(Format.ConnectionId, false);
            }

            // Update Input format for IOs.
            foreach (wclWeDoIo Io in Hub.IoDevices)
            {
                if (Io.ConnectionId == Format.ConnectionId)
                {
                    Io.UpdateInputFormat(Format);
                }
            }
        }
Exemple #6
0
 /// <summary> The method called when Input Format has been changed. </summary>
 /// <param name="OldFormat"> The old Input Format. </param>
 protected override void InputFormatChanged(wclWeDoInputFormat OldFormat)
 {
     if (InputFormat != null)
     {
         if (OldFormat == null)
         {
             DoModeChanged();
         }
         else
         {
             if (InputFormat.Mode != OldFormat.Mode)
             {
                 DoModeChanged();
             }
         }
     }
 }
Exemple #7
0
        /// <summary> Creates new motion sensor 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 wclWeDoMotionSensor(wclWeDoHub Hub, Byte ConnectionId)
            : base(Hub, ConnectionId)
        {
            FCount    = 0;
            FDistance = 0;

            AddValidDataFormat(new wclWeDoDataFormat(1, 1, (Byte)wclWeDoMotionSensorMode.mmDetect, wclWeDoSensorDataUnit.suRaw));
            AddValidDataFormat(new wclWeDoDataFormat(1, 1, (Byte)wclWeDoMotionSensorMode.mmDetect, wclWeDoSensorDataUnit.suPercentage));
            AddValidDataFormat(new wclWeDoDataFormat(1, 4, (Byte)wclWeDoMotionSensorMode.mmDetect, wclWeDoSensorDataUnit.suSi));
            AddValidDataFormat(new wclWeDoDataFormat(1, 4, (Byte)wclWeDoMotionSensorMode.mmCount, wclWeDoSensorDataUnit.suRaw));
            AddValidDataFormat(new wclWeDoDataFormat(1, 1, (Byte)wclWeDoMotionSensorMode.mmCount, wclWeDoSensorDataUnit.suPercentage));
            AddValidDataFormat(new wclWeDoDataFormat(1, 4, (Byte)wclWeDoMotionSensorMode.mmCount, wclWeDoSensorDataUnit.suSi));

            DefaultInputFormat = new wclWeDoInputFormat(ConnectionId, wclWeDoIoDeviceType.iodMotionSensor, 0, 1,
                                                        wclWeDoSensorDataUnit.suRaw, true, 0, 4);

            OnCountChanged    = null;
            OnDistanceChanged = null;
            OnModeChanged     = null;
        }
Exemple #8
0
        /// <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;
        }
Exemple #9
0
        /// <summary> Compares two Input Formats. </summary>
        /// <param name="obj"> The other object to be compared with current. </param>
        /// <returns> <c>True</c> if this input format is equal to <c>obj</c>.
        ///   <c>False</c> otherwise. </returns>
        public override Boolean Equals(Object obj)
        {
            if (ReferenceEquals(obj, null))
            {
                return(false);
            }
            if (ReferenceEquals(this, obj))
            {
                return(true);
            }
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }

            wclWeDoInputFormat Format = (wclWeDoInputFormat)obj;

            return(FConnectionId == Format.ConnectionId && FInterval == Format.Interval &&
                   FMode == Format.Mode && FNotificationsEnabled == Format.NotificationsEnabled &&
                   FNumberOfBytes == Format.NumberOfBytes && FRevision == Format.Revision &&
                   FDeviceType == Format.DeviceType && FUnit == Format.Unit);
        }
Exemple #10
0
        /// <summary> Creates new IO 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 wclWeDoIo(wclWeDoHub Hub, Byte ConnectionId)
        {
            if (Hub == null)
            {
                throw new wclEInvalidArgument("Hub parameter can not be null.");
            }

            FAttached           = true; // It is always attached on creation!
            FConnectionId       = ConnectionId;
            FDataFormats        = new List <wclWeDoDataFormat>();
            FDefaultInputFormat = null;
            FDeviceType         = wclWeDoIoDeviceType.iodUnknown;
            FFirmwareVersion    = new wclWeDoVersion();
            FHardwareVersion    = new wclWeDoVersion();
            FHub                  = Hub;
            FInputFormat          = null;
            FInternal             = true;
            FPortId               = 0;
            FNumbersFromValueData = new List <Byte[]>();
            FValidDataFormats     = new List <wclWeDoDataFormat>();
            FValue                = null;
        }
Exemple #11
0
        /// <summary> Creates new tilt sensor 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 wclWeDoTiltSensor(wclWeDoHub Hub, Byte ConnectionId)
            : base(Hub, ConnectionId)
        {
            AddValidDataFormat(new wclWeDoDataFormat(2, 1, (Byte)wclWeDoTiltSensorMode.tmAngle, wclWeDoSensorDataUnit.suRaw));
            AddValidDataFormat(new wclWeDoDataFormat(2, 1, (Byte)wclWeDoTiltSensorMode.tmAngle, wclWeDoSensorDataUnit.suPercentage));
            AddValidDataFormat(new wclWeDoDataFormat(2, 4, (Byte)wclWeDoTiltSensorMode.tmAngle, wclWeDoSensorDataUnit.suSi));

            AddValidDataFormat(new wclWeDoDataFormat(1, 1, (Byte)wclWeDoTiltSensorMode.tmTilt, wclWeDoSensorDataUnit.suRaw));
            AddValidDataFormat(new wclWeDoDataFormat(1, 1, (Byte)wclWeDoTiltSensorMode.tmTilt, wclWeDoSensorDataUnit.suPercentage));
            AddValidDataFormat(new wclWeDoDataFormat(1, 4, (Byte)wclWeDoTiltSensorMode.tmTilt, wclWeDoSensorDataUnit.suSi));

            AddValidDataFormat(new wclWeDoDataFormat(3, 1, (Byte)wclWeDoTiltSensorMode.tmCrash, wclWeDoSensorDataUnit.suRaw));
            AddValidDataFormat(new wclWeDoDataFormat(3, 1, (Byte)wclWeDoTiltSensorMode.tmCrash, wclWeDoSensorDataUnit.suPercentage));
            AddValidDataFormat(new wclWeDoDataFormat(3, 4, (Byte)wclWeDoTiltSensorMode.tmCrash, wclWeDoSensorDataUnit.suSi));

            DefaultInputFormat = new wclWeDoInputFormat(ConnectionId, wclWeDoIoDeviceType.iodTiltSensor,
                                                        (Byte)wclWeDoTiltSensorMode.tmTilt, 1, wclWeDoSensorDataUnit.suRaw, true, 0, 1);

            OnAngleChanged     = null;
            OnCrashChanged     = null;
            OnDirectionChanged = null;
            OnModeChanged      = null;
        }
Exemple #12
0
 private Int32 SetDefaultInputFormat(wclWeDoInputFormat Format)
 {
     FDefaultInputFormat = Format;
     return(SendInputFormat(Format));
 }
Exemple #13
0
 /// <summary> The method called when Input Format has been changed. </summary>
 /// <param name="OldFormat"> The old Input Format. </param>
 /// <remarks> A derived class must override this method to get notifications about
 ///   format changes. </remarks>
 protected virtual void InputFormatChanged(wclWeDoInputFormat OldFormat)
 {
     // Do nothing
 }
Exemple #14
0
 /// <summary> Send an updated input format for this service to the device. </summary>
 /// <param name="Format"> New input format. </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>
 /// <seelso cref="wclWeDoInputFormat"/>
 protected Int32 SendInputFormat(wclWeDoInputFormat Format)
 {
     return(FHub.Io.WriteInputFormat(Format, FConnectionId));
 }
Exemple #15
0
 internal Int32 WriteInputFormat(wclWeDoInputFormat Format, Byte ConnectionId)
 {
     Byte[] Cmd = ComposeInputCommand(IN_CMD_ID_INPUT_FORMAT, IN_CMD_TYPE_WRITE, ConnectionId,
                                      Format.ToBytesArray());
     return(WriteInputCommand(Cmd));
 }