示例#1
0
        public void SetReportType(InputReport type, IRSensitivity irSensitivity, bool continuous)
        {
            if (!_Connected)
            {
                return;
            }

            switch (type)
            {
            case InputReport.IRAccel:
                EnableIR(IRMode.Extended, irSensitivity);
                break;

            default:
                DisableIR();
                break;
            }

            ClearReport();
            _Buff[0] = (byte)OutputReport.Type;
            _Buff[1] = (byte)((continuous ? 0x04 : 0x00) | (byte)(_WiiMoteState.Rumble ? 0x01 : 0x00));
            _Buff[2] = (byte)type;

            CHIDAPI.Write(_Handle, _Buff);
        }
        /// <summary>
        /// Callback for above. Care with this as it will be called on the background thread from the async read
        /// </summary>
        /// <param name="iResult">Async result parameter</param>
        protected void ReadCompleted(IAsyncResult iResult)
        {
            if (m_iFile == null)
            {
                return;
            }

            byte[] arrBuff = (byte[])iResult.AsyncState;
            try
            {
                m_iFile.EndRead(iResult);
                try
                {
                    InputReport oInRep = CreateInputReport();
                    oInRep.SetData(arrBuff);
                    HandleDataReceived(oInRep);
                }
                finally
                {
                    BeginAsyncRead();
                }
            }
            catch (IOException ex)
            {
                HandleDeviceRemoved();
                OnDeviceRemoved?.Invoke(this, new EventArgs());
                Dispose();
            }
        }
示例#3
0
 protected byte[] SendAndReturnReport(InputReport returnReportType, TimeSpan timeout)
 {
     byte[] report = null;
     using (IReportInterceptor reportInterceptor = CreateReportInterceptor())
     {
         SendReport();
         DateTime start = DateTime.Now;
         while ((report = reportInterceptor.Intercept()) != null)
         {
             if (report[0] == (byte)returnReportType)
             {
                 break;
             }
             if (DateTime.Now - start > timeout)
             {
                 report = null;
                 break;
             }
         }
     }
     if (report == null)
     {
         throw new TimeoutException("Could not retrieve result-report.");
     }
     return(report);
 }
示例#4
0
        /// <summary>
        /// Set Wiimote reporting mode
        /// </summary>
        /// <param name="type">Report type</param>
        /// <param name="continuous">Continuous data</param>
        public void SetReportType(InputReport type, bool continuous)
        {
            mReportType = type;

            switch (type)
            {
            case InputReport.IRAccel:
                EnableIR(IRMode.Extended);
                break;

            case InputReport.IRExtensionAccel:
                EnableIR(IRMode.Basic);
                break;

            default:
                DisableIR();
                break;
            }

            ClearReport();
            mBuff[0] = (byte)OutputReport.Type;
            mBuff[1] = (byte)((continuous ? 0x04 : 0x00) | (byte)(mWiimoteState.Rumble ? 0x01 : 0x00));
            mBuff[2] = (byte)type;

            WriteReport();
        }
示例#5
0
        public void Update(byte[] data)
        {
            InputReport reportType = (InputReport)data[0];

            if (Utils.ReportContainsCoreButtons(reportType))
            {
                buttons.Parse(data, 1);
            }

            if (Utils.ReportContainsAccelerometer(reportType))
            {
                accelerometer.Parse(data, 3);
            }

            if (reportType == InputReport.BtnsAccIR || reportType == InputReport.BtnsAccIRExt)
            {
                irSensor.Parse(data, 6);
            }
            else if (reportType == InputReport.BtnsIRExt)
            {
                irSensor.Parse(data, 3);
            }

            accelerometer.Normalize();
        }
        public bool OnEvent(BaseEvent ev)
        {
            InputReport inputReport = (InputReport)null;
            InputDevice inputDevice = (InputDevice)null;
            TouchEvent  touchEvent;

            if ((touchEvent = ev as TouchEvent) != null)
            {
                UIElement target = TouchCapture.Captured;
                if (target != null && touchEvent.EventMessage == (byte)1)
                {
                    int x1 = 0;
                    int y1 = 0;
                    int x2 = touchEvent.Touches[0].X;
                    int y2 = touchEvent.Touches[0].Y;
                    target.PointToScreen(ref x1, ref y1);
                    int width;
                    int height;
                    target.GetRenderSize(out width, out height);
                    if ((x1 > x2 || x2 > x1 + width || (y1 > y2 || y2 > y1 + height)) && (x2 <= (int)this.display.ActiveSettings.Width && y2 <= (int)this.display.ActiveSettings.Height))
                    {
                        target = (UIElement)null;
                    }
                }
                if (target == null)
                {
                    target = WindowManager.Instance.GetPointerTarget(touchEvent.Touches[0].X, touchEvent.Touches[0].Y);
                }
                if (target != null)
                {
                    Application._inputManager.TouchDevice.SetTarget(target);
                }
                else
                {
                    Application._inputManager.TouchDevice.SetTarget((UIElement)this.MainWindow);
                }
                inputReport = (InputReport) new RawTouchInputReport((PresentationSource)null, touchEvent.Time, touchEvent.EventMessage, touchEvent.Touches);
                inputDevice = (InputDevice)Application._inputManager._touchDevice;
            }
            else
            {
                GenericEvent genericEvent;
                if ((genericEvent = ev as GenericEvent) != null)
                {
                    UIElement target = TouchCapture.Captured ?? WindowManager.Instance.GetPointerTarget(genericEvent.X, genericEvent.Y);
                    if (target != null)
                    {
                        Application._inputManager.GenericDevice.SetTarget(target);
                    }
                    else
                    {
                        Application._inputManager.GenericDevice.SetTarget((UIElement)this.MainWindow);
                    }
                    inputReport = (InputReport) new RawGenericInputReport((PresentationSource)null, genericEvent);
                    inputDevice = (InputDevice)Application._inputManager._genericDevice;
                }
            }
            this.Dispatcher.BeginInvoke(Application._reportInputMethod, (object)new InputReportArgs((object)inputDevice, (object)inputReport));
            return(true);
        }
