protected void OnPhotoDataChange(object sender, PropertyChangeArgs ph_dat) { if (PhotoDataChange != null) { PhotoDataChange(this, ph_dat); } }
void connection_changed(object sender, PropertyChangeArgs data) { if (bluetooth.Connected == true) { // Verbunden Status - evtl das Event in das Haupfenster einbinden für ein Symbol?? Debug.WriteLine("Verbunden!"); //Connection Detective aktivieren //bluetooth.connection_detective(true); Connect.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)delegate { Connect.Content = "Trennen"; Thread.Sleep(300); Close(); }); } else { //Gerät wurde getrennt -> Meldung ausgeben in allen Fenstern??? Debug.WriteLine("Verbindung getrennt!"); //bluetooth.connection_detective(false, 4000); Connect.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)delegate { Connect.Content = "Verbinden"; }); } }
protected void OnCommandControlChange(object sender, PropertyChangeArgs cc) { if (CommandControlChange != null) { CommandControlChange(this, cc); } }
protected void OnDeviceListChange(object sender, PropertyChangeArgs devl) { // Check if there are any Subscribers if (DeviceListChange != null) { // Call the Event DeviceListChange(this, devl); } }
protected void OnConnectedChange(object sender, PropertyChangeArgs conn) { // Check if there are any Subscribers if (ConnectionChange != null) { // Call the Event ConnectionChange(this, conn); } }
protected void OnPropertyChange(object sender, PropertyChangeArgs data) { // Check if there are any Subscribers if (PropertyChange != null) { // Call the Event PropertyChange(this, data); } }
//Bluetooth Control COmmands private void Event_Control_tetris(object sender, PropertyChangeArgs args) { String control = args.mesg; if (args.mesg.Length > 13) { return; } //Es könnten noch Probleme auftreten wegen "Taste gedrückt halten" - mit Kitzmüller besprechen try { switch (control) { case "down_click": { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => CentralMonitor_KeyDown(this, new KeyEventArgs(Keyboard.PrimaryDevice, hwnds, 0, Key.Down)) )); break; } case "left_click": { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => CentralMonitor_KeyDown(this, new KeyEventArgs(Keyboard.PrimaryDevice, hwnds, 0, Key.Left)) )); break; } case "right_click": { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => CentralMonitor_KeyDown(this, new KeyEventArgs(Keyboard.PrimaryDevice, hwnds, 0, Key.Right)))); break; } case "up_click": { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => CentralMonitor_KeyDown(this, new KeyEventArgs(Keyboard.PrimaryDevice, hwnds, 0, Key.Up)))); break; } } } catch (Exception ex) { } }
private void Event_Photo_Data(object sender, PropertyChangeArgs photo_data) { if (photo_data.ev_buffer != null) { try { byte[] photo_buffer = photo_data.ev_buffer; for (int i = 0; i < photo_data.ev_buffer.Length; i++) { if (index < 68 * 42 * 4) { bitmap_buffer[index] = photo_buffer[i]; index++; } else { try { WriteableBitmap bmp_foto = BitmapFactory.New(68, 42).FromByteArray(bitmap_buffer); Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { drawlayer = bmp_foto; monitor.Blit(new Rect(new Size(68, 42)), drawlayer, new Rect(new Size(68, 42))); })); break; } catch (System.Exception e) { } } } } catch (Exception exc) { } } }
private void Bluetooth_Command_Listener(object sender, PropertyChangeArgs command) { try { int Mode = -1; string comm = command.mesg; System.Diagnostics.Debug.WriteLine("Command wurde übergeben: " + comm); switch (comm) { case "Paint": //Paint { Mode = 0; Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)delegate { if (tetris != null) { tetris.Stop_Tetris(); monitor = BitmapFactory.New(68, 42); monitorImg.Source = monitor; } runningTask = RunningTask.Draw; drawAccept = true; if (video != null) video.RunVideo = false; if (webcam != null) webcam.closeWebcam(); try { draw = new Draw(drawlayer, monitorImg, monitor); } catch (Exception exc) { } ex_eff = draw.Draw_execute; draw.setColor = Color.FromArgb(0, 200, 0, 255); draw.setDrawtype = Drawtype.point; Binding ColorBinding = new Binding("setColor"); ColorBinding.Source = draw; ColorBinding.Mode = BindingMode.TwoWay; DrawingColorPicker.SetBinding(Xceed.Wpf.Toolkit.ColorCanvas.SelectedColorProperty, ColorBinding); SetUserControls(); //object GlassOfSugar = new Object(); //Slider slider = new Slider(); //Binding AmountBinding = new Binding("Amount"); ////AmountBinding.Source = GlassOfSugar; ////AmountBinding.Mode = BindingMode.TwoWay; //slider.SetBinding(Slider.ValueProperty, AmountBinding); }); break; } case "Fotobearbeitung": //Pixelated Picture { Mode = 1; Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)delegate { if (tetris != null) { tetris.Stop_Tetris(); monitor = BitmapFactory.New(68, 42); monitorImg.Source = monitor; } runningTask = RunningTask.Draw; drawAccept = true; if (video != null) video.RunVideo = false; if (webcam != null) webcam.closeWebcam(); try { draw = new Draw(drawlayer, monitorImg, monitor); } catch (Exception exc) { } ex_eff = draw.Draw_execute; draw.setColor = Color.FromArgb(0, 200, 0, 255); draw.setDrawtype = Drawtype.point; Binding ColorBinding = new Binding("setColor"); ColorBinding.Source = draw; ColorBinding.Mode = BindingMode.TwoWay; DrawingColorPicker.SetBinding(Xceed.Wpf.Toolkit.ColorCanvas.SelectedColorProperty, ColorBinding); SetUserControls(); //object GlassOfSugar = new Object(); //Slider slider = new Slider(); //Binding AmountBinding = new Binding("Amount"); //AmountBinding.Source = GlassOfSugar; //AmountBinding.Mode = BindingMode.TwoWay; //slider.SetBinding(Slider.ValueProperty, AmountBinding); }); break; } case "Tetris": //Tetris { Mode = 2; Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)delegate { if (webcam != null) webcam.closeWebcam(); runningTask = RunningTask.Tetris; drawAccept = false; //Versuchsweise eingebaut -> dt_m.Tick ist fehlerquelle -.- -> sollte eigentlich nicht sein //dt_m.IsEnabled = false; if (tetris == null) { monitor = BitmapFactory.New(68, 42); monitorImg.Source = monitor; tetris = new TetrisExecute(monitor, monitorTimer, AuroraWindow); ex_eff = tetris.tetris_exe; Binding ScoreBinding = new Binding("Score"); ScoreBinding.Mode = BindingMode.OneWay; ScoreBinding.Source = tetris.t; Points.SetBinding(Label.ContentProperty, ScoreBinding); Binding LevelBinding = new Binding("Level"); LevelBinding.Mode = BindingMode.OneWay; LevelBinding.Source = tetris.t; Level.SetBinding(Label.ContentProperty, LevelBinding); } else { tetris.Stop_Tetris(); tetris = new TetrisExecute(monitor, monitorTimer, AuroraWindow); ex_eff = tetris.tetris_exe; Binding ScoreBinding = new Binding("Score"); ScoreBinding.Mode = BindingMode.TwoWay; ScoreBinding.Source = tetris.t; Points.SetBinding(Label.ContentProperty, ScoreBinding); } SetUserControls(); }); break; } default: { //hier wäre normalerweise ein switch(mode) -> unnötig? break; } } } catch (Exception exc) { } }
//void commca(object sender, PropertyChangeArgs data) //{ // string command = data.mesg; //} void scan_finished(object sender, PropertyChangeArgs data) { found_devices = data.liste; //Clear Devices Devices.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)delegate { Devices.Items.Clear(); }); //Found Devices foreach (String str in found_devices) { Devices.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)delegate { Devices.Items.Add(str); Devices.SelectedItem = Devices.Items[0]; }); } ProgressRing.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)delegate { ProgressRing.IsActive = false; ProgressRing.Visibility = Visibility.Collapsed; }); //Known Devices List<String> known_dev = bluetooth.get_known_devices(); foreach (String str in known_dev) { Devices.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (ThreadStart)delegate { Devices.Items.Add(str); Devices.SelectedItem = Devices.Items[0]; }); } }
private void Event_Paint_Handler(object sender, PropertyChangeArgs args) { try { byte[] buffer = new byte[50000]; string data = args.mesg; if (data == "Tetris") // Alle Hauptbefehle hier unterbringen { data_Stream = ""; bluetooth.CommandControlChange -= new Bluetooth.PropertyChangeHandler(Event_Paint_Handler); bluetooth.PhotoDataChange -= new Bluetooth.PropertyChangeHandler(Event_Photo_Data); return; } if (data == "Paint") { bluetooth.PhotoDataChange -= new Bluetooth.PropertyChangeHandler(Event_Photo_Data); Draw_Mode = 1; //wird nur beim wechseln aufgerufen? data_Stream = ""; } if (data == "Fotobearbeitung") { bluetooth.PhotoDataChange += new Bluetooth.PropertyChangeHandler(Event_Photo_Data); //bluetooth.CommandControlChange -= new Bluetooth.PropertyChangeHandler(Event_Paint_Handler); Draw_Mode = 2; data_Stream = ""; data = ""; } //if (data == "Fertig") //Das Übertragen der Fotodaten wurde abgeschlossen //{ // try // { // WriteableBitmap bmp_foto = BitmapFactory.New(68, 42).FromByteArray(bitmap_buffer); // Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => wh = bmp_foto)); // } // catch (Exception exc) // { // } //} //i = 0; //neue Bitmap anlegen!! ////daten aus dem Stream in ein Byte Array //string[] data_buffer = new string[68*42*3]; //char[] separator = {' '}; //data_buffer = data_Stream.Split(separator,StringSplitOptions.RemoveEmptyEntries); //Neuer Ansatz: //Zuerst wird "Fotobearbeitung" als String gesendet und in der Bluetooth Klasse dementsprechend weitergeleitet, da dies dort konvertiert wird. //Dann sollen Android seitig die Bilddaten als BYTES gesendet werden, ohne konvertierung. //Diese Daten werden dann in Bluetooth.Read konvertiert in Strings, was jedoch nur Kauderwelsch ist. //Diese Daten werden an den aktuellen modus (Fotobearbeitung) weitergeleitet, wo sie als String in einen großen String gespeichert werden //Am Ende des sendens wird wieder ein String ("Fertig") gesendet //Mit diesem String beginnt die Konvertierung der String Daten zurück in byte Form. //Diese Bytes werden in ein großes Array geschrieben und an das Bitmap übergeben. //buffer = Encoding.ASCII.GetBytes(data_Stream); //try //{ //WriteableBitmap bmp_foto = BitmapFactory.New(0, 0).FromByteArray(buffer); //Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => wh = bmp_foto)); //} //catch(Exception exc) //{ //} //} //Paint if(Draw_Mode == 1) { //Überprüfung, ob das Argument eine Zahl ist - > eventuell sollte man dies durch eine Modus Abfrage MainWindow seitig ersetzen //string Str = args.mesg.Split(' ')[0]; //double Num = 0; //bool isNum = double.TryParse(Str, out Num); --> wirft noch einen Fehler? bool isNum = true; if (isNum) { int draw_pos_x = Convert.ToInt16(data.Split(' ')[0]); int draw_pos_y = Convert.ToInt16(data.Split(' ')[1]); int draw_col_r = Convert.ToInt32(data.Split(' ')[2]); int draw_col_g = Convert.ToInt32(data.Split(' ')[3]); int draw_col_b = Convert.ToInt32(data.Split(' ')[4]); //byte draw_col_b = 100; setDrawtype = Drawtype.point; if (draw_pos_x < 68) { mousepos.X = draw_pos_x; } if (draw_pos_y < 42) { mousepos.Y = draw_pos_y; } if ((draw_col_r < 256) && (draw_col_g < 256) && (draw_col_b < 256)) { try { byte r = Convert.ToByte(draw_col_r); byte g = Convert.ToByte(draw_col_g); byte b = Convert.ToByte(draw_col_b); Color draw_col = Color.FromRgb(r, g, b); Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { drawlayer.SetPixel((int)mousepos.X, (int)mousepos.Y, draw_col); monitor.Blit(new Rect(new Size(68, 42)), drawlayer, new Rect(new Size(68, 42))); drawlayer.Blit(new Rect(new Size(68, 42)), monitor, new Rect(new Size(68, 42))); })); } catch (Exception ex) { string excep = ex.ToString(); } } } } ////Fotobearbeitung //if (Draw_Mode == 2) //{ //Versuchsewise unperfomante Variante - eventuell zur performanteren Variante mit Stringbuilder wechseln!! //Verzögerungen können jedoch nur schwer festgestellt werden. //data_Stream = data_Stream + data; //buffer[i] = Convert.ToByte(data); //Neuer Ansatz - ARGB werden getrennt vom ANdroid Device gesendet // i++; //} } catch (Exception exc) { } }
private void Event_Paint_Handler(object sender, PropertyChangeArgs args) { try { byte[] buffer = new byte[50000]; string data = args.mesg; if (data == "Tetris") // Alle Hauptbefehle hier unterbringen { data_Stream = ""; bluetooth.CommandControlChange -= new Bluetooth.PropertyChangeHandler(Event_Paint_Handler); bluetooth.PhotoDataChange -= new Bluetooth.PropertyChangeHandler(Event_Photo_Data); return; } if (data == "Paint") { bluetooth.PhotoDataChange -= new Bluetooth.PropertyChangeHandler(Event_Photo_Data); Draw_Mode = 1; //wird nur beim wechseln aufgerufen? data_Stream = ""; } if (data == "Fotobearbeitung") { bluetooth.PhotoDataChange += new Bluetooth.PropertyChangeHandler(Event_Photo_Data); //bluetooth.CommandControlChange -= new Bluetooth.PropertyChangeHandler(Event_Paint_Handler); Draw_Mode = 2; data_Stream = ""; data = ""; } //if (data == "Fertig") //Das Übertragen der Fotodaten wurde abgeschlossen //{ // try // { // WriteableBitmap bmp_foto = BitmapFactory.New(68, 42).FromByteArray(bitmap_buffer); // Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => wh = bmp_foto)); // } // catch (Exception exc) // { // } //} //i = 0; //neue Bitmap anlegen!! ////daten aus dem Stream in ein Byte Array //string[] data_buffer = new string[68*42*3]; //char[] separator = {' '}; //data_buffer = data_Stream.Split(separator,StringSplitOptions.RemoveEmptyEntries); //Neuer Ansatz: //Zuerst wird "Fotobearbeitung" als String gesendet und in der Bluetooth Klasse dementsprechend weitergeleitet, da dies dort konvertiert wird. //Dann sollen Android seitig die Bilddaten als BYTES gesendet werden, ohne konvertierung. //Diese Daten werden dann in Bluetooth.Read konvertiert in Strings, was jedoch nur Kauderwelsch ist. //Diese Daten werden an den aktuellen modus (Fotobearbeitung) weitergeleitet, wo sie als String in einen großen String gespeichert werden //Am Ende des sendens wird wieder ein String ("Fertig") gesendet //Mit diesem String beginnt die Konvertierung der String Daten zurück in byte Form. //Diese Bytes werden in ein großes Array geschrieben und an das Bitmap übergeben. //buffer = Encoding.ASCII.GetBytes(data_Stream); //try //{ //WriteableBitmap bmp_foto = BitmapFactory.New(0, 0).FromByteArray(buffer); //Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => wh = bmp_foto)); //} //catch(Exception exc) //{ //} //} //Paint if (Draw_Mode == 1) { //Überprüfung, ob das Argument eine Zahl ist - > eventuell sollte man dies durch eine Modus Abfrage MainWindow seitig ersetzen //string Str = args.mesg.Split(' ')[0]; //double Num = 0; //bool isNum = double.TryParse(Str, out Num); --> wirft noch einen Fehler? bool isNum = true; if (isNum) { int draw_pos_x = Convert.ToInt16(data.Split(' ')[0]); int draw_pos_y = Convert.ToInt16(data.Split(' ')[1]); int draw_col_r = Convert.ToInt32(data.Split(' ')[2]); int draw_col_g = Convert.ToInt32(data.Split(' ')[3]); int draw_col_b = Convert.ToInt32(data.Split(' ')[4]); //byte draw_col_b = 100; setDrawtype = Drawtype.point; if (draw_pos_x < 68) { mousepos.X = draw_pos_x; } if (draw_pos_y < 42) { mousepos.Y = draw_pos_y; } if ((draw_col_r < 256) && (draw_col_g < 256) && (draw_col_b < 256)) { try { byte r = Convert.ToByte(draw_col_r); byte g = Convert.ToByte(draw_col_g); byte b = Convert.ToByte(draw_col_b); Color draw_col = Color.FromRgb(r, g, b); Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { drawlayer.SetPixel((int)mousepos.X, (int)mousepos.Y, draw_col); monitor.Blit(new Rect(new Size(68, 42)), drawlayer, new Rect(new Size(68, 42))); drawlayer.Blit(new Rect(new Size(68, 42)), monitor, new Rect(new Size(68, 42))); })); } catch (Exception ex) { string excep = ex.ToString(); } } } } ////Fotobearbeitung //if (Draw_Mode == 2) //{ //Versuchsewise unperfomante Variante - eventuell zur performanteren Variante mit Stringbuilder wechseln!! //Verzögerungen können jedoch nur schwer festgestellt werden. //data_Stream = data_Stream + data; //buffer[i] = Convert.ToByte(data); //Neuer Ansatz - ARGB werden getrennt vom ANdroid Device gesendet // i++; //} } catch (Exception exc) { } }
//Bluetooth Control COmmands private void Event_Control_tetris(object sender, PropertyChangeArgs args) { String control = args.mesg; if (args.mesg.Length > 13) { return; } //Es könnten noch Probleme auftreten wegen "Taste gedrückt halten" - mit Kitzmüller besprechen try { switch (control) { case "down_click": { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal,new Action(() => CentralMonitor_KeyDown(this, new KeyEventArgs(Keyboard.PrimaryDevice,hwnds, 0, Key.Down)) )); break; } case "left_click": { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => CentralMonitor_KeyDown(this, new KeyEventArgs(Keyboard.PrimaryDevice, hwnds, 0, Key.Left)) )); break; } case "right_click": { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => CentralMonitor_KeyDown(this, new KeyEventArgs(Keyboard.PrimaryDevice, hwnds, 0, Key.Right)))); break; } case "up_click": { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => CentralMonitor_KeyDown(this, new KeyEventArgs(Keyboard.PrimaryDevice, hwnds, 0, Key.Up)))); break; } } } catch (Exception ex) { } }