public MCTelemetryInfo(MCAPI telemetryData, MCAPI lastTelemetryData)
 {
     _telemetryData     = telemetryData;
     _lastTelemetryData = lastTelemetryData;
 }
        private void Run()
        {
            MCAPI     lastTelemetryData = new MCAPI();
            Stopwatch sw = new Stopwatch();

            sw.Start();
            while (!isStopped)
            {
                try
                {
                    MCAPI telemetryData = new MCAPI();//(MCAPI)readSharedMemory(typeof(MCAPI), sharedMemoryFile);

                    Guid key = controllerForm.selectedJoystick.Key;
                    if (controllerGuid != key)
                    {
                        if (key == Guid.Empty)
                        {
                            if (joystick != null)
                            {
                                joystick.Dispose();
                                joystick = null;
                            }
                        }
                        else
                        {
                            if (joystick != null)
                            {
                                joystick.Dispose();
                            }
                            joystick = new Joystick(directInput, key);
                        }
                    }
                    controllerGuid = key;

                    joystick.Acquire();
                    joystick.Poll();

                    telemetryData.Pitch = 0;
                    telemetryData.Roll  = 0;

                    {
                        JoystickState state = new JoystickState();
                        joystick.GetCurrentState(ref state);

                        if (IsMotionEnabled)
                        {
                            //if(axes.Length > 5)
                            //{
                            //telemetryData.Roll = axes[5];
                            //if (state.Buttons.Length > 1 && state.Buttons[1])
                            //{
                            //    MessageBox.Show("STATE: " + state.ToString());
                            //}
                            telemetryData.AccG    = new float[3];
                            telemetryData.Roll    = (state.RotationX - 32768.0f) / 32768.0f;
                            telemetryData.Pitch   = (state.Y - 32768.0f) / 32768.0f;
                            telemetryData.AccG[1] = (state.Z - 32768.0f) / 32768.0f * 5.0f;
                            //}

                            //X = LEFT THUMB X AXIS
                            //Y = LEFT THUMB Y AXIS

                            //ROTATION X = RIGHT THUMB X AXIS
                            //ROTATION Y = RIGHT THUMB Y AXIS

                            //POINT OF VIEW CONTROLLERS = DPAD

                            //RIGHT TRIGGER = -Z
                            //LEFT TRIGGER = Z
                        }
                    }

                    IsConnected = true;

                    IsRunning = true;

                    sw.Restart();

                    TelemetryEventArgs args = new TelemetryEventArgs(
                        new MCTelemetryInfo(telemetryData, lastTelemetryData));
                    RaiseEvent(OnTelemetryUpdate, args);

                    lastTelemetryData = telemetryData;

                    Thread.Sleep(SamplePeriod);
                }
                catch (Exception e)
                {
                    LogError("MCTelemetryProvider Exception while processing data", e);
                    IsConnected = false;
                    IsRunning   = false;
                    Thread.Sleep(1000);
                }
            }

            IsConnected = false;
            IsRunning   = false;
        }