Exemplo n.º 1
0
    void OnTimedEvent(object sender, MicroTimerEventArgs timerEventArgs)
    {
        FrameCount = timerEventArgs.TimerCount;

        if (sw_eye == null || sw_facial == null)
        {
            UnityEngine.Debug.Log(timerEventArgs.TimerCount + "," + (System.DateTime.Now - StartRecordingTime) + ",0,0,0");
        }
        else
        {
            //sw_eye.WriteLine(timerEventArgs.TimerCount + "," + (System.DateTime.Now - StartRecordingTime) + "," + GazeDirection.x + "," + GazeDirection.y + "," + GazeDirection.z);
            sw_eye.WriteLine(timerEventArgs.TimerCount + "," + (System.DateTime.Now - StartRecordingTime) + "," + EyeRotationInDegree.x + "," + EyeRotationInDegree.y + "," + EyeRotationInDegree.z);

            for (int i = 0; i < BlendShapeNumber; i++)
            {
                sw_facial.WriteLine(timerEventArgs.TimerCount + "," + (System.DateTime.Now - StartRecordingTime) + "," +
                                    BlendShapeNames[i] + "," + BlendShapeValues[i]);
            }
        }

//        UnityEngine.Debug.Log(string.Format(
//            "Count = {0:#,0}  Timer = {1:#,0} µs, " +
//            "LateBy = {2:#,0} µs, ExecutionTime = {3:#,0} µs",
//            timerEventArgs.TimerCount, timerEventArgs.ElapsedMicroseconds,
//            timerEventArgs.TimerLateBy, timerEventArgs.CallbackFunctionExecutionTime));
    }
        private void OnTimedEvent(object sender, MicroTimerEventArgs timerEventArgs)
        {
            //_debugMessageList.Add(timerEventArgs.ElapsedMicroseconds.ToString());
            _dispatcher.BeginInvoke((Action)(() =>
            {
                _totalTime += 10;


                //_debugMessageList.Add(_totalTime.ToString())
                if (_messageBuffer != null)
                {
                    var message = new SerialMessage();
                    _messageBuffer.TryGetValue(_totalTime, out message);
                    if (message != null)
                    {
                        var result = _messageService.Send(message).GetAwaiter().GetResult();
                        if (String.IsNullOrWhiteSpace(result))
                        {
                            _debugMessageList.Add($"Sending message '{message.Message}' at {_totalTime}ms to port: {message.PortName}, OK");
                        }
                        else
                        {
                            _debugMessageList.Add($"Sending message '{message.Message}' at {_totalTime}ms to port: {message.PortName}, FAILED, {result}");
                        }

                        // _ea.GetEvent<MessageSendEvent>().Publish("");
                    }
                }
            }

                                             ));
        }
Exemplo n.º 3
0
        private void Event_Refresh(object sender, MicroTimerEventArgs timereventargs)
        {
            Logger.Debug(TraceMessage.Execute(this, "Refresh celestial map control."));

            if (refreshInProgress)
            {
                return;
            }

            var timeDrawScreen = Stopwatch.StartNew();

            refreshInProgress = true;

            DrawTacticalMapScreen();

            if (_gameSession.SpaceMap.IsEnabled)
            {
                turnStep++;
            }

            RefreshSelectedInfoControl(MouseMoveCelestialObject, granularTurnInformation, turnStep);

            refreshInProgress = false;

            Logger.Debug(TraceMessage.Execute(this, $"Time {timeDrawScreen.Elapsed.TotalMilliseconds} ms."));
        }
