public void MapperTest(double[] values, double centerValue, double mappedValue)
        {
            var mapper = new InputMapperCollection
            {
                CenterPoint = centerValue,
            };
            double result = mapper.GetValue(values);

            Assert.AreEqual(mappedValue, result);
        }
예제 #2
0
        public void Configure(ControllerConfig <T> config, IEnumerable <IInputDevice> devices)
        {
            var mapping = config.InputMapping;

            foreach (var input in Enum.GetValues(typeof(T)).OfType <T>().Where(i => !mapping.ContainsKey(i)))
            {
                mapping[input] = new InputMapperCollection();
            }
            foreach (var device in boundDevices)
            {
                device.InputChanged -= InputDeviceChanged;
            }
            forceFeedbackSetters.Clear();
            boundDevices.Clear();
            var deviceLookup = devices.ToDictionary(d => d.UniqueId, d => d);

            inputGetters         = mapping.ToDictionary(m => m.Key, m => CreateGetter(deviceLookup, m.Value, GetDefaultValue(m.Key)));
            forceFeedbackSetters = config.ForceFeedbackMapping.Select(m => CreateSetter(deviceLookup, m)).ToList();
            foreach (var device in devices)
            {
                device.InputChanged += InputDeviceChanged;
                boundDevices.Add(device);
            }
        }
예제 #3
0
        private Func <double> CreateGetter(Dictionary <string, IInputDevice> deviceLookup, InputMapperCollection collection, double defaultValue)
        {
            var sources = collection.Mappers
                          .Where(m => deviceLookup.ContainsKey(m.Device))
                          .Select(m => deviceLookup[m.Device].FindSource(m.InputId))
                          .Where(s => s != null)
                          .ToArray();

            if (sources.Length == 0)
            {
                return(() => defaultValue);
            }
            return(() =>
            {
                return collection.GetValue(sources.Select(s => s.GetValue()));
            });
        }