예제 #1
0
        public void Generate(int count)
        {
            var data   = new byte[count];
            var random = new Random();

            random.NextBytes(data);
            DataGenerated?.Invoke(this, new DataGeneratedEventArgs {
                Data = data
            });
        }
예제 #2
0
        private async void OnTimerTick(object sender, ElapsedEventArgs e)
        {
            if (_token.IsCancellationRequested)
            {
                StopGenerate();
                return;
            }

            var randomValue = await _generator.GetRandomValueAsync();

            DataGenerated?.Invoke(randomValue);
        }
예제 #3
0
        public CentralClock(Form caller)
        {
            int delay = 1000 / ApplicationConfig.Shared.UpdateRate;

            ApplicationConfig.ConfigUpdated += config => _timer.DelayTime = 1000 / config.UpdateRate;


            _timer = new ThreadedTimer(() =>
            {
                if (_supressTimer)
                {
                    return;
                }

                var padState = GamePad.GetState(PlayerIndex.One, ApplicationConfig.Shared.DeadZone);
                StateGenerated?.Invoke(padState);

                //Process Gamepad
                var frame = CustomLogic.LogicMapper <TResponseData> .InputProcessor.ProcessData(padState, _previousFrame);

                //Update the frame number
                if (_previousFrame != null)
                {
                    frame.FrameNumber = _previousFrame.FrameNumber + 1;
                }

                //Send an update tick to the servos
                //The trick with the servos, is that all in all we only ever make one ServoSubFrame.
                //It gets recycled ever tick so that the servos can calculate velocities
                frame.Servos.Servo1.Update();
                frame.Servos.Servo2.Update();
                frame.Servos.Servo3.Update();
                frame.Servos.Servo4.Update();


                //Send the frame to anybody who is listening
                FrameGenerated?.Invoke(frame);

                //Get Sensor Data and send it to anybody who is listening
                DataGenerated?.Invoke(CustomLogic.LogicMapper <TResponseData> .RobotClient.LatestData);

                //Update Video


                //Send new commands
                var c = CustomLogic.LogicMapper <TResponseData> .RobotClient;
                c.SendFrame(frame);

                //Stash the current frame away for the next loop.
                _previousFrame = frame;
            }, caller, delay);
        }