/// <summary> /// Hat servers connection state changed /// </summary> private void OnHatConnectionChanged(object sender, HatConnectionEventArgs e) { switch (e.State) { case HatConnectionState.Discovered: { if (!DevicesListContainsServer(e.HostName)) { var newListViewItem = new ListViewItem(new string[4] { e.HostName, e.IpAddress, e.BoardId.ToString(), e.SampleRate.ToString() }); newListViewItem.Tag = e.HostName; Invoke(new Action(() => listViewDevices.Items.Add(newListViewItem))); } } break; case HatConnectionState.Lost: { var client = BrainHatServers.GetHatClient(e.HostName); if (client != null) { if (OpenForms.ContainsKey(e.HostName)) { OpenForms.TryRemove(e.HostName, out var form); Invoke(new Action(() => form.Close())); } Invoke(new Action(() => { foreach (var nextItem in listViewDevices.Items) { if (nextItem is ListViewItem item && item.Tag.ToString() == e.HostName) { listViewDevices.Items.Remove(item); break; } } })); } else { // todo log it } } break; } }
async void OnHatConnectionChanged(object sender, HatConnectionEventArgs e) { if (IsConnected) { switch (e.State) { case HatConnectionState.Lost: { if (e.HostName == HostName) { await StopMonitorForServer(); await StartLightFlash(); } } break; } } }