Exemplo n.º 4
0
    void OnTimedEvent(object sender, MicroTimerEventArgs timerEventArgs)
    {
        FrameCount = timerEventArgs.TimerCount;

        if (sw_cameraPos == null)
        {
            UnityEngine.Debug.Log(timerEventArgs.TimerCount + "," + (System.DateTime.Now - StartRecordingTime) + ",0,0,0");
        }
        else
        {
            sw_cameraPos.WriteLine(timerEventArgs.TimerCount + "," + (System.DateTime.Now - StartRecordingTime) + "," + position.x + "," + position.y + "," + position.z + "," + rotation.x + "," + rotation.y + "," + rotation.z);

//			for (int i = 0; i < BlendShapeNumber; i++)
//			{
//				sw_cameraPos.WriteLine(timerEventArgs.TimerCount + "," + (System.DateTime.Now - StartRecordingTime) + "," +
//					BlendShapeNames[i] + "," + BlendShapeValues[i]);
//			}
        }

        //        UnityEngine.Debug.Log(string.Format(
        //            "Count = {0:#,0}  Timer = {1:#,0} µs, " +
        //            "LateBy = {2:#,0} µs, ExecutionTime = {3:#,0} µs",
        //            timerEventArgs.TimerCount, timerEventArgs.ElapsedMicroseconds,
        //            timerEventArgs.TimerLateBy, timerEventArgs.CallbackFunctionExecutionTime));
    }
Exemplo n.º 5
0
    private void hiResTick(object sender, MicroTimerEventArgs timerEventArgs)
    {
        // Emulate a cycle
        emulator.Cycle();

        // If the screen was updated, draw it
        if (emulator.DrawRequired())
        {
            byte[] screen_data = emulator.GetDisplay();

            for (int y = 0; y < SCREEN_HEIGHT; ++y)
            {
                for (int x = 0; x < SCREEN_WIDTH; ++x)
                {
                    if (screen_data[(y * SCREEN_WIDTH) + x] == 0)
                    {
                        screen.SetPixel(x, y, Color.Black);
                    }
                    else
                    {
                        screen.SetPixel(x, y, Color.White);
                    }
                }
            }

            QueueDraw();
        }
    }
Exemplo n.º 6
0
        protected virtual 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();
        }
        private void Timer_MicroTimerElapsed(object sender, MicroTimerEventArgs timerEventArgs)
        {
            if (cancellationPending.Get())
            {
                return;
            }

            mainTicks++;
            MainTick(mainTicks);
            if ((mainTicks - 1) % sideTickDivider == 0)
            {
                sideTicks++;
                SideTick(sideTicks);
            }
        }
Exemplo n.º 8
0
 private void OnSpeakerTimerEllapsed(object sender, MicroTimerEventArgs e)
 {
     if (sender == speakerTimer)
     {
         //Console.WriteLine(speakerWatch.ElapsedMilliseconds);
         //speakerWatch = Stopwatch.StartNew();
         WriteReport(nextSpeakerReport);
         //Console.WriteLine(speakerWatch.ElapsedMilliseconds);
         if (NextSpeakerReport())
         {
             speakerTimer.Stop();
             Trace.WriteLine("Sound END");
         }
     }
 }
Exemplo n.º 9
0
        private void timer_TimerTick(object sender, MicroTimerEventArgs timerEventArgs)
        {
            switch (timerFlag)
            {
            case 0:
            {
                currentMotorSpeed += speedIncrement;
                int nextMotorSpeed = (int)Math.Truncate(currentMotorSpeed + speedIncrement);
                if (nextMotorSpeed != currentMotorSpeed)
                {
                    theBridge.SendMotorSpeed(nextMotorSpeed);
                }
                if (timerEventArgs.ElapsedMicroseconds > duration)
                {
                    timer.StopAndWait();
                    CommandFinished();
                }
            }
            break;

            case 1:
            {
                int nextMotorSpeed = (int)Math.Truncate(currentMotorSpeed + speedIncrement);
                if (nextMotorSpeed != (int)Math.Truncate(currentMotorSpeed))
                {
                    theBridge.SendMotorSpeed(-nextMotorSpeed);
                }
                currentMotorSpeed += speedIncrement;
                if (timerEventArgs.ElapsedMicroseconds >= duration)
                {
                    timer.StopAndWait();
                    CommandFinished();
                }
            }
            break;

            case 2:
                timer.StopAndWait();
                CommandFinished();
                break;

            default:
                break;
            }
        }
