Exemplo n.º 1
0
        public void Read()
        {
            HidDeviceData dataPoint = usbDevice.Read();

            if (dataPoint.Status != HidDeviceData.ReadStatus.Success)
            {
                throw new InvalidOperationException($"Cannot read from USB device! State was {dataPoint.Status}");
            }

            // this is the same behaviour as the CAM software.
            // Somehow it sometimes spits random, fixed values and nobody really knows why.
            if (dataPoint.Data[10] != deviceId)
            {
                return;
            }

            if (dataPoint.Data[0] == 4)
            {
                LastStates.Enqueue(ParseDataPackage(dataPoint));
            }

            while (LastStates.Count > 255)
            {
                LastStates.Dequeue();
            }
        }
Exemplo n.º 2
0
        private async void ReadLoop()
        {
            HidDeviceData dataPoint = await usbDevice.ReadAsync();

            GetDeviceId(dataPoint);
            while (keepReading)
            {
                dataPoint = await usbDevice.ReadAsync();

                if (dataPoint.Status != HidDeviceData.ReadStatus.Success)
                {
                    throw new InvalidOperationException($"Cannot read from USB device! State was {dataPoint.Status}");
                }

                // this is the same behaviour as the CAM software.
                // Somehow it sometimes spits random, fixed values and nobody really knows why.
                if (dataPoint.Data[10] != deviceId)
                {
                    // Console.WriteLine("Disposed");
                    continue;
                }

                if (dataPoint.Data[0] == 4)
                {
                    LastStates.Enqueue(ParseDataPackage(dataPoint));
                }

                while (LastStates.Count > 255)
                {
                    LastStates.Dequeue();
                }
            }
        }
Exemplo n.º 3
0
        internal void OnUpdate(out AtsHandles vehicleOperations, AtsVehicleState vehicleState, IntPtr panelArray, IntPtr soundArray)
        {
            PanelOperations.SetSource(panelArray);
            SoundOperations.SetSource(soundArray);

            LastStates.CopyFrom(CurrentStates);
            if (WasJustInitialized)
            {
                LastStates.SetVehicleState(vehicleState);
            }

            CurrentStates.SetVehicleState(vehicleState);

            this.UpdateVelocityFromDeltaLocation();


            ControlHandle.Update();


            foreach (var behaviour in BehaviourArray)
            {
                behaviour.Update();
            }

            LastKeyStates.CopyFrom(CurrentKeyStates);

            vehicleOperations = ControlHandle.Operation;

            WasJustInitialized = false;
        }
Exemplo n.º 4
0
        internal void OnUpdate(out AtsHandles vehicleOperations, AtsVehicleState vehicleState, IntPtr panelArray, IntPtr soundArray)
        {
            PanelOperations.SetSource(panelArray);
            SoundOperations.SetSource(soundArray);

            LastStates.CopyFrom(CurrentStates);
            CurrentStates.SetVehicleState(vehicleState);

            foreach (IAtsBehaviour behaviour in Behaviours)
            {
                behaviour.Update();
            }

            LastKeyStates.CopyFrom(CurrentKeyStates);

            vehicleOperations = ControlHandle.Handles;
        }
Exemplo n.º 5
0
        public void Step()
        {
            ShortStop = false;

            AdvancePopulation();
            NewStates.CopyTo(CurrentStates, 0);

            string curr = GetStateString(CurrentStates);

            if (LastStates.Count == 10)
            {
                if (LastStates.Contains(curr))
                {
                    ShortStop = true;
                }

                LastStates.RemoveAt(0);
                LastStates.Add(curr);
            }
            else
            {
                LastStates.Add(curr);
            }
        }