示例#7
0
        internal static int GetExtensionOffset(InputReport reportType)
        {
            switch (reportType)
            {
            case InputReport.BtnsExt:
            case InputReport.BtnsExtB:
                return(3);

            case InputReport.BtnsAccExt:
                return(6);

            case InputReport.BtnsIRExt:
                return(13);

            case InputReport.BtnsAccIRExt:
                return(16);

            case InputReport.ExtOnly:
                return(1);

            // No other reports send extension bytes
            default:
                return(-1);
            }
        }
示例#8
0
 protected override void HandleDataReceived(InputReport oInRep)
 {
     if (DataRecieved != null)
     {
         SpecifiedInputReport report = (SpecifiedInputReport)oInRep;
         DataRecieved(this, new DataRecievedEventArgs(report.Data));
     }
 }
示例#9
0
文件: HID.cs 项目: levi1994/LitDev
 protected override void HandleDataReceived(InputReport oInRep)
 {
     if (OnDeviceChanged != null)
     {
         HIDInputReport oHIDIn = (HIDInputReport)oInRep;
         OnDeviceChanged(this, new HIDChangedEventArgs(oHIDIn));
     }
 }
示例#10
0
        /// <summary>
        /// Parse IR sensor data
        /// </summary>
        /// <param name="input"></param>
        /// <param name="offset"></param>
        public void Parse(byte[] input, int offset = 0)
        {
            InputReport type = (InputReport)input[0];

            if (type == InputReport.BtnsAccIR || type == InputReport.BtnsAccIRExt)
            {
                offset += 3;
            }
            else if (type != InputReport.BtnsIRExt)
            {
                return;
            }

            point1.rawX = input[offset] | ((input[offset + 2] >> 4) & 0x03) << 8;
            point1.rawY = input[offset + 1] | ((input[offset + 2] >> 6) & 0x03) << 8;

            if (type == InputReport.BtnsAccIR)
            {
                // Extended Mode
                point2.rawX = input[offset + 3] | ((input[offset + 5] >> 4) & 0x03) << 8;
                point2.rawY = input[offset + 4] | ((input[offset + 5] >> 6) & 0x03) << 8;
                point3.rawX = input[offset + 6] | ((input[offset + 8] >> 4) & 0x03) << 8;
                point3.rawY = input[offset + 7] | ((input[offset + 8] >> 6) & 0x03) << 8;
                point4.rawX = input[offset + 9] | ((input[offset + 11] >> 4) & 0x03) << 8;
                point4.rawY = input[offset + 10] | ((input[offset + 11] >> 6) & 0x03) << 8;

                point1.size = input[offset + 2] & 0x0F;
                point2.size = input[offset + 5] & 0x0F;
                point3.size = input[offset + 8] & 0x0F;
                point4.size = input[offset + 11] & 0x0F;

                point1.visible = !(input[offset] == 0xFF && input[offset + 1] == 0xFF && input[offset + 2] == 0xFF);
                point2.visible = !(input[offset + 3] == 0xFF && input[offset + 4] == 0xFF && input[offset + 5] == 0xFF);
                point3.visible = !(input[offset + 6] == 0xFF && input[offset + 7] == 0xFF && input[offset + 8] == 0xFF);
                point4.visible = !(input[offset + 9] == 0xFF && input[offset + 10] == 0xFF && input[offset + 11] == 0xFF);
            }
            else
            {
                // Basic Mode
                point2.rawX = input[offset + 3] | ((input[offset + 2] >> 0) & 0x03) << 8;
                point2.rawY = input[offset + 4] | ((input[offset + 2] >> 2) & 0x03) << 8;
                point3.rawX = input[offset + 5] | ((input[offset + 7] >> 4) & 0x03) << 8;
                point3.rawY = input[offset + 6] | ((input[offset + 7] >> 6) & 0x03) << 8;
                point4.rawX = input[offset + 8] | ((input[offset + 7] >> 0) & 0x03) << 8;
                point4.rawY = input[offset + 9] | ((input[offset + 7] >> 2) & 0x03) << 8;

                point1.size = 0x00;
                point2.size = 0x00;
                point3.size = 0x00;
                point4.size = 0x00;

                point1.visible = !(input[offset] == 0xFF && input[offset + 1] == 0xFF);
                point2.visible = !(input[offset + 3] == 0xFF && input[offset + 4] == 0xFF);
                point3.visible = !(input[offset + 5] == 0xFF && input[offset + 6] == 0xFF);
                point4.visible = !(input[offset + 8] == 0xFF && input[offset + 9] == 0xFF);
            }
        }
示例#11
0
        internal static bool ReportContainsAccelerometer(InputReport reportType)
        {
            switch (reportType)
            {
            case InputReport.BtnsAcc:
            case InputReport.BtnsAccExt:
            case InputReport.BtnsAccIR:
            case InputReport.BtnsAccIRExt:
                return(true);

            default:
                return(false);
            }
        }
示例#12
0
        protected override void ParseHidReport(byte[] report)
        {
            if (report[1] != 0x01)
            {
                return;
            }

            PacketCounter++;

            #region HID Report translation

            // no battery state since the Gamepad is USB-powered
            m_BatteryStatus = InputReport.SetBatteryStatus(DsBattery.None);

            // packet counter
            InputReport.PacketCounter = PacketCounter;

            // set fake MAC address
            InputReport.PadMacAddress = PhysicalAddress.Parse(m_Mac.Replace(":", string.Empty));

            // reset buttons
            InputReport.ZeroSelectStartButtonsState();
            InputReport.ZeroShoulderButtonsState();

            InputReport.Set(Ds3Button.Select, IsBitSet(report[7], 4));   // Select
            InputReport.Set(Ds3Button.Start, IsBitSet(report[7], 5));    // Start

            InputReport.Set(Ds3Button.L1, IsBitSet(report[7], 0));       // L1 (button)
            InputReport.Set(Ds3Button.R1, IsBitSet(report[7], 2));       // R1 (button)

            InputReport.Set(Ds3Button.Triangle, IsBitSet(report[6], 4)); // Triangle (button)
            InputReport.Set(Ds3Button.Circle, IsBitSet(report[6], 5));   // Circle (button)
            InputReport.Set(Ds3Button.Cross, IsBitSet(report[6], 6));    // Cross (button)
            InputReport.Set(Ds3Button.Square, IsBitSet(report[6], 7));   // Square (button)

            InputReport.Set(Ds3Button.Right, (report[4] == 0xFF));       // D-Pad right
            InputReport.Set(Ds3Button.Left, (report[4] == 0x00));        // D-Pad left
            InputReport.Set(Ds3Button.Up, (report[5] == 0x00));          // D-Pad up
            InputReport.Set(Ds3Button.Down, (report[5] == 0xFF));        // D-Pad down

            // This device has no thumb sticks, center axes
            InputReport.Set(Ds3Axis.Lx, 0x80);
            InputReport.Set(Ds3Axis.Ly, 0x80);
            InputReport.Set(Ds3Axis.Rx, 0x80);
            InputReport.Set(Ds3Axis.Ry, 0x80);

            #endregion

            OnHidReportReceived();
        }