Exemplo n.º 10
0
        private void OnTimerEvent(object sender, MicroTimerEventArgs e)
        {
            if (++_internalCounter < GetDividerMode())
            {
                return;
            }

            _internalCounter = 0;

            if (_tcntL.Inc())
            {
                if (_tcntH.Inc())
                {
                    SetOverflowFlag(true);
                }
            }
            byte mode = GetMode();

            if (mode == 2)   // сравнение
            {
                if (_tcntL.NumValue() == _tiorL.NumValue() && _tcntH.NumValue() == _tiorH.NumValue())
                {
                    SetComparisonFlag(true);

                    if (IsResetOnCmp())
                    {
                        _tcntH = new ExtendedBitArray();
                        _tcntL = new ExtendedBitArray();
                    }
                }
            }

            double nowMillis = DateTime.Now.ToUniversalTime().Subtract(
                new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
                ).TotalMilliseconds;

            if (nowMillis - _lastUpdateMillis > UPDATE_PERIOD_MILLIS)
            {
                _form.Invoke(_updateFormDelegate);
                _lastUpdateMillis = nowMillis;
            }
        }
Exemplo n.º 11
0
        private void OnTimerElapsed(object sender, MicroTimerEventArgs e)
        {
            Dispatcher.Invoke(() =>
            {
                if (_doAudioOperations == null)
                {
                    return;
                }
                var currenttime = _audioObject.GetCurrentTime();

                if (currenttime.TotalSeconds <= SelectEnd)
                {
                    string currentTimeStamp = currenttime.Minutes + ":" + currenttime.Seconds + ":" + currenttime.Milliseconds;
                    StartText.Text          = currentTimeStamp;
                }

                if (!_isPlaying)
                {
                    if (_audioObject.GetPlayBackState() == PlayBackState.Playing)
                    {
                        _audioObject.StopAudio();
                        _microTimer.Stop();
                    }
                }

                if (_isPlaying)
                {
                    _waveDisplay.ChannelPosition = currenttime.TotalSeconds;
                }


                PlayInSelectedRegion();

                //if (_loopFalg == false && SelectBegin <= 0)
                //{
                //	ResetAtMaximum();
                //}

                StlimusSwitcher();
            });
        }
Exemplo n.º 12
0
 private void OnTickMicro(object sender, MicroTimerEventArgs timerEventArgs)
 {
     //   try
     // {
     lock (_timerMicro)
     {
         using (oscilloscopeChart.SuspendUpdates())
         {
             if ((ParserRayonM1.GetInstanceofParser.FifoplotList.IsEmpty == false))
             {
                 ParserRayonM1.GetInstanceofParser.FifoplotList.TryDequeue(out y);
                 Ch1Series.Append(dtx, y);
                 dtx = (dtx + 0.0001);
             }
             else
             {
             }
         }
         //
     }
 }
