Пример #1
0
        /// <summary>
        /// Creates a data message from raw message data, starting at a given offset in the raw data.
        /// </summary>
        /// <param name="rawMessage">The raw message data.</param>
        /// <param name="start">The index the recreation of the data message should be started at.</param>
        /// <returns>A data message of correct type, recreated from the raw data.</returns>
        public static DataMessage CreateFromRawMessage(byte[] rawMessage, int start)
        {
            // result
            DataMessage result = null;

            // inspect type
            var dataType = (DataType)BitConverter.ToInt32(rawMessage, start + 1);

            // simple switch here
            switch (dataType)
            {
                case DataType.ControllerInfo:
                    result = new ControllerInfoData();
                    break;
                case DataType.Accelerometer:
                    result = new AccelerometerData();
                    break;
                case DataType.Compass:
                    result = new CompassData();
                    break;
                case DataType.Gyroscope:
                    result = new GyroscopeData();
                    break;
                case DataType.Motion:
                    result = new MotionData();
                    break;
                case DataType.Touch:
                    result = new TouchData();
                    break;
                case DataType.Tap:
                    result = new TapData();
                    break;
                case DataType.DoubleTap:
                    result = new DoubleTapData();
                    break;
                case DataType.Hold:
                    result = new HoldData();
                    break;
                case DataType.Flick:
                    result = new FlickData();
                    break;
                case DataType.FreeDrag:
                    result = new FreeDragData();
                    break;
                case DataType.HorizontalDrag:
                    result = new HorizontalDragData();
                    break;
                case DataType.VerticalDrag:
                    result = new VerticalDragData();
                    break;
                case DataType.DragComplete:
                    result = new DragCompleteData();
                    break;
                case DataType.CustomDrag:
                    result = new CustomDragData();
                    break;
                case DataType.CustomDragComplete:
                    result = new CustomDragCompleteData();
                    break;
                case DataType.Pinch:
                    result = new PinchData();
                    break;
                case DataType.PinchComplete:
                    result = new PinchCompleteData();
                    break;
                case DataType.Text:
                    result = new TextData();
                    break;
            }

            // fill from raw data
            if (result != null)
            {
                result.FromByteArray(rawMessage, start);
            }
            else
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }

            return result;
        }
Пример #2
0
        /// <summary>
        /// Gets capabilities information about the device used for data acquisition.
        /// </summary>
        /// <returns>
        /// A <c>ControllerInfoData</c> object that contains the capabilities information of the device.
        /// </returns>
        public ControllerInfoData GetControllerInfoData()
        {
            _logger.Trace("Creating and returning information about the controller capabilities");

            // create info
            var data = new ControllerInfoData();
            data.ClientVersion = Constants.ControllerVersion;

            // add device caps
            data.IsTouchSupported = true; // touch is supported on all devices
            data.IsAccelerometerSupported = Accelerometer.IsSupported;
            data.IsCompassSupported = Compass.IsSupported;
            data.IsGyroscopeSupported = Gyroscope.IsSupported;
            data.IsMotionSupported = Motion.IsSupported;

            // we want the logical dimensions that are valid for landscape mode
            data.DisplayWidth = DeviceInfo.Current.LogicalScreenWidth;
            data.DisplayHeight = DeviceInfo.Current.LogicalScreenHeight;

            return data;
        }