Ejemplo n.º 1
0
 public void UpdateInfo(BLEDeviceInfo bLEScanDeviceInfo)
 {
     DeviceNameText.text = bLEScanDeviceInfo.DeviceName;
     MACAddressText.text = bLEScanDeviceInfo.MacAddress;
     RssiText.text       = bLEScanDeviceInfo.Rssi;
     SetRssiFill(bLEScanDeviceInfo.Rssi);
     BLEscaninfo = bLEScanDeviceInfo;
 }
Ejemplo n.º 2
0
 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");
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public void A2DPListen(bool isConnected, BLEDeviceInfo bLEDeviceInfo)
 {
     if (!isConnected)
     {
         A2DPText.text = "  A2DP(连接的音频蓝牙) : 未连接";
     }
     else
     {
         A2DPText.text = "  A2DP(连接的音频蓝牙) : " + bLEDeviceInfo.DeviceName + " Address:" + bLEDeviceInfo.MacAddress;
     }
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 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);
     }
 }
Ejemplo n.º 7
0
 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);
     }
 }
Ejemplo n.º 8
0
 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;
     }
 }
Ejemplo n.º 9
0
        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
            }
        }
Ejemplo n.º 10
0
 public void A2DPListen(bool isConnect, BLEDeviceInfo A2DPInfo)
 {
     isConnectA2DPBlue     = isConnect;
     ConnectedA2DPBlueInfo = A2DPInfo;
     A2DPListener?.Invoke(isConnect, A2DPInfo);
 }