Beispiel #1
0
        public static List <ArduinoController> ListDevices()
        {
            var ret   = new List <ArduinoController>();
            var ports = SerialPortInfo.GetPorts();

            foreach (var entry in ConfigManager.ArduinoMapping)
            {
                var port = ports.FirstOrDefault(p => p.Name == entry.Key && p.IsConnected);
                if (port != null)
                {
                    switch (entry.Value)
                    {
                    case ControllerType.SNES:
                        ret.Add(new ArduinoSnes(port));
                        break;

                    case ControllerType.N64:
                        ret.Add(new ArduinoN64(port));
                        break;

                    case ControllerType.NGC:
                        ret.Add(new ArduinoNgc(port));
                        break;
                    }
                }
            }
            return(ret);
        }
        public void LoadFrom(XmlNode xn)
        {
            MappedType = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["type"].Value, true);
            Source     = (SourceType)Enum.Parse(typeof(SourceType), xn.Attributes["source"].Value, true);
            UUID       = xn.Attributes["uuid"] != null?Guid.Parse(xn.Attributes["uuid"].Value) : Guid.NewGuid();

            if (Source == SourceType.RawInput)
            {
                VendorID    = int.Parse(xn.Attributes["vid"].Value, NumberStyles.HexNumber);
                ProductID   = int.Parse(xn.Attributes["pid"].Value, NumberStyles.HexNumber);
                ReportHash  = uint.Parse(xn.Attributes["rpt_hash"].Value);
                DeviceIndex = int.Parse(xn.Attributes["idx"].Value);
            }
            else if (Source == SourceType.XInput)
            {
                DeviceIndex = int.Parse(xn.Attributes["idx"].Value);
            }
            else if (Source == SourceType.MUNIA)
            {
                DevicePath = xn.Attributes["devicepath"].Value;
            }
            else if (Source == SourceType.Arduino)
            {
                string port = xn.Attributes["arduino_port"].Value;
                ArduinoPort = SerialPortInfo.GetPorts().FirstOrDefault(spi => spi.Name == port) ?? new SerialPortInfo {
                    Name = port
                };
                ArduinoSource = (ControllerType)Enum.Parse(typeof(ControllerType), xn.Attributes["arduino_type"].Value, true);
            }

            foreach (XmlNode n in xn["buttons"].ChildNodes)
            {
                var btn = new ButtonMap();
                btn.LoadFrom(n);
                ButtonMaps.Add(btn);
            }

            foreach (XmlNode n in xn["axes"].ChildNodes)
            {
                var axis = new AxisMap();
                axis.LoadFrom(n);
                AxisMaps.Add(axis);
            }

            foreach (XmlNode n in xn["buttons_to_axis"].ChildNodes)
            {
                var button = new ButtonToAxisMap();
                button.LoadFrom(n);
                ButtonToAxisMaps.Add(button);
            }

            foreach (XmlNode n in xn["axis_to_buttons"].ChildNodes)
            {
                var axis = new AxisToButtonMap();
                axis.LoadFrom(n);
                AxisToButtonMaps.Add(axis);
            }
        }
        public SerialPortDataSource(string portname, int baudrate)
        {
            var ports = SerialPortInfo.GetPorts();

            PortInfo = ports.FirstOrDefault(p => p.Name == portname) ?? new SerialPortInfo {
                Name        = portname,
                Description = "Disconnected device"
            };
            BaudRate = baudrate;
        }
        public static List <ArduinoController> ListDevices()
        {
            var ret   = new List <ArduinoController>();
            var ports = SerialPortInfo.GetPorts();

            foreach (var entry in ConfigManager.ArduinoMapping)
            {
                var port = ports.FirstOrDefault(p => p.Name == entry.Key);
                if (port != null && entry.Value != ControllerType.None)
                {
                    ret.Add(CreateDevice(port, entry.Value));
                }
            }
            return(ret);
        }
Beispiel #5
0
        private void UpdateDeviceSources(string selectPort = null)
        {
            var selected = cbSerialPort.SelectedItem;

            cbSerialPort.Items.Clear();
            var ports = SerialPortInfo.GetPorts().ToArray();

            cbSerialPort.Items.AddRange(ports);
            // keep currently selected if still exists
            if (ports.Contains(selected))
            {
                cbSerialPort.SelectedItem = selected;
            }
            // else select newly arrived port
            else
            {
                cbSerialPort.SelectedItem = ports.FirstOrDefault(p => p.Name.Equals(selectPort));
            }
        }
Beispiel #6
0
        private void RefreshListbox()
        {
            lbSerialPorts.Items.Clear();
            var ports = SerialPortInfo.GetPorts().ToList();

            foreach (var spi in ports)
            {
                lbSerialPorts.Items.Add(spi);
            }
            foreach (var entry in Mapping)
            {
                // if port was mapped, but now unavailable, don't hide the original mapping
                if (ports.All(p => p.Name != entry.Key))
                {
                    lbSerialPorts.Items.Add(new SerialPortInfo {
                        Name = entry.Key, Description = "Unavailable"
                    });
                }
            }
            if (!ports.Any() && !Mapping.Any())
            {
                lbSerialPorts.Items.Add("None available");
            }
        }
Beispiel #7
0
 private bool IsPresent()
 {
     return(!string.IsNullOrEmpty(portName) && SerialPortInfo.GetPorts().Any(p => p.Name == portName));
 }