Пример #1
0
        private void UnregisterToSimConnect(SimVarRequest simvarRequest)
        {
            if (_simConnect == null)
            {
                return;
            }

            _simConnect.ClearDataDefinition((eDummy)simvarRequest.Def);
        }
Пример #2
0
        private bool RegisterToSimConnect(SimVarRequest simvarRequest)
        {
            if (_simConnect == null)
            {
                return(false);
            }

            /// Define a data structure
            _simConnect.AddToDataDefinition((eDummy)simvarRequest.Def, simvarRequest.Name, simvarRequest.Units, SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);

            /// IMPORTANT: Register it with the simconnect managed wrapper marshaller
            /// If you skip this step, you will only receive a uint in the .dwData field.
            _simConnect.RegisterDataDefineStruct <double>((eDummy)simvarRequest.Def);

            return(true);
        }
Пример #3
0
        public Task <Double> GetValueAsync(string simvar, string unit)
        {
            Console.WriteLine("Adding a one-time request for value: " + simvar);

            string newSimvarRequest = simvar;
            string newUnitRequest   = unit;
            var    reqId            = ++_lastReqId;

            SimVarRequest request = new SimVarRequest
            {
                Def          = (eDummy)reqId,
                Request      = (eDummy)reqId,
                Name         = newSimvarRequest,
                Units        = newUnitRequest,
                OneTimeEvent = true
            };

            double retValue   = 0d;
            bool   isFinished = false;

            request.SimVarChanged += (object sender, SimVarUpdatedEventArgs e) =>
            {
                retValue   = e.Request.Value;
                isFinished = true;
            };

            request.Pending      = !RegisterToSimConnect(request);
            request.StillPending = request.Pending;

            _simVarRequests.Add(request);

            return(Task <Double> .Factory.StartNew(() =>
            {
                while (!isFinished)
                {
                    System.Threading.Thread.Yield();
                }

                return retValue;
            }));
        }
Пример #4
0
        public SimVarRequest AddRequest(string simvar, string unit)
        {
            Console.WriteLine("Adding request for value: " + simvar);

            string newSimvarRequest = simvar;
            string newUnitRequest   = unit;
            var    reqId            = ++_lastReqId;

            SimVarRequest request = new SimVarRequest
            {
                Def          = (eDummy)reqId,
                Request      = (eDummy)reqId,
                Name         = newSimvarRequest,
                Units        = newUnitRequest,
                OneTimeEvent = false
            };

            request.Pending      = !RegisterToSimConnect(request);
            request.StillPending = request.Pending;

            _simVarRequests.Add(request);

            return(request);
        }
Пример #5
0
 public SimVarUpdatedEventArgs(SimVarRequest request)
 {
     Request = request;
 }