コード例 #1
0
        /// <summary>
        /// Subscribe to a DataRef, notification will be sent every time the value changes
        /// </summary>
        /// <param name="dataref">DataRef to subscribe to</param>
        /// <param name="frequency">Times per seconds X-Plane will be seding this value</param>
        /// <param name="onchange">Callback invoked every time a change in the value is detected</param>
        public void Subscribe(FloatArrayDataRefElement dataref, int frequency = -1, Action <FloatArrayDataRefElement, List <float> > onchange = null)
        {
            if (dataref == null)
            {
                throw new ArgumentNullException(nameof(dataref));
            }

            dataref.OnValueChange += (e, v) =>
            {
                onchange(e, v);
            };

            var wT3NumberOfAircraftRendered = (FloatDataRefElement)global::XPlaneConnector.DataRefs.WT3NumberOfAircraftRendered;

            Subscribe(wT3NumberOfAircraftRendered, frequency, (element, aircraftCount) =>
            {
                dataref.ArrayLength = (int)aircraftCount;
                for (var c = 0; c < aircraftCount; c++)
                {
                    var arrayElementDataRef = new FloatDataRefElement
                    {
                        DataRef     = $"{dataref.DataRef}[{c}]",
                        Description = ""
                    };

                    var currentIndex = c;
                    Subscribe(arrayElementDataRef, frequency, (e, v) =>
                    {
                        dataref.Update(currentIndex, v);
                    });
                }
            });
        }
コード例 #2
0
        /// <summary>
        /// Subscribe to a DataRef, notification will be sent every time the value changes
        /// </summary>
        /// <param name="dataref">DataRef to subscribe to</param>
        /// <param name="frequency">Times per seconds X-Plane will be seding this value</param>
        /// <param name="onchange">Callback invoked every time a change in the value is detected</param>
        public void Subscribe(StringDataRefElement dataref, int frequency = -1, Action <StringDataRefElement, string> onchange = null)
        {
            //if (onchange != null)
            //    dataref.OnValueChange += (e, v) => { onchange(e, v); };

            //Subscribe((DataRefElement)dataref, frequency);

            if (dataref == null)
            {
                throw new ArgumentNullException(nameof(dataref));
            }

            dataref.OnValueChange += (e, v) => { onchange(e, v); };

            for (var c = 0; c < dataref.StringLenght; c++)
            {
                var arrayElementDataRef = new FloatDataRefElement
                {
                    DataRef     = $"{dataref.DataRef}[{c}]",
                    Description = ""
                };

                var currentIndex = c;
                Subscribe(arrayElementDataRef, frequency, (e, v) =>
                {
                    var character = Convert.ToChar(Convert.ToInt32(v));
                    dataref.Update(currentIndex, character);
                });
            }
        }
コード例 #3
0
        /// <summary>
        /// Informs X-Plane to change the value of the DataRef
        /// </summary>
        /// <param name="dataref">DataRef that will be changed</param>
        /// <param name="value">New value of the DataRef</param>
        public void SetDataRefValue(FloatDataRefElement dataref, float value)
        {
            if (dataref == null)
            {
                throw new ArgumentNullException(nameof(dataref));
            }

            SetDataRefValue(dataref.DataRef, value);
        }
コード例 #4
0
        private void RequestDataRef(FloatDataRefElement element)
        {
            if (client != null)
            {
                var dg = new XPDatagram();
                dg.Add("RREF");
                dg.Add(element.Frequency);
                dg.Add(element.Id);
                dg.Add(element.DataRef);
                dg.FillTo(413);

                client.Send(dg.Get(), dg.Len);

                OnLog?.Invoke($"Requested {element.DataRef}@{element.Frequency}Hz with Id:{element.Id}");
            }
        }
コード例 #5
0
        /// <summary>
        /// Subscribe to a DataRef, notification will be sent every time the value changes
        /// </summary>
        /// <param name="dataref">DataRef to subscribe to</param>
        /// <param name="frequency">Times per seconds X-Plane will be seding this value</param>
        /// <param name="onchange">Callback invoked every time a change in the value is detected</param>
        public void Subscribe(FloatDataRefElement dataref, int frequency = -1, Action <FloatDataRefElement, float> onchange = null)
        {
            if (dataref == null)
            {
                throw new ArgumentNullException(nameof(dataref));
            }

            if (onchange != null)
            {
                dataref.OnValueChange += (e, v) => { onchange(e, v); }
            }
            ;

            if (frequency > 0)
            {
                dataref.Frequency = frequency;
            }

            DataRefs.Add(dataref);
        }
コード例 #6
0
 private void Subscribe(FloatDataRefElement dataref, int frequency = -1)
 {
 }