Example #1
0
        private void InitSimConnectField(Field field)
        {
            if (!isConnected)
            {
                return;
            }
            var attrib = FieldDefinition(field);

            if (attrib is null)
            {
                return;
            }

            var unitConfig = UnitTypeConfig.GetConfig(attrib.UnitType);

            // Set up data definition
            Console.WriteLine($"Def {attrib.DatumName}, {attrib.UnitType}");
            simconnect.AddToDataDefinition(field, attrib.DatumName, unitConfig.Units,
                                           unitConfig.DataType, 0.0f, SimConnect.SIMCONNECT_UNUSED);
            var method    = typeof(SimConnect).GetMethod("RegisterDataDefineStruct");
            var methodRef = method.MakeGenericMethod(unitConfig.Struct);

            methodRef.Invoke(simconnect, new object[] { field });

            // Get initial value
            simconnect.RequestDataOnSimObjectType(field, field, 0, SIMCONNECT_SIMOBJECT_TYPE.USER);

            // Create event mapping
            simconnect.MapClientEventToSimEvent(field, attrib.EventId);
            simconnect.AddClientEventToNotificationGroup(GROUPS.GroupA, field, false);
        }
Example #2
0
        public SimControlAdaptor CreateAdaptor(Field field)
        {
            var attrib = FieldDefinition(field);

            if (attrib is null)
            {
                return(null);
            }
            var unitConfig     = UnitTypeConfig.GetConfig(attrib.UnitType);
            var controlAdaptor = new SimControlAdaptor(field, attrib.UnitType, unitConfig.MinValue, unitConfig.MaxValue);

            controlAdaptors.Add(field, controlAdaptor);
            InitSimConnectField(field);
            return(controlAdaptor);
        }