public void Stop() { BleDeviceWatcher.Stop(); }
/// <summary> /// Public Standard Constructor /// Initializes the UI, watcher, wsServer, wsVibration and corresponding callback methods /// Searches for ble devices and the server /// </summary> public MainWindow() { InitializeComponent(); watcher = new BleDeviceWatcher(); wsServer = new WebSocketServer("ws://127.0.0.1"); // Intercept ServerFound event from watcher watcher.ServerFound += (device) => { // save server to espServer espServer = device; // Use Dispatcher to acces UI thread Dispatcher.Invoke(() => { blestatus.Foreground = Brushes.Green; blestatus.Text = $"Verbunden mit {espServer.Name}"; }); // Stop watcher because server is found watcher.Stop(); // Use Dispatcher to acces UI thread Dispatcher.Invoke(() => { wssstatus.Foreground = Brushes.Yellow; wssstatus.Text = "Starte Websocket Server..."; }); wsVibration = new VibrationWebsocket(device); // Intercept ClientConnected event from wsVibration wsVibration.ClientConnected += () => { // Use Dispatcher to access UI thread Dispatcher.Invoke(() => { wssstatus.Text = "Client ist verbunden"; DisableTest(); }); }; // Intercept ClientDisconnected event from wsVibration wsVibration.ClientDisconnected += () => { // User Dispatcher to access UI thread Dispatcher.Invoke(() => { wssstatus.Text = "Client nicht verbunden"; EnableTest(); }); }; // Add wsVibration service to the wsServer wsServer.AddWebSocketService("/vibrate", () => { return(wsVibration); }); wsServer.Start(); // If server was successfully started if (wsServer.IsListening) { // Use Dispatcher to access UI thread Dispatcher.Invoke(() => { wssstatus.Foreground = Brushes.Green; wssstatus.Text = $"Websocket hört auf {wsServer.Address}:{wsServer.Port}"; DisableConnect(); EnableTest(); }); } // If server wasn't successfully started else { // Use Dispatcher to access UI thread Dispatcher.Invoke(() => { wssstatus.Foreground = Brushes.Red; wssstatus.Text = "Es ist ein Fehler aufgetreten"; }); } }; }
public void Start() { BleDeviceWatcher.Start(); }