Beispiel #1
0
        public static void ReadUSBWorker(object data)
        {
            XboxReader reader = ((XboxReader)data);

            while (!reader.inShutdown)
            {
                USBPacket packet = reader.packetPool[reader.currentPacketInPool];
                reader.currentPacketInPool += 1;
                reader.currentPacketInPool %= 100;

                uint  status         = 0;
                uint  events         = 0;
                ulong timeSop        = 0;
                ulong timeDuration   = 0;
                uint  timeDataOffset = 0;

                packet.Length = BeagleApi.bg_usb2_read(
                    ((XboxReader)data).hBeagle, ref status, ref events, ref timeSop,
                    ref timeDuration, ref timeDataOffset, 1024, packet.Packet);

                if (packet.Length == 23 &&
                    (packet.Packet[0] == BeagleApi.BG_USB_PID_DATA1 || packet.Packet[0] == BeagleApi.BG_USB_PID_DATA0) &&
                    packet.Packet[1] == 0x00 &&
                    packet.Packet[2] == 0x14)
                {
                    reader.packetsToBeProcessed.Enqueue(packet);
                }
            }
        }
Beispiel #2
0
        public static void ProcessPacketWorker(object data)
        {
            XboxReader reader = ((XboxReader)data);

            while (!reader.inShutdown)
            {
                if (reader.packetsToBeProcessed.Count > 0)
                {
                    reader.packetsToBeProcessed.TryDequeue(out USBPacket packet);

                    var outState = new ControllerStateBuilder();

                    for (int i = 0; i < 8; ++i)
                    {
                        outState.SetButton(BUTTONS[i], (packet.Packet[3] & (1 << i)) != 0);
                    }

                    for (int i = 5; i < 13; ++i)
                    {
                        outState.SetButton(ANALOG_BUTTONS[i - 5], packet.Packet[i] > 0);
                        outState.SetAnalog(ANALOG_BUTTONS[i - 5], ReadTrigger(packet.Packet[i]));
                    }

                    int j = 0;
                    for (int i = 0; i < 4; ++i)
                    {
                        short val = packet.Packet[13 + j];
                        val += (short)(packet.Packet[14 + j] << 8);
                        outState.SetAnalog(STICKS[i], ReadStick(val));
                        j += 2;
                    }

                    reader.ControllerStateChanged?.Invoke(reader, outState.Build());
                }
            }
        }