示例#13
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            //_lastReport = buffer;
            _reportQueue.Enqueue(buffer);
            OutputReport output = (OutputReport)buffer[0];

            switch (output)
            {
            case OutputReport.StatusRequest:
                //NextReport = InputReport.Status;
                _nextQueue.Enqueue(InputReport.Status);
                RumbleByte = buffer[1];
                break;

            case OutputReport.ReadMemory:     // 21 BB BB SE AA AA DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD DD
                //if (NextReport != InputReport.ReadMem)
                if (!_nextQueue.Contains(InputReport.ReadMem))
                {
                    // Extension Step A
                    //NextReport = InputReport.ReadMem;
                    _nextQueue.Enqueue(InputReport.ReadMem);
                }
                else
                {
                    // Extension Step B
                }
                break;

            case OutputReport.LEDs:     // 11 LL
                //NextReport = InputReport.Acknowledge;
                _nextQueue.Enqueue(InputReport.Acknowledge);
                LED_1 = (buffer[1] & 0x10) != 0x00;
                LED_2 = (buffer[1] & 0x20) != 0x00;
                LED_3 = (buffer[1] & 0x30) != 0x00;
                LED_4 = (buffer[1] & 0x40) != 0x00;
                break;

            case OutputReport.DataReportMode:     // 12 TT MM
                DataReportMode = (InputReport)buffer[2];
                //if ((byte)NextReport >= 0x30)
                //{
                //    NextReport = DataReportMode;
                //}
                if (_nextQueue.Count == 0 || (byte)_nextQueue.Peek() >= 0x30)
                {
                    _nextQueue.Enqueue(DataReportMode);
                }
                break;
            }
        }
        /// <summary>
        /// Set BalanceBoard reporting mode
        /// </summary>
        /// <param name="type">Report type</param>
        /// <param name="continuous">Continuous data</param>
        internal override void SetDataReportingMode(bool continuous)
        {
            // BalanceBoard has CoreButtonsWith8Extension 0x32 ReportMode
            InputReport type = InputReport.CoreButtonsWith8Extension;

            ClearReport();

            buff[0] = (byte)OutputReport.DataReportingMode;
            buff[1] = (byte)(continuous ? 0x04 : 0x00);
            buff[2] = (byte)type;

            // Write
            if (!WriteReport())
            {
                Log("Write failed: DataReporting");
            }
        }
示例#15
0
        /// <summary>Set Wiimote reporting mode.</summary>
        /// <param name="reportType">Report type</param>
        /// <param name="irSensitivity">IR sensitivity</param>
        /// <param name="continuous">Continuous data</param>
        public void SetReportType(ReportType reportType, IRSensitivity irSensitivity, bool continuous)
        {
            InputReport         type       = (InputReport)reportType;
            DataReportAttribute dataReport =
                EnumInfo <InputReport> .TryGetAttribute <DataReportAttribute>(type);

            if (dataReport == null)
            {
                throw new WiimoteException(this, $"{type} is not a valid report type!");
            }

            int irSize = dataReport.IRSize;

            if (dataReport.IsInterleaved)
            {
                irSize *= 2;
            }

            switch (dataReport.IRSize)
            {
            case 10:
                EnableIR(IRMode.Basic, irSensitivity);
                break;

            case 12:
                EnableIR(IRMode.Extended, irSensitivity);
                break;

            case 36:
                EnableIR(IRMode.Full, irSensitivity);
                break;

            default:
                DisableIR();
                break;
            }

            byte[] buff = CreateReport(OutputReport.InputReportType);

            buff[1] = (byte)(continuous ? 0x04 : 0x00);
            buff[2] = (byte)type;

            WriteReport(buff);
            wiimoteState.ReportType       = reportType;
            wiimoteState.ContinuousReport = continuous;
        }
示例#16
0
        protected static IRMode GetIrMode(InputReport reportType)
        {
            switch (reportType)
            {
            case InputReport.ButtonsAccelerometer12Ir:
                return(IRMode.Extended);

            case InputReport.Buttons10Ir9Extension:
            case InputReport.ButtonsAccelerometer10Ir6Extension:
                return(IRMode.Basic);

            case InputReport.ButtonsAccelerometer36IrA:
            case InputReport.ButtonsAccelerometer36IrB:
                return(IRMode.Full);
            }
            return(IRMode.Off);
        }
示例#17
0
        protected override void ParseHidReport(byte[] report)
        {
            if (report[5] != 0x00)
            {
                return;
            }

            PacketCounter++;

            #region HID Report translation

            // no battery state since the Gamepad is USB-powered
            m_BatteryStatus = InputReport.SetBatteryStatus(DsBattery.None);

            // packet counter
            InputReport.PacketCounter = PacketCounter;

            InputReport.Set(Ds3Button.Triangle, IsBitSet(report[6], 4));
            InputReport.Set(Ds3Button.Circle, IsBitSet(report[6], 5));
            InputReport.Set(Ds3Button.Cross, IsBitSet(report[6], 6));
            InputReport.Set(Ds3Button.Square, IsBitSet(report[6], 7));

            InputReport.Set(Ds3Button.Select, IsBitSet(report[7], 4));
            InputReport.Set(Ds3Button.Start, IsBitSet(report[7], 5));

            InputReport.Set(Ds3Button.Up, (report[4] == 0x00));
            InputReport.Set(Ds3Button.Right, (report[3] == 0xFF));
            InputReport.Set(Ds3Button.Down, (report[4] == 0xFF));
            InputReport.Set(Ds3Button.Left, (report[3] == 0x00));

            InputReport.Set(Ds3Button.L1, IsBitSet(report[7], 0));
            InputReport.Set(Ds3Button.R1, IsBitSet(report[7], 1));
            InputReport.Set(Ds3Button.L2, IsBitSet(report[7], 2));
            InputReport.Set(Ds3Button.R2, IsBitSet(report[7], 3));

            InputReport.Set(Ds3Button.L3, IsBitSet(report[7], 6));
            InputReport.Set(Ds3Button.R3, IsBitSet(report[7], 7));

            // TODO: the PS-button is dead according to the report:
            // http://forums.pcsx2.net/attachment.php?aid=57420

            #endregion

            OnHidReportReceived();
        }