Exemplo n.º 13
0
        private void OnTimerEvent(object sender, MicroTimerEventArgs e)
        {
            if (++_internalCounter < GetDivider())
            {
                return;
            }

            _internalCounter = 0;

            bool equalUpperLimit = _tcntL.NumValue() == upperLimit[0].NumValue() && _tcntH.NumValue() == upperLimit[1].NumValue();
            bool equalLowerLimit = _tcntL.NumValue() == 0 && _tcntH.NumValue() == 0;

            // Инкремент/декремент
            if (dec)
            {
                if (_tcntL.Dec())
                {
                    if (_tcntH.Dec())
                    {
                        // 0000 -> FFFF underflow
                        Console.WriteLine("Shouldn't normally happen! 0000.Dec()");
                    }
                }
            }
            else
            {
                if (equalUpperLimit)
                {
                    _tcntL.And(new ExtendedBitArray());
                    _tcntH.And(new ExtendedBitArray());

                    SetOverflowFlag(true);
                }
                else if (_tcntL.Inc())
                {
                    if (_tcntH.Inc())
                    {
                        // FFFF -> 0000 overflow
                        Console.WriteLine("Shouldn't normally happen! FFFF.Inc()");
                        SetOverflowFlag(true);
                    }
                }
            }

            equalUpperLimit = _tcntL.NumValue() == upperLimit[0].NumValue() && _tcntH.NumValue() == upperLimit[1].NumValue();
            equalLowerLimit = _tcntL.NumValue() == 0 && _tcntH.NumValue() == 0;
            bool equalTcntOcr = _tcntL.NumValue() == _ocrL.NumValue() && _tcntH.NumValue() == _ocrH.NumValue();

            byte mode = GetMode();

            switch (mode)
            {
            case 1:     // сброс при совпадении
                if (equalTcntOcr)
                {
                    SetComparisonFlag(true);

                    _tcntH = new ExtendedBitArray();
                    _tcntL = new ExtendedBitArray();
                }
                break;

            case 2:     // быстрый ШИМ
                break;

            case 3:     // ШИМ с фазовой коррекцией
                // проверка совпадения с верхним пределом
                if (equalUpperLimit)
                {
                    dec = true;
                }
                else if (equalLowerLimit)
                {
                    dec = false;
                }
                break;
            }

            byte outputMode = GetOutputMode();

            switch (outputMode)
            {
            case 0:
                outputPinValue = false;
                break;

            case 1:     // инверсия при совпадении TCNT == OCR
                if (equalTcntOcr)
                {
                    outputPinValue = !outputPinValue;
                }
                break;

            case 2:
                if (mode < 2)         // Без ШИМ
                {
                    if (equalTcntOcr) // сброс при совпадении
                    {
                        outputPinValue = false;
                    }
                }
                if (mode == 2)        // Быстрый ШИМ
                {
                    if (equalTcntOcr) // сброс при совпадении
                    {
                        outputPinValue = false;
                    }
                    else if (equalUpperLimit)         // установка на вершине счета
                    {
                        outputPinValue = true;
                    }
                }
                if (mode == 3)       // ШИМ с ФК
                {
                    if (equalTcntOcr)
                    {
                        if (dec)
                        {
                            outputPinValue = true;     // установка при совпадении во время обратного счета
                        }
                        else
                        {
                            outputPinValue = false;     // сброс при совпадении во время прямого счета
                        }
                    }
                }
                break;

            case 3:
                if (mode < 2)         // Без ШИМ
                {
                    if (equalTcntOcr) // установка при совпадении
                    {
                        outputPinValue = true;
                    }
                }
                if (mode == 2)        // Быстрый ШИМ
                {
                    if (equalTcntOcr) // установка при совпадении
                    {
                        outputPinValue = true;
                    }
                    else if (equalUpperLimit)         // сброс на вершине счета
                    {
                        outputPinValue = false;
                    }
                }
                if (mode == 3)       // ШИМ с ФК
                {
                    if (equalTcntOcr)
                    {
                        if (dec)
                        {
                            outputPinValue = false;     // сброс при совпадении во время обратного счета
                        }
                        else
                        {
                            outputPinValue = true;     // установка при совпадении во время прямого счета
                        }
                    }
                }
                break;
            }

            double nowMillis = DateTime.Now.ToUniversalTime().Subtract(
                new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
                ).TotalMilliseconds;

            if (nowMillis - _lastUpdateMillis > UPDATE_PERIOD_MILLIS)
            {
                _form.Invoke(_updateFormDelegate);
                _lastUpdateMillis = nowMillis;
            }
        }
Exemplo n.º 14
0
 //////////////////////////////////////////////////////////////////////
 //
 //////////////////////////////////////////////////////////////////////
 private void OnCpuTick(object sender, MicroTimerEventArgs timerEventArgs)
 {
     RunOneFrame();
 }
Exemplo n.º 15
0
        void NotificationTimer(ref long timerIntervalInMicroSec,
                               ref long ignoreEventIfLateBy,
                               ref bool stopTimer)
        {
            var timerCount = 0;
            long nextNotification = 0;

            var microStopwatch = new MicroStopwatch();
            microStopwatch.Start();

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

                var timerIntervalInMicroSecCurrent =
                    Interlocked.Read(ref timerIntervalInMicroSec);
                var ignoreEventIfLateByCurrent =
                    Interlocked.Read(ref ignoreEventIfLateBy);

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

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

                var timerLateBy = elapsedMicroseconds - nextNotification;

                if (timerLateBy >= ignoreEventIfLateByCurrent) {
                    continue;
                }

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

            microStopwatch.Stop();
        }