Beispiel #1
0
        private void PollThread()
        {
            double[] prevs  = { 0, 0, 0 };
            bool[]   hasNew = { false, false, false };

            while (continuePolling)
            {
                double[] joyStickAmounts = NXTcontroller.getAxisPositions();
                Console.WriteLine("Throttle is at: " + joyStickAmounts[0] + ", Pitch: " + joyStickAmounts[1] + ", Yaw: " + joyStickAmounts[2]);

                for (int i = 0; i < 2; i++)
                {
                    if (joyStickAmounts[i] != -1 && prevs[i] != joyStickAmounts[i])
                    {
                        hasNew[i] = true;
                    }
                }
                if (hasNew[0])
                {
                    StructPlaneThrottle planeThrottle = new StructPlaneThrottle()
                    {
                        ENG1 = joyStickAmounts[0],
                        ENG2 = joyStickAmounts[0]
                    };
                    if (connectedToSim)
                    {
                        simConnect.SetDataOnSimObject(DEFINITIONS.PlaneThrottle, 1, SIMCONNECT_DATA_SET_FLAG.DEFAULT, planeThrottle);
                        prevs[0] = joyStickAmounts[0];
                    }
                }
                if (hasNew[1] || hasNew[2])
                {
                    StructPlanePitchYaw planePY = new StructPlanePitchYaw {
                        ELEVATOR = joyStickAmounts[1],
                        AILERON  = joyStickAmounts[2]
                    };
                    if (connectedToSim)
                    {
                        simConnect.SetDataOnSimObject(DEFINITIONS.PlanePitchYaw, 1, SIMCONNECT_DATA_SET_FLAG.DEFAULT, planePY);
                        prevs[1] = joyStickAmounts[1];
                        prevs[2] = joyStickAmounts[2];
                    }
                }
                Thread.Sleep(2);
            }
        }
Beispiel #2
0
 private void keepAwakeTimerFunction(object state)
 {
     byte[] keepAwakePacket = { 0x80, 0x0D }; //sends keep awake packet with no response requested.
     NXTcontroller.SendPacket(keepAwakePacket);
 }