コード例 #1
0
        private static void ButtonPress(object sender, MicroTimerEventArgs timerEventArgs)
        {
            count++;

            if (count <= pwm && !press_phase_done && fwd == '1')
            {
                press_phase_done = true;
                if (L == '0' && R == '1')
                {
                    Keyboard.KeyDown(Keys.Right);
                }
                else if (L == '1' && R == '0')
                {
                    Keyboard.KeyDown(Keys.Left);
                }
            }

            else if (count > pwm && !release_phase_done)
            {
                release_phase_done = true;
                if (L == '0' && R == '1')
                {
                    Keyboard.KeyUp(Keys.Right);
                }
                else if (L == '1' && R == '0')
                {
                    Keyboard.KeyUp(Keys.Left);
                }
            }

            else if (count > 100)
            {
                cycle_done = true;
            }
        }
コード例 #2
0
ファイル: Timer.cs プロジェクト: nmakes/NFS-Computer-Vision
        void NotificationTimer(ref long timerIntervalInMicroSec,
                               ref long ignoreEventIfLateBy,
                               ref bool stopTimer)
        {
            int  timerCount       = 0;
            long nextNotification = 0;

            MicroStopwatch microStopwatch = new MicroStopwatch();

            microStopwatch.Start();

            while (!stopTimer)
            {
                long callbackFunctionExecutionTime =
                    microStopwatch.ElapsedMicroseconds - nextNotification;

                long timerIntervalInMicroSecCurrent =
                    System.Threading.Interlocked.Read(ref timerIntervalInMicroSec);
                long ignoreEventIfLateByCurrent =
                    System.Threading.Interlocked.Read(ref ignoreEventIfLateBy);

                nextNotification += timerIntervalInMicroSecCurrent;
                timerCount++;
                long elapsedMicroseconds = 0;

                while ((elapsedMicroseconds = microStopwatch.ElapsedMicroseconds)
                       < nextNotification)
                {
                    System.Threading.Thread.SpinWait(10);
                }

                long timerLateBy = elapsedMicroseconds - nextNotification;

                if (timerLateBy >= ignoreEventIfLateByCurrent)
                {
                    continue;
                }

                MicroTimerEventArgs microTimerEventArgs =
                    new MicroTimerEventArgs(timerCount,
                                            elapsedMicroseconds,
                                            timerLateBy,
                                            callbackFunctionExecutionTime);
                MicroTimerElapsed(this, microTimerEventArgs);
            }

            microStopwatch.Stop();
        }