Ejemplo n.º 1
0
 ///<example>await AVActions.TaskDelayLoop(1000, AVTask);</example>
 public static async Task TaskDelayLoop(int millisecondsDelay, AVTaskDetails avTask)
 {
     try
     {
         await Task.Delay(millisecondsDelay, avTask.TokenSource.Token);
     }
     catch { }
 }
Ejemplo n.º 2
0
 ///<example>await AVActions.TaskDelayLoop(1000, AVTask);</example>
 public static async Task TaskDelayLoop(int millisecondsDelay, AVTaskDetails avTask)
 {
     try
     {
         if (millisecondsDelay < 50)
         {
             TaskDelayMs((uint)millisecondsDelay);
         }
         else
         {
             await Task.Delay(millisecondsDelay, avTask.TokenSource.Token);
         }
     }
     catch { }
 }
Ejemplo n.º 3
0
        ///<param name="actionRun">async Task TaskAction() { while (!AVTask.TaskStopRequest) { void(); await TaskDelayLoop(1000, AVTask); } }</param>
        ///<example>AVActions.TaskStartLoop(TaskAction, AVTask);</example>
        ///<summary>Don't forget to use try and catch to improve stability</summary>
        public static void TaskStartLoop(Action actionRun, AVTaskDetails avTask)
        {
            try
            {
                if (avTask == null)
                {
                    Task.Run(actionRun);
                }
                else
                {
                    //Dispose and reset task
                    avTask.DisposeReset();

                    //Create new loop task
                    avTask.Task = Task.Run(actionRun);
                }
                Debug.WriteLine("Loop task has been started.");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to start loop task: " + ex.Message);
            }
        }
Ejemplo n.º 4
0
        ///<example>AVActions.TaskStopLoop(AVTask);</example>
        public static async Task TaskStopLoop(AVTaskDetails avTask)
        {
            try
            {
                //Check if the task is stopped
                if (avTask.TaskStopRequest || avTask.TaskCompleted || !avTask.TaskRunning)
                {
                    Debug.WriteLine("Loop task is stopping or not running.");
                    return;
                }

                //Signal the loop task to stop
                avTask.TokenSource.Cancel();

                //Wait for task to have stopped
                Debug.WriteLine("Waiting for task to stop or timeout...");
                long stopTimeout = GetSystemTicksMs();
                while (!avTask.TaskCompleted)
                {
                    if ((GetSystemTicksMs() - stopTimeout) >= 8000)
                    {
                        Debug.WriteLine("Stopping the task has timed out...");
                        break;
                    }
                    await Task.Delay(1);
                }

                //Dispose and reset task
                avTask.DisposeReset();

                Debug.WriteLine("Loop task has been stopped.");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to stop loop task: " + ex.Message);
            }
        }
Ejemplo n.º 5
0
            //Reset controller status to defaults
            public void ResetControllerStatus()
            {
                try
                {
                    Debug.WriteLine("Reset the controller status for controller: " + NumberId);

                    //Controller Status
                    Activated = false;

                    //Battery Status
                    BatteryCurrent  = new ControllerBattery();
                    BatteryPrevious = new ControllerBattery();

                    //Time Variables
                    PrevInputTicks  = 0;
                    LastInputTicks  = 0;
                    LastActiveTicks = 0;

                    //Controller Details
                    Details     = null;
                    BlockOutput = false;

                    //Controller Tasks
                    InputVirtualOverlapped = new NativeOverlapped()
                    {
                        EventHandle = CreateEvent(IntPtr.Zero, true, false, null)
                    };
                    OutputVirtualOverlapped = new NativeOverlapped()
                    {
                        EventHandle = CreateEvent(IntPtr.Zero, true, false, null)
                    };
                    InputControllerTask  = new AVTaskDetails();
                    OutputControllerTask = new AVTaskDetails();
                    OutputVirtualTask    = new AVTaskDetails();
                    OutputGyroTask       = new AVTaskDetails();

                    //WinUsb Device Variables
                    WinUsbDevice = null;

                    //Hid Device Variables
                    HidDevice = null;

                    //Gyro Dsu Client Variables
                    GyroDsuClientPacketNumber = 0;
                    GyroDsuClientEndPoint     = null;

                    //Device In and Output
                    InputButtonCountLoop1     = 0;
                    InputButtonCountTotal1    = 80;
                    InputButtonCountLoop2     = 0;
                    InputButtonCountTotal2    = 80;
                    InputButtonCountLoop3     = 0;
                    InputButtonCountTotal3    = 80;
                    InputHeaderOffsetFinished = false;
                    InputHeaderOffsetByte     = 0;
                    InputButtonOffsetFinished = false;
                    InputButtonOffsetByte     = 0;
                    InputReport  = null;
                    OutputReport = null;
                    XInputData   = new XUSB_INPUT_REPORT();
                    XOutputData  = new XUSB_OUTPUT_REPORT();
                    XOutputCurrentRumbleHeavy  = 0;
                    XOutputCurrentRumbleLight  = 0;
                    XOutputPreviousRumbleHeavy = 0;
                    XOutputPreviousRumbleLight = 0;

                    //Controller Input
                    InputCurrent     = new ControllerInput();
                    SupportedCurrent = new ControllerSupported();
                }
                catch { }
            }