示例#18
0
        protected override void HandleDataReceived(InputReport inputReport)
        {
            var report = (InputEvent)inputReport;

            // Fire generic data received event
            if (DataRecieved != null)
            {
                if (report.EventType != EventType.Unspecified)
                {
                    var args = new MirrorEventReceivedArgs(report);
                    DataRecieved(this, args);
                }
            }
            // Fire specific events
            switch (report.EventType)
            {
            case EventType.ShowTag:
                if (TagShown != null)
                {
                    TagShown(this, new TagEventArgs(report.Data));
                }
                break;

            case EventType.HideTag:
                if (TagHid != null)
                {
                    TagHid(this, new TagEventArgs(report.Data));
                }
                break;

            case EventType.OrientationDown:
                if (OrientationChanged != null)
                {
                    OrientationChanged(this, new OrientationChangedEventArgs(Orientation.Down));
                }
                break;

            case EventType.OrientationUp:
                if (OrientationChanged != null)
                {
                    OrientationChanged(this, new OrientationChangedEventArgs(Orientation.Up));
                }
                break;
            }
        }
示例#19
0
        /// <summary>
        /// Parses core buttons based on 2 bytes from the input data.
        /// </summary>
        /// <param name="input">Byte array of controller data.</param>
        /// <param name="offset">Starting index of Core Button bytes.</param>
        public void Parse(byte[] input, int offset = 0)
        {
            InputReport type = (InputReport)input[0];

            if (type != InputReport.ExtOnly)
            {
                A     = (input[offset + 1] & 0x08) != 0;
                B     = (input[offset + 1] & 0x04) != 0;
                One   = (input[offset + 1] & 0x02) != 0;
                Two   = (input[offset + 1] & 0x01) != 0;
                Home  = (input[offset + 1] & 0x80) != 0;
                Minus = (input[offset + 1] & 0x10) != 0;
                Plus  = (input[offset + 0] & 0x10) != 0;
                Up    = (input[offset + 0] & 0x08) != 0;
                Down  = (input[offset + 0] & 0x04) != 0;
                Right = (input[offset + 0] & 0x02) != 0;
                Left  = (input[offset + 0] & 0x01) != 0;
            }
        }
示例#20
0
        /// <summary>
        /// Parses 3 byte accelerometer raw data.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="offset"></param>
        public void Parse(byte[] input, int offset = 0)
        {
            InputReport type = (InputReport)input[0];

            InputReport[] accepted = new InputReport[]
            {
                InputReport.BtnsAcc,
                InputReport.BtnsAccExt,
                InputReport.BtnsAccIR,
                InputReport.BtnsAccIRExt
            };

            if (accepted.Contains(type))
            {
                rawX = input[offset + 0];
                rawY = input[offset + 1];
                rawZ = input[offset + 2];
            }
        }
