void OnGUI() { if (BTHelper == null) { return; } BTHelper.DrawGUI(); if (!BTHelper.isConnected()) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Connect")) { if (BTHelper.isDevicePaired()) { BTHelper.Connect(); // tries to connect } } } if (BTHelper.isConnected()) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect")) { BTHelper.Disconnect(); } } }
//Call this function to emulate message receiving from bluetooth while debugging on your PC. void OnGUI() { if (bluetoothHelper != null) { bluetoothHelper.DrawGUI(); } else { return; } if (bluetoothHelper.isConnected()) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect")) { bluetoothHelper.Disconnect(); sphere.GetComponent <Renderer>().material.color = Color.blue; } } if (bluetoothHelper.isConnected()) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Send text")) { //bluetoothHelper.SendData(new byte[] { 0, 1, 2, 3, 4 }); bluetoothHelper.SendData("Hi From unity"); } } }
void OnDestroy() { if (bluetoothHelper != null) { bluetoothHelper.Disconnect(); } }
void OnDestroy() { if (bluetoothHelper != null) { bluetoothHelper.Disconnect(); //Middletext.text = "Disconnected"; //IGConsole.Instance.Main.println("Disconnected"); } }
//Call this function to emulate message receiving from bluetooth while debugging on your PC. void OnGUI() { tmp = GUI.TextField(new Rect(Screen.width / 4, Screen.height / 10, Screen.width / 2, Screen.height / 10 - 10), tmp); if (bluetoothHelper != null) { bluetoothHelper.DrawGUI(); } else { return; } if (!bluetoothHelper.isConnected()) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Connect")) { if (bluetoothHelper.isDevicePaired()) { bluetoothHelper.Connect(); // tries to connect } else { write("Cannot connect, device is not found, for bluetooth classic, pair the device\n\tFor BLE scan for nearby devices"); } } } if (bluetoothHelper.isConnected()) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect")) { bluetoothHelper.Disconnect(); write("Disconnected"); } if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Turn On")) { bluetoothHelper.SendData("O"); write("Sending O"); } if (GUI.Button(new Rect(Screen.width / 2 + Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Turn Off")) { bluetoothHelper.SendData("F"); write("Sending F"); } } }
private void OnDestroy() { if (connectBT == true) { helper.Disconnect(); // old stopListening } }
public void Disconnect() { if (m_Helper != null) { m_Helper.Disconnect(); } }
void Start() { Btn_Connect.onClick.AddListener(() => { if (bluetoothHelper.isDevicePaired()) { Debug.Log("try to connect"); bluetoothHelper.Connect(); // tries to connect } else { Debug.Log("not DevicePaired"); } }); Btn_Disconnect.onClick.AddListener(() => { bluetoothHelper.Disconnect(); Debug.Log("try to Disconnect"); }); //============================================================================================= //============================================================================================= deviceName = "AR"; //bluetooth should be turned ON; // 페어링되는 아두이노 블루투스 이름과 같아야 합니다. //============================================================================================= //============================================================================================= try { bluetoothHelper = BluetoothHelper.GetInstance(deviceName); bluetoothHelper.OnConnected += OnConnected; bluetoothHelper.OnConnectionFailed += OnConnectionFailed; bluetoothHelper.OnDataReceived += OnMessageReceived; //read the data bluetoothHelper.setTerminatorBasedStream("\n"); if (bluetoothHelper.isDevicePaired()) { Toggle_isDevicePaired.isOn = true; } else { Toggle_isDevicePaired.isOn = false; } } catch (Exception ex) { Toggle_isDevicePaired.isOn = false; Debug.Log(ex.Message); } }
/// <summary> /// This is called when the application is closed. Afterwards, the the device is disconnected. /// </summary> void OnDestroy() { if (bt != null) { // make microcontroller know that it is not connected to this mobile device an more SendData("closeBT"); bt.Disconnect(); } }
//Call this function to emulate message receiving from bluetooth while debugging on your PC. void OnGUI() { if (bluetoothHelper != null) { bluetoothHelper.DrawGUI(); } else { return; } if (!bluetoothHelper.isConnected()) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Connect")) { if (bluetoothHelper.isDevicePaired()) { bluetoothHelper.Connect(); // tries to connect } else { sphere.GetComponent <Renderer>().material.color = Color.magenta; } } } if (bluetoothHelper.isConnected()) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height - 2 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect")) { bluetoothHelper.Disconnect(); sphere.GetComponent <Renderer>().material.color = Color.blue; } } if (bluetoothHelper.isConnected()) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Send text")) { bluetoothHelper.SendData(new Byte[] { 0, 0, 85, 0, 85 }); // bluetoothHelper.SendData("This is a very long long long long text"); } } }
void OnGUI() { if (helper == null) { return; } if (!helper.isConnected() && !isScanning && !isConnecting) { if (GUI.Button(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Start Scanning")) { isScanning = helper.ScanNearbyDevices(); } if (devices != null && devices.First != null) { draw(); } } else if (!helper.isConnected() && isScanning) { GUI.TextArea(new Rect(Screen.width / 2 - Screen.width / 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Scanning..."); } else if (helper.isConnected()) { GUI.TextArea(new Rect(Screen.width / 4, 2 * Screen.height / 10, Screen.width / 2, 7 * Screen.height / 10), data); tmp = GUI.TextField(new Rect(Screen.width / 4, Screen.height / 10, Screen.width / 2, Screen.height / 10 - 10), tmp); if (GUI.Button(new Rect(3 * Screen.width / 4 + 10, Screen.height / 10, Screen.width / 5, Screen.height / 10), "Send")) { helper.SendData(tmp); data += "\n>" + tmp; tmp = ""; } if (GUI.Button(new Rect(3 * Screen.width / 4 + 10, 8 * Screen.height / 10, Screen.width / 5, Screen.height / 10), "Disconnect")) { helper.Disconnect(); } } }
void OnDestroy() { BTHelper.SendData("disable"); BTHelper.Disconnect(); }
public void DisconnectButtonClick() { bluetoothHelper.Disconnect(); LogWrite("Disconnected"); }