private async void Connection_Click(object sender, RoutedEventArgs e) { // If currently connected then disconnected if (_bleDevice != null) { await Disconnect(); } else { _bleDevice = DevicesDropdown.SelectedItem as BLE_Device; // Try and connect Connecting = true; if (await _bleDevice.Connect()) { NotifyPropertyChanged("IsConnected"); _bleDevice.ResponseStringEventOccurred += Device_ResponseStringEventOccurred; // Set initial brightness await _bleDevice.SendChannelString("{\"BRIGHTNESS\", 15}"); // Retrieve animations stored on the device await _bleDevice.SendChannelString("{\"CMD\", \"ENUMERATE\"}"); } else { // A coonection error occurred so flash an appropriate message to the user Connecting = false; Storyboard sbFlashConnectionError = this.Resources["FlashConnectionError"] as Storyboard; sbFlashConnectionError.Begin(); } Connecting = false; } }
private async void BrightnessTimer_Tick(object sender, EventArgs e) { _brightnessTimer.Stop(); if (_bleDevice != null) { await _bleDevice.SendChannelString("{\"BRIGHTNESS\", " + CurrentBrightness + "}"); } }
private async void AnimationPlay_Click(object sender, RoutedEventArgs e) { var button = (Button)sender; string animationName = button.DataContext as string; await _bleDevice.SendChannelString("{\"PLAY\", \"" + animationName + "\"}"); }