示例#21
0
        private void TestInputFeeder()
        {
            var feeder = ServiceProvider.Get <IInputFeeder>();

            try
            {
                feeder.Connect("1");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
            }

            var report = new InputReport
            {
                ButtonReport = new ButtonReport(),
                AxisReport   = new InputAxisReport
                {
                    Axis1 = new Axis(),
                    Axis2 = new Axis()
                }
            };

            try
            {
                while (true)
                {
                    report.ButtonReport.Buttons = 4;
                    feeder.Feed(report);
                    System.Threading.Thread.Sleep(20);
                    report.ButtonReport.Buttons = 0;
                    feeder.Feed(report);
                    System.Threading.Thread.Sleep(20);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
            }
            Console.ReadKey();
        }
示例#22
0
        internal static bool ReportContainsCoreButtons(InputReport reportType)
        {
            switch (reportType)
            {
            case InputReport.ReadMem:
            case InputReport.Acknowledge:
            case InputReport.BtnsOnly:
            case InputReport.BtnsAcc:
            case InputReport.BtnsExt:
            case InputReport.BtnsAccIR:
            case InputReport.BtnsExtB:
            case InputReport.BtnsAccExt:
            case InputReport.BtnsIRExt:
            case InputReport.BtnsAccIRExt:
                // 0x3E & 0x3F Also return button data but we don't use those
                return(true);

            default:
                return(false);
            }
        }
示例#23
0
        protected override bool ParseReport(byte[] report)
        {
            InputReport type = (InputReport)report[0];

            if (type == InputReport.GetStatusResult)
            {
                BatteryLevel = (report[6]);
                OnUpdated();
            }
            else if (type == InputReport.Buttons8Extension)
            {
                _Button = (report[2] & 0x08) == 0x8;

                int offset = 3;
                _TopRight    = (ushort)((report[offset + 0] << 8) | report[offset + 1]);
                _BottomRight = (ushort)((report[offset + 2] << 8) | report[offset + 3]);
                _TopLeft     = (ushort)((report[offset + 4] << 8) | report[offset + 5]);
                _BottomLeft  = (ushort)((report[offset + 6] << 8) | report[offset + 7]);
                OnUpdated();
            }
            return(true);
        }
示例#24
0
        /// <summary>
        /// Handle the given message
        /// </summary>
        /// <returns>True if handled</returns>
        protected virtual bool InputReport(InputReport msg)
        {
            // Sensor input
            var actual  = msg.SensorLevel;
            var address = msg.Address + 1; // Fixup

            log.Trace("Received: InputReport: address={0}, level={1}", address, actual);
            stateDispatcher.PostAction(() =>
            {
                var foundSensor = false;
                foreach (var sensor in cs.Sensors.Where(x => x.Entity.Address.Value == address))
                {
                    sensor.Active.Actual = actual;
                    foundSensor          = true;
                }
                if (!foundSensor)
                {
                    railwayState.OnUnknownSensor(new Address(AddressType.LocoNet, string.Empty, address));
                    log.Info(Strings.InputReportForUnknownAddress, actual.OnOff(),
                             address);
                }
            });
            return(true);
        }
示例#25
0
        /// <summary>
        /// Handle the given message
        /// </summary>
        /// <returns>True if handled</returns>
        protected virtual bool ReceiveInputReport(InputReport msg)
        {
            // Sensor input
            var actual            = msg.SensorLevel;
            var actualDir         = msg.SensorLevel ? SwitchDirection.Straight : SwitchDirection.Off;
            var invertedActualDir = msg.SensorLevel ? SwitchDirection.Off : SwitchDirection.Straight;
            var address           = msg.Address + 1; // Fixup

            log.Trace("Received: InputReport: address={0}, level={1}", address, actual);
            stateDispatcher.PostAction(() =>
            {
                var foundInput = false;
                foreach (var input in cs.Inputs.Where(x => x.Address.ValueAsInt == address))
                {
                    input.Active.Actual = actual;
                    foundInput          = true;
                }
                var foundSwitch = false;
                if (!foundInput)
                {
                    // The address does not match any of the sensors, perhaps it matches some of the switches?
                    foreach (var @switch in cs.Junctions.OfType <ISwitchState>().Where(x => x.HasFeedback && (x.FeedbackAddress.ValueAsInt == address)))
                    {
                        @switch.Direction.Actual = @switch.InvertFeedback ? invertedActualDir : actualDir;
                        foundSwitch = true;
                    }
                }
                if (!(foundInput || foundSwitch))
                {
                    railwayState.OnUnknownSensor(new Address(AddressType.LocoNet, string.Empty, address));
                    log.Info(Strings.InputReportForUnknownAddress, actual.OnOff(),
                             address);
                }
            });
            return(true);
        }
示例#26
0
        /// <summary>
        /// Set Wiimote reporting mode
        /// </summary>
        /// <param name="type">Report type</param>
        /// <param name="irSensitivity">IR sensitivity</param>
        /// <param name="continuous">Continuous data</param>
        public void SetReportType(InputReport type, IRSensitivity irSensitivity, bool continuous)
        {
            switch(type)
            {
                case InputReport.IRAccel:
                    EnableIR(IRMode.Extended, irSensitivity);
                    break;
                case InputReport.IRExtensionAccel:
                    EnableIR(IRMode.Basic, irSensitivity);
                    break;
                default:
                    DisableIR();
                    break;
            }

            ClearReport();
            mBuff[0] = (byte)OutputReport.Type;
            mBuff[1] = (byte)((continuous ? 0x04 : 0x00) | (byte)(mWiimoteState.Rumble ? 0x01 : 0x00));
            mBuff[2] = (byte)type;

            WriteReport();
        }
示例#27
0
 /// <summary>
 /// Set Wiimote reporting mode (if using an IR report type, IR sensitivity is set to WiiLevel3)
 /// </summary>
 /// <param name="type">Report type</param>
 /// <param name="continuous">Continuous data</param>
 public void SetReportType(InputReport type, bool continuous)
 {
     SetReportType(type, IRSensitivity.Maximum, continuous);
 }
示例#28
0
        public bool OnEvent(BaseEvent ev)
        {
            InputReport ir  = null;
            InputDevice dev = null;

            /// Process known events, otherwise forward as generic to MainWindow.
            ///

            TouchEvent touchEvent = ev as TouchEvent;

            if (touchEvent != null)
            {
                Microsoft.SPOT.Presentation.UIElement targetWindow = TouchCapture.Captured;

                ///
                ///  Make sure the current event's coordinates are contained in the current
                ///  stylus/touch window, if not then search for the appropriate window
                ///
                if (targetWindow != null && touchEvent.EventMessage == (byte)TouchMessages.Down)
                {
                    int x = 0, y = 0, w, h;
                    int xSrc = touchEvent.Touches[0].X;
                    int ySrc = touchEvent.Touches[0].Y;

                    targetWindow.PointToScreen(ref x, ref y);
                    targetWindow.GetRenderSize(out w, out h);

                    if (!(x <= xSrc && xSrc <= (x + w) &&
                          y <= ySrc && ySrc <= (y + h)))
                    {
                        // only look for different target window if the touch point is inside
                        // the system metrics, otherwise, it may be a touch calibration point
                        // which is translated in the application layer.
                        if (xSrc <= SystemMetrics.ScreenWidth &&
                            ySrc <= SystemMetrics.ScreenHeight)
                        {
                            targetWindow = null;
                        }
                    }
                }

                if (targetWindow == null)
                {
                    //If we can enforce that the first event in the array is always the primary touch, we don't have to
                    //search.
                    targetWindow = WindowManager.Instance.GetPointerTarget(touchEvent.Touches[0].X, touchEvent.Touches[0].Y);
                }

                if (targetWindow != null)
                {
                    _inputManager.TouchDevice.SetTarget(targetWindow);
                }
                else
                {
                    _inputManager.TouchDevice.SetTarget(MainWindow);
                }

                ir =
                    new RawTouchInputReport(
                        null,
                        touchEvent.Time,
                        touchEvent.EventMessage,
                        touchEvent.Touches
                        );

                dev = _inputManager._touchDevice;
            }
            else if (ev is GenericEvent)
            {
                GenericEvent genericEvent = (GenericEvent)ev;

                Microsoft.SPOT.Presentation.UIElement targetWindow = TouchCapture.Captured;

                if (targetWindow == null)
                {
                    targetWindow = WindowManager.Instance.GetPointerTarget(genericEvent.X, genericEvent.Y);
                }

                if (targetWindow != null)
                {
                    _inputManager.GenericDevice.SetTarget(targetWindow);
                }
                else
                {
                    _inputManager.GenericDevice.SetTarget(MainWindow);
                }

                ir = new RawGenericInputReport(
                    null,
                    genericEvent
                    );

                dev = _inputManager._genericDevice;
            }
            else
            {
                /// Unkown event.
            }

            this.Dispatcher.BeginInvoke(_reportInputMethod, new InputReportArgs(dev, ir));

            return(true);
        }
        /// <summary>
        /// Set Wiimote reporting mode
        /// </summary>
        /// <param name="type">Report type</param>
        /// <param name="irSensitivity">IR sensitivity</param>
        /// <param name="continuous">Continuous data</param>
        public void SetReportType(InputReport type, IRSensitivity irSensitivity, bool continuous)
        {
            // only 1 report type allowed for the BB
            if(mWiimoteState.ExtensionType == ExtensionType.BalanceBoard)
                type = InputReport.ButtonsExtension;

            switch(type)
            {
                case InputReport.IRAccel:
                    EnableIR(IRMode.Extended, irSensitivity);
                    break;
                case InputReport.IRExtensionAccel:
                    EnableIR(IRMode.Basic, irSensitivity);
                    break;
                default:
                    DisableIR();
                    break;
            }

            ClearReport();
            mBuff[0] = (byte)OutputReport.Type;
            mBuff[1] = (byte)((continuous ? 0x04 : 0x00) | (byte)(mWiimoteState.Rumble ? 0x01 : 0x00));
            mBuff[2] = (byte)type;

            WriteReport();
        }
示例#30
0
        public void SetReportType2(WiimoteDevice device,InputReport type, bool continuous)
        {
            byte[] mBuff = new byte[REPORT_LENGTH];

            mBuff[0] = (byte)OutputReport.Type;
            // mBuff[1] = (byte)((continuous ? 0x04 : 0x00) | (byte)(mWiimoteState.Rumble ? 0x01 : 0x00));
            mBuff[1] = (byte)((continuous ? (uint)0x04 : (uint)0x00) | (uint)device.RumbleBit);
            mBuff[2] =(byte)type;

            _hidInterface.Write(mBuff, device.ID, (suc) => { 
                _hidInterface.Read(device.ID,onRead); });
        }
示例#31
0
        public void SetReportType(InputReport type, IRSensitivity irSensitivity, bool continuous)
        {
            if (!_Connected)
                return;

            switch (type)
            {
                case InputReport.IRAccel:
                    EnableIR(IRMode.Extended, irSensitivity);
                    break;
                default:
                    DisableIR();
                    break;
            }

            ClearReport();
            _Buff[0] = (byte)OutputReport.Type;
            _Buff[1] = (byte)((continuous ? 0x04 : 0x00) | (byte)(_WiiMoteState.Rumble ? 0x01 : 0x00));
            _Buff[2] = (byte)type;

            CHIDAPI.Write(_Handle, _Buff);
        }
 /// <summary>
 /// Set Wiimote reporting mode (if using an IR report type, IR sensitivity is set to WiiLevel3)
 /// </summary>
 /// <param name="type">Report type</param>
 /// <param name="continuous">Continuous data</param>
 public void SetReportType(InputReport type, bool continuous)
 {
     Debug.WriteLine("SetReportType: " + type);
     SetReportType(type, IRSensitivity.Maximum, continuous);
 }
示例#33
0
        ///// <summary>
        ///// Returns whether rumble is currently enabled.
        ///// </summary>
        ///// <returns>Byte indicating true (0x01) or false (0x00)</returns>
        //private byte GetRumbleBit(WiimoteDevice device)
        //{
        //    //return (byte)(mWiimoteState.Rumble ? 0x01 : 0x00);
        //    return (byte)(device.Rumble ? 0x01 : 0x00);
        //}

     
        /// <summary>
        /// Set Wiimote reporting mode (if using an IR report type, IR sensitivity is set to WiiLevel3)
        /// </summary>
        /// <param name="type">Report type</param>
        /// <param name="continuous">Continuous data</param>
        void SetReportType(WiimoteDevice device, InputReport type, bool continuous)
        {
            SetReportType(device, type, IRSensitivity.Maximum, continuous);
        }
示例#34
0
        /// <summary>
        /// Set Wiimote reporting mode
        /// </summary>
        /// <param name="type">Report type</param>
        /// <param name="irSensitivity">IR sensitivity</param>
        /// <param name="continuous">Continuous data</param>
        void SetReportType(WiimoteDevice device, InputReport type, IRSensitivity irSensitivity, bool continuous)
        {
            switch (type)
            {
                case InputReport.ButtonsIRAccel:
                    EnableIR(device, IRMode.Extended, irSensitivity);
                    break;
                case InputReport.ButtonsIRExtensionAccel:
                    EnableIR(device, IRMode.Basic, irSensitivity);
                    break;
                default:
                    DisableIR(device);
                    break;
            }


            UnityEngine.Debug.Log("SyncType");

            byte[] mBuff = new byte[REPORT_LENGTH];

            mBuff[0] = (byte)OutputReport.Type;
            // mBuff[1] = (byte)((continuous ? 0x04 : 0x00) | (byte)(mWiimoteState.Rumble ? 0x01 : 0x00));
            mBuff[1] = (byte)((continuous ? (uint)0x04 : (uint)0x00) | (uint)device.RumbleBit);
            mBuff[2] = (byte)type;

            _hidInterface.Write(mBuff, device.ID);
        }
示例#35
0
 public void SetReportType(InputReport type, IRSensitivity irSensitivity, bool continuous)
 {
     long
         token1 = -1541405694;
     if (this.mWiimoteState.ExtensionType == (ExtensionType)((ulong)token1))
     {
         type = InputReport.ButtonsExtension;
     }
     InputReport inputReport = type;
     if (inputReport != InputReport.IRAccel)
     {
         if (inputReport != InputReport.IRExtensionAccel)
         {
             this.DisableIR();
         }
         else
         {
             this.EnableIR(IRMode.Basic, irSensitivity);
         }
     }
     else
     {
         this.EnableIR(IRMode.Extended, irSensitivity);
     }
     this.ClearReport();
     this.mBuff[0] = 18;
     this.mBuff[1] = (byte)((continuous ? 4 : 0) | (this.mWiimoteState.Rumble ? 1 : 0));
     this.mBuff[2] = (byte)type;
     this.WriteReport();
 }
示例#36
0
        protected override bool ParseReport(byte[] report)
        {
            if (report[0] < 0x20)
            {
                throw new InvalidOperationException("Received an output report!");
            }
            InputReport type = (InputReport)report[0];

            if (type >= InputReport.Buttons && type <= InputReport.ButtonsAccelerometer36IrB)
            {
                if (type == InputReport.ButtonsAccelerometer36IrB)
                {
                    ReportingMode = ReportingMode.ButtonsAccelerometer36Ir;
                }
                else
                {
                    ReportingMode = (ReportingMode)type;
                }

                IRMode irMode = GetIrMode(type);
                if (this._IrMode != irMode)
                {
                    for (int i = 0; i < _CachedIRBeacons.Length; i++)
                    {
                        BasicIRBeacon newBeacon = null;
                        switch (irMode)
                        {
                        case IRMode.Basic:
                            newBeacon = new BasicIRBeacon();
                            break;

                        case IRMode.Extended:
                            newBeacon = new ExtendedIRBeacon();
                            break;

                        case IRMode.Full:
                            newBeacon = new FullIRBeacon();
                            break;
                        }
                        _CachedIRBeacons[i] = newBeacon;
                        _IRBeacons[i]       = null;
                    }
                    this._IrMode = irMode;
                }
            }
            switch (type)
            {
            case InputReport.Buttons:
                ParseButtons(report, 1);
                break;

            case InputReport.ButtonsAccelerometer:
                ParseButtons(report, 1);
                ParseAccelerometer(report, 3);
                break;

            case InputReport.Buttons8Extension:
                ParseButtons(report, 1);
                ParseExtension(report, 3, 8);
                break;

            case InputReport.ButtonsAccelerometer12Ir:
            {
                ParseButtons(report, 1);
                ParseAccelerometer(report, 3);

                ExtendedIRBeacon irBeacon;

                // Parse beacon 0.
                irBeacon      = (ExtendedIRBeacon)_CachedIRBeacons[0];
                _IRBeacons[0] = ParseExtendedBeacon(report, 6, irBeacon) ? irBeacon : null;

                // Parse beacon 1.
                irBeacon      = (ExtendedIRBeacon)_CachedIRBeacons[1];
                _IRBeacons[1] = ParseExtendedBeacon(report, 9, irBeacon) ? irBeacon : null;

                // Parse beacon 2.
                irBeacon      = (ExtendedIRBeacon)_CachedIRBeacons[2];
                _IRBeacons[2] = ParseExtendedBeacon(report, 12, irBeacon) ? irBeacon : null;

                // Parse beacon 3.
                irBeacon      = (ExtendedIRBeacon)_CachedIRBeacons[3];
                _IRBeacons[3] = ParseExtendedBeacon(report, 15, irBeacon) ? irBeacon : null;
            }
            break;

            case InputReport.Buttons19Extension:
                ParseButtons(report, 1);
                ParseExtension(report, 3, 19);
                break;

            case InputReport.ButtonsAccelerometer16Extension:
                ParseButtons(report, 1);
                ParseAccelerometer(report, 3);
                ParseExtension(report, 6, 16);
                break;

            case InputReport.Buttons10Ir9Extension:
            case InputReport.ButtonsAccelerometer10Ir6Extension:
            {
                int offset = 1;
                offset += ParseButtons(report, offset);
                if (type == InputReport.ButtonsAccelerometer10Ir6Extension)
                {
                    offset += ParseAccelerometer(report, offset);
                }

                BasicIRBeacon irBeacon;

                // Parse beacon 0.
                irBeacon      = _CachedIRBeacons[0];
                _IRBeacons[0] = ParseBasicBeacon(report, offset, 0, irBeacon) ? irBeacon : null;

                // Parse beacon 1.
                irBeacon      = _CachedIRBeacons[1];
                _IRBeacons[1] = ParseBasicBeacon(report, offset, 1, irBeacon) ? irBeacon : null;

                // Parse beacon 2.
                irBeacon      = _CachedIRBeacons[2];
                _IRBeacons[2] = ParseBasicBeacon(report, offset + 5, 0, irBeacon) ? irBeacon : null;

                // Parse beacon 3.
                irBeacon      = _CachedIRBeacons[3];
                _IRBeacons[3] = ParseBasicBeacon(report, offset + 5, 1, irBeacon) ? irBeacon : null;

                offset += 10;         // Each pair of IR-beacons is 5 bytes.

                if (type == InputReport.ButtonsAccelerometer10Ir6Extension)
                {
                    ParseExtension(report, offset, 6);
                }
                else
                {
                    ParseExtension(report, offset, 9);
                }
            }
            break;

            case InputReport.Extension:
                ParseExtension(report, 1, 21);
                break;

            case InputReport.ButtonsAccelerometer36IrA:
            {
                ParseButtons(report, 1);         // since button information is complete on both the interlaced reports it needs no temporary storage

                _PartialAccelerometerX = report[3];
                _PartialAccelerometerZ = (ushort)(((report[2] & 0x60) << 1) | ((report[1] & 0x60) >> 1));

                _PartialIRBeaconOneResult = ParseFullBeacon(report, 4, (FullIRBeacon)_CachedIRBeacons[0]);
                _PartialIRBeaconTwoResult = ParseFullBeacon(report, 13, (FullIRBeacon)_CachedIRBeacons[1]);
            }
            break;

            case InputReport.ButtonsAccelerometer36IrB:
            {
                ParseButtons(report, 1);

                // Complete the _PartialAccelerometerZ field
                _PartialAccelerometerZ = (ushort)(_PartialAccelerometerZ | ((report[2] & 60) >> 3) | ((report[1] & 60) >> 5));

                // Initialize the accelerometer if it was not yet initialized (should never happen).
                if (Accelerometer == null)
                {
                    ReadCalibrationData();
                }

                // Construct the new accelerometer-values from now completed data
                Accelerometer.Raw.X = _PartialAccelerometerX;
                Accelerometer.Raw.Y = report[3];
                Accelerometer.Raw.Z = _PartialAccelerometerZ;

                UpdateCalibratedAccelerometer();

                FullIRBeacon irBeacon;

                // Commit partial irbeacon from 'a' report
                IRBeacons[0] = _PartialIRBeaconOneResult ? _CachedIRBeacons[0] : null;

                // Commit partial irbeacon from 'a' report
                IRBeacons[1] = _PartialIRBeaconTwoResult ? _CachedIRBeacons[1] : null;

                // Parse beacon 2.
                irBeacon     = (FullIRBeacon)_CachedIRBeacons[2];
                IRBeacons[2] = ParseFullBeacon(report, 4, irBeacon) ? irBeacon : null;

                // Parse beacon 3.
                irBeacon     = (FullIRBeacon)_CachedIRBeacons[3];
                IRBeacons[3] = ParseFullBeacon(report, 13, irBeacon) ? irBeacon : null;
            }
            break;

            case InputReport.GetStatusResult:
                ParseButtons(report, 1);
                ParseStatus(report);
                break;

            case InputReport.ReadDataResult:
                ParseButtons(report, 1);
                // The rest is handled by the ReadData method (waiting for the report).
                break;

            case InputReport.WriteDataResult:
                // The rest is handled by the WriteData method (waiting for the report).
                break;

            default:
                Debug.WriteLine("Unknown report type: " + type.ToString("x"));
                return(false);
            }

            if ((type >= InputReport.Buttons || type == InputReport.GetStatusResult) && (type != InputReport.ButtonsAccelerometer36IrA))
            {
                OnUpdated();
            }
            return(true);
        }
示例#37
0
 /// <summary>
 /// Feedback report
 /// </summary>
 public override bool Visit(InputReport msg, Client data)
 {
     return(data.ReceiveInputReport(msg));
 }
示例#38
0
 protected static IRMode GetIrMode(InputReport reportType)
 {
     switch (reportType)
     {
         case InputReport.ButtonsAccelerometer12Ir:
             return IRMode.Extended;
         case InputReport.Buttons10Ir9Extension:
         case InputReport.ButtonsAccelerometer10Ir6Extension:
             return IRMode.Basic;
         case InputReport.ButtonsAccelerometer36IrA:
         case InputReport.ButtonsAccelerometer36IrB:
             return IRMode.Full;
     }
     return IRMode.Off;
 }
示例#39
0
 protected byte[] SendAndReturnReport(InputReport returnReportType)
 {
     return SendAndReturnReport(returnReportType, ReportTimeout);
 }
示例#40
0
 protected byte[] SendAndReturnReport(InputReport returnReportType, TimeSpan timeout)
 {
     byte[] report = null;
     using (IReportInterceptor reportInterceptor = CreateReportInterceptor())
     {
         SendReport();
         DateTime start = DateTime.Now;
         while ((report = reportInterceptor.Intercept()) != null)
         {
             if (report[0] == (byte)returnReportType)
                 break;
             if (DateTime.Now - start > timeout)
             {
                 report = null;
                 break;
             }
         }
     }
     if (report == null)
         throw new TimeoutException("Could not retrieve result-report.");
     return report;
 }
        /// <summary>
        /// Set Wiimote reporting mode
        /// </summary>
        /// <param name="type">Report type</param>
        /// <param name="irSensitivity">IR sensitivity</param>
        /// <param name="continuous">Continuous data</param>
        public void SetReportType(InputReport type, IRSensitivity irSensitivity, bool continuous)
        {
            // only 1 report type allowed for the BB
            //if (mWiimoteState.ExtensionType == ExtensionType.BalanceBoard)
            //	type = InputReport.ButtonsExt19;


            DataReportAttribute dataReport =
                EnumInfo <InputReport> .TryGetAttribute <DataReportAttribute>(type);

            if (dataReport == null)
            {
                throw new WiimoteException($"{type} is not a valid report type!");
            }

            int irSize = dataReport.IRSize;

            if (dataReport.IsInterleaved)
            {
                irSize *= 2;
            }

            switch (dataReport.IRSize)
            {
            case 10:
                EnableIR(IRMode.Basic, irSensitivity);
                break;

            case 12:
                EnableIR(IRMode.Extended, irSensitivity);
                break;

            case 36:
                EnableIR(IRMode.Full, irSensitivity);
                break;

            default:
                DisableIR();
                break;
            }

            /*switch (type) {
             * case InputReport.ButtonsAccelIR12:
             *      EnableIR(IRMode.Extended, irSensitivity);
             *      break;
             * case InputReport.ButtonsAccelIR10Ext6:
             *      EnableIR(IRMode.Basic, irSensitivity);
             *      break;
             * default:
             *      DisableIR();
             *      break;
             * }*/

            /*byte[] buff = CreateReport();
             * buff[0] = (byte) OutputReport.DataReportType;
             * buff[1] = (byte) ((continuous ? 0x04 : 0x00) | GetRumbleBit());
             * buff[2] = (byte) type;*/

            byte[] buff = CreateReport();
            buff[0] = (byte)((continuous ? 0x04 : 0x00) | GetRumbleBit());
            buff[1] = (byte)type;

            WriteReport2(OutputReport.DataReportType, buff);
        }
示例#42
0
        /// <summary>
        /// Parse accelerometer data in PASS-THRU
        /// </summary>
        /// <param name="buff">Data buffer</param>
        private void ParseAccel(WiimoteDevice device, InputReport type, byte[] buff)
        {    AxisDetails axisDetails;

            if (type == InputReport.InterleaveButtonsAccellIR1)
            {
                
                axisDetails = device.Axis[JoystickAxis.AxisAccX] as AxisDetails;
                axisDetails.value = (float)buff[3] - axisDetails.min / (axisDetails.max - axisDetails.min);
                //mWiimoteState.AccelState.RawValues6b.X = buff[3];
                //mWiimoteState.AccelState.RawValues6b.Z = (buff[1] << 1 & 0xC0) | (buff[0] >> 1 & 0x30);

                axisDetails = device.Axis[JoystickAxis.AxisAccZ] as AxisDetails;
                axisDetails.rawValue = ((buff[1] << 1 & 0xC0) | (buff[0] >> 1 & 0x30));
            }
            else
            {
                axisDetails = device.Axis[JoystickAxis.AxisAccY] as AxisDetails;
                axisDetails.value = (float)buff[3] - axisDetails.min / (axisDetails.max - axisDetails.min);

                //mWiimoteState.AccelState.RawValues6b.Y = buff[3];
                //mWiimoteState.AccelState.RawValues6b.Z |= (buff[0] >> 5 & 0x3) | (buff[1] >> 3 & 0xC);

                axisDetails = device.Axis[JoystickAxis.AxisAccZ] as AxisDetails;
                axisDetails.rawValue |= (buff[0] >> 5 & 0x3) | (buff[1] >> 3 & 0xC);

                axisDetails.value = (float)(axisDetails.rawValue) - axisDetails.min / (axisDetails.max - axisDetails.min);
       
            }
        }