bool useRepetierprotocol = Settings.repetierProtocol; //Keep a cahced value of this setting because retrieving it every time would be to intensive public GCodeSender(BluetoothIO _bluetoothIO, GCodeResponseReciever _responseReciever, Dispatcher _dispatcher) { bluetoothIO = _bluetoothIO; responseReciever = _responseReciever; dispatcher = _dispatcher; waitingCommandList = new List <string>(); commandsInBuffer = new Dictionary <Int64, string>(); bytesInBuffer = new Dictionary <Int64, int>(); emptyBytes = new byte[32]; for (int i = 0; i < 32; i++) { emptyBytes[i] = 0; } responseReciever.OkRecieved += responseReciever_OkRecieved; responseReciever.ResendRecieved += responseReciever_ResendRecieved; bluetoothIO.ConnectedToDevice += bluetoothIO_ConnectedToDevice; commandSendingTimer = new Timer(new TimerCallback(this.sendWaitingCommands)); commandSendingTimer.Change(0, 0); Settings.repetierProtocolChangedEvent += (o) => { useRepetierprotocol = (bool)o; }; }
private void RefreshBtn_Click(object sender, EventArgs e) { // Disable the register scout button registerScoutBtn.Enabled = false; // Prepare the Bluetooth adapter if (!BluetoothIO.PrepareAdapter()) { // Show toast error message if the device doesn't have a Bluetooth adapter Toast.MakeText(this, BluetoothIO.NoAdapterMessage, ToastLength.Long); return; } // Update list of paired devices var adapter = BluetoothIO.Adapter; adapter.StartDiscovery(); devicesGroup.RemoveAllViews(); foreach (var d in adapter.BondedDevices) { var rb = new RadioButton(this) { Text = $"{d.Name} ({d.Address})", Tag = d.Address }; devicesGroup.AddView(rb); } // Cancel device discovery as it slows down a Bluetooth connection adapter.CancelDiscovery(); }
protected bool ConnectToScoutMaster() { // Prepare the Bluetooth adapter if (!BluetoothIO.PrepareAdapter()) { // Show toast error message if the device doesn't have a Bluetooth adapter Toast.MakeText(this, BluetoothIO.NoAdapterMessage, ToastLength.Long).Show(); return(false); } // Establish a connection to the scout master var connection = new ScoutConnection(BluetoothIO.Adapter); connection.Start(); // Add this connection to the list of Bluetooth connections BluetoothIO.ClearAllConnections(); BluetoothIO.Connections.Add(connection); return(true); }
BluetoothIO bluetoothIO;//The bluetoothio that we will be recieving meesages from /// <summary> /// Intitialises a new class that can respond to messages recieved from a bluetooth /// device connected to a bluetoothio instance /// </summary> /// <param name="_bluetoothIO">The bluetoothio that is connected to the device that will be sending us a message</param> public GCodeResponseReciever(BluetoothIO _bluetoothIO) { bluetoothIO = _bluetoothIO; bluetoothIO.RecievedMessage += bluetoothIO_RecievedMessage; }