private void DeviceTypeChanged(object o, EventArgs e) { FeatherBoard f = (FeatherBoard)o; Application.Current.Dispatcher.BeginInvoke(new Action(() => this.ServerConnectDevicesObservableCollection.Remove(f))); Application.Current.Dispatcher.BeginInvoke(new Action(() => this.ClientConnectDevicesObservableCollection.Remove(f))); Application.Current.Dispatcher.BeginInvoke(new Action(() => this.UnknownConnectDevicesObservableCollection.Remove(f))); AddArduino(f); }
private void SetupDevicesAndCollectionsAsync(ArduinoManager am) { foreach (Arduino a in am.ConnectedDevices) { FeatherBoard f = new FeatherBoard(a); f.TypeChanged += DeviceTypeChanged; AddArduino(f); } am.DeviceAdded += DeviceAdded; am.DeviceRemoved += DeviceRemoved; }
private void AddArduino(FeatherBoard f) { f.TypeChanged += DeviceTypeChanged; if (f.DeviceType == Values.DeviceTypes.Unknown) { Application.Current.Dispatcher.BeginInvoke(new Action(() => this.UnknownConnectDevicesObservableCollection.Add(f))); } else if (f.DeviceType == Values.DeviceTypes.Server) { f.ClientsCollection = MoteObservableCollection; Application.Current.Dispatcher.BeginInvoke(new Action(() => this.ServerConnectDevicesObservableCollection.Add(f))); } else { Application.Current.Dispatcher.BeginInvoke(new Action(() => this.ClientConnectDevicesObservableCollection.Add(f))); } }
private FeatherBoard FindFeatheBoard(Arduino a) { FeatherBoard f = null; var s = ServerConnectDevicesObservableCollection.Where(x => x.Arduino == a).ToList(); var c = ClientConnectDevicesObservableCollection.Where(x => x.Arduino == a).ToList(); var u = UnknownConnectDevicesObservableCollection.Where(x => x.Arduino == a).ToList(); if (s.Count != 0) { f = s[0]; } else if (c.Count != 0) { f = c[0]; } else if (u.Count != 0) { f = u[0]; } return(f); }
private void DeviceRemoved(object o, EventArgs e) { FeatherBoard f = FindFeatheBoard((Arduino)o); if (f == null) { return; } if (f.DeviceType == Values.DeviceTypes.Unknown) { Application.Current.Dispatcher.BeginInvoke(new Action(() => this.UnknownConnectDevicesObservableCollection.Remove(f))); } else if (f.DeviceType == Values.DeviceTypes.Server) { Application.Current.Dispatcher.BeginInvoke(new Action(() => this.ServerConnectDevicesObservableCollection.Remove(f))); } else { Application.Current.Dispatcher.BeginInvoke(new Action(() => this.ClientConnectDevicesObservableCollection.Remove(f))); } }
private void DeviceAdded(object o, EventArgs e) { FeatherBoard f = new FeatherBoard((Arduino)o); AddArduino(f); }