public void UpdateInfo(BLEDeviceInfo bLEScanDeviceInfo) { DeviceNameText.text = bLEScanDeviceInfo.DeviceName; MACAddressText.text = bLEScanDeviceInfo.MacAddress; RssiText.text = bLEScanDeviceInfo.Rssi; SetRssiFill(bLEScanDeviceInfo.Rssi); BLEscaninfo = bLEScanDeviceInfo; }
public CharacteristicInfo(BLEDeviceInfo bLEDeviceInfo, string ServiceUUID, string uuid, string CanRead, string CanWrite, string CanNotify) { this.bLEDeviceInfo = bLEDeviceInfo; this.ServiceUUID = ServiceUUID; this.UUID = uuid; this.CanRead = CanRead.Equals("1"); this.CanWrite = CanWrite.Equals("1"); this.CanNotify = CanNotify.Equals("1"); }
public void NotifyInfoCallback(BLEDeviceInfo bLEDeviceInfo, string updateCharacteristic, string info) { readDefault.SetActive(false); GameObject obj = Instantiate(ValuePrefab, ValueParent) as GameObject; obj.GetComponent <Text>().text = DateTime.UtcNow.ToString() + ":\n" + info; readObj.Add(obj); Invoke("LayoutUpdate", 0.1f); }
public void A2DPListen(bool isConnected, BLEDeviceInfo bLEDeviceInfo) { if (!isConnected) { A2DPText.text = " A2DP(连接的音频蓝牙) : 未连接"; } else { A2DPText.text = " A2DP(连接的音频蓝牙) : " + bLEDeviceInfo.DeviceName + " Address:" + bLEDeviceInfo.MacAddress; } }
public void Init(BLEDeviceInfo bLEScanDeviceInfo, BLEExample bLEExample) { DeviceNameText = transform.GetChild(0).GetComponent <Text>(); MACAddressText = transform.GetChild(1).GetComponent <Text>(); RssiText = transform.GetChild(5).GetComponent <Text>(); RssiFillImg = transform.GetChild(3).GetComponent <Image>(); transform.GetChild(6).GetComponent <Button>().onClick.AddListener(ConnectDevice); rssiI = transform.GetChild(4).gameObject; UpdateInfo(bLEScanDeviceInfo); this.bLEExample = bLEExample; }
public void ScanDeviceEvent(BLEDeviceInfo bLEScanDeviceInfo) { if (scanDeviceDic.ContainsKey(bLEScanDeviceInfo.MacAddress)) { scanDeviceDic[bLEScanDeviceInfo.MacAddress].UpdateInfo(bLEScanDeviceInfo); } else { BLEScanDevice bLEScanDevice = Instantiate(DevicePre, DeviceParent).AddComponent <BLEScanDevice>(); bLEScanDevice.Init(bLEScanDeviceInfo, this); scanDeviceDic.Add(bLEScanDeviceInfo.MacAddress, bLEScanDevice); } }
public void ReadDataCallBack(bool isSuccess, BLEDeviceInfo bLEDeviceInfo, string data) { if (isSuccess) { readDefault.SetActive(false); GameObject obj = Instantiate(ValuePrefab, ValueParent) as GameObject; obj.GetComponent <Text>().text = DateTime.UtcNow.ToString() + ":\n" + data; obj.transform.SetSiblingIndex(ReadTrans.GetSiblingIndex() + 1); readObj.Add(obj); Invoke("LayoutUpdate", 0.1f); } else { bLEExample.TipPage.ShowTip("读取Characteristic错误:" + data, TipType.OneBnt); } }
public void BlueConnectStateListener(bool state, BLEDeviceInfo bLEScanDeviceInfo) { if (state) { if (bLEScanDeviceInfo.DeviceName.Equals(ConnectedBlueInfo.DeviceName) && bLEScanDeviceInfo.MacAddress.Equals(ConnectedBlueInfo.MacAddress)) { isConnectedBlue = state; ConnectListener?.Invoke(isConnectedBlue); ConnectListener = null; } } else { isConnectedBlue = false; ConnectedBlueInfo = null; ConnectListener?.Invoke(isConnectedBlue); DisconnectCallBack?.Invoke(); DisconnectCallBack = null; } }
public void ConnectBLE(BLEDeviceInfo bLEScanDeviceInfo, Action <bool> ConnectListener = null, Action <string> ServiceUUIDs = null, Action <CharacteristicInfo> CharacteristicUUIDs = null) { ConnectedBlueInfo = bLEScanDeviceInfo; this.ConnectListener = ConnectListener; if (bLEMsgHandler != null) { bLEMsgHandler.DiscoveyServiceUUID = ServiceUUIDs; bLEMsgHandler.CharacteristicUUID = CharacteristicUUIDs; } if (!Application.isEditor) { #if UNITY_ANDROID Debug.Log("unity请求连接蓝牙:" + (jo != null)); if (jo != null) { jo.Call("ConnectBLEByName", bLEScanDeviceInfo.DeviceName); } #elif UNITY_IPHONE iOSBluetoothLE.connectToPeripheral(bLEScanDeviceInfo.MacAddress); #endif } }
public void A2DPListen(bool isConnect, BLEDeviceInfo A2DPInfo) { isConnectA2DPBlue = isConnect; ConnectedA2DPBlueInfo = A2DPInfo; A2DPListener?.Invoke(isConnect, A2DPInfo); }