예제 #1
0
 public void Back()
 {
     for (int i = CharacterParent.childCount - 1; i >= 0; i--)
     {
         DestroyImmediate(CharacterParent.GetChild(i).gameObject);
     }
     writeCharacterInfo = null;
     bLEExample.DeviceInfoBackScan();
 }
예제 #2
0
 public void OnDiscoveryCharacteristic(CharacteristicInfo characterInfo)
 {
     Debug.Log("搜索到Character:" + characterInfo.UUID + " 所属Service:" + characterInfo.ServiceUUID +
               " 是否可读:" + characterInfo.CanRead + " 是否可写:" + characterInfo.CanWrite + " 是否可Notify:" + characterInfo.CanNotify);
     Instantiate(CharacterPrefab, CharacterParent).AddComponent <DeviceInfoCharacter>().Init(characterInfo, bLEExample);
     if (characterInfo.CanWrite)
     {
         writeCharacterInfo = characterInfo;
     }
 }
예제 #3
0
 public void Init(CharacteristicInfo characteristicInfo, BLEExample bLEExample)
 {
     this.characteristicInfo = characteristicInfo;
     this.bLEExample         = bLEExample;
     transform.GetChild(0).GetComponent <Text>().text             = characteristicInfo.ServiceUUID;
     transform.GetChild(0).GetChild(0).GetComponent <Text>().text = characteristicInfo.UUID;
     transform.GetChild(3).GetComponent <Button>().onClick.AddListener(() =>
     {
         this.bLEExample.DeviceInfoToCharacterInfo(characteristicInfo);
     });
 }
예제 #4
0
        public void Init(CharacteristicInfo characteristicInfo)
        {
            this.characteristicInfo = characteristicInfo;
            ServiceUUID.text        = characteristicInfo.ServiceUUID;
            CharacterUUID.text      = characteristicInfo.UUID;
            string operationStr = "";

            DeviceName.text = characteristicInfo.bLEDeviceInfo.DeviceName;

            if (characteristicInfo.CanRead)
            {
                operationStr += "Read";
                ReadBtn.SetActive(true);
            }
            else
            {
                ReadBtn.SetActive(false);
            }
            if (characteristicInfo.CanWrite)
            {
                if (operationStr != "")
                {
                    operationStr += ",";
                }
                operationStr += "Write";
                WriteObj.SetActive(true);
                writeDefault.SetActive(true);
                if (characteristicInfo.CanNotify || characteristicInfo.CanRead)
                {
                    ReadTrans.gameObject.SetActive(true);
                    readDefault.SetActive(true);
                    //设置位置,有写位置则要下移
                    ReadTrans.anchoredPosition = new Vector2(8.5f, -620);
                }
                else
                {
                    ReadTrans.gameObject.SetActive(false);
                    readDefault.SetActive(false);
                }
            }
            else
            {
                WriteObj.SetActive(false);
                writeDefault.SetActive(false);
                if (characteristicInfo.CanNotify || characteristicInfo.CanRead)
                {
                    ReadTrans.gameObject.SetActive(true);
                    readDefault.SetActive(true);
                    //设置位置,没有写位置则要上移
                    ReadTrans.anchoredPosition = new Vector2(8.5f, -370);
                }
                else
                {
                    ReadTrans.gameObject.SetActive(false);
                    readDefault.SetActive(false);
                }
            }
            if (characteristicInfo.CanNotify)
            {
                if (operationStr != "")
                {
                    operationStr += ",";
                }
                operationStr += "Notify";
                //默认订阅,底层会防止多次订阅
                BLEManager.Instance.NotifyCharacteristic(characteristicInfo, NotifyInitResult, NotifyInfoCallback);
            }
            else
            {
                NotifyBtn.SetActive(false);
            }
            OperationText.text = operationStr;
        }
예제 #5
0
 public void Init(CharacteristicInfo characteristicInfo, BLEExample bLEExample)
 {
     this.characteristicInfo = characteristicInfo;
     this.bLEExample         = bLEExample;
 }
예제 #6
0
 public void DeviceInfoToRecord(CharacteristicInfo characteristicInfo)
 {
     DeviceInfoPage.SetActive(false);
     RecordPage.SetActive(true);
     RecordPage.GetComponent <BlueRecord>().Init(characteristicInfo, this);
 }
예제 #7
0
 public void DiscoveryCharacteristic(CharacteristicInfo characterInfo)
 {
     deviceInfo.OnDiscoveryCharacteristic(characterInfo);
 }
예제 #8
0
 public void DeviceInfoToCharacterInfo(CharacteristicInfo characteristicInfo)
 {
     CharacterInfoPage.SetActive(true);
     DeviceInfoPage.SetActive(false);
     CharacterInfoPage.GetComponent <CharacterInfo>().Init(characteristicInfo);
 }
예제 #9
0
 /// <summary>
 /// 写数据
 /// </summary>
 /// <param name="characteristicInfo"></param>
 /// <param name="writeEvent"></param>
 /// <param name="deltaTime">一次只能发送20字节,超20字节会分次发送,deltaTime为分次发送间的间隔,一般是20-40毫秒</param>
 public void WriteCharacteristic(CharacteristicInfo characteristicInfo, string SendData, Action <bool, string, string> writeEvent, int deltaTime = 30)
 {
     WriteCharacteristic(characteristicInfo.bLEDeviceInfo.MacAddress, characteristicInfo.ServiceUUID,
                         characteristicInfo.UUID, SendData, writeEvent, deltaTime);
 }
예제 #10
0
 public void UnNotifyCharacteristic(CharacteristicInfo characteristicInfo, Action <bool, string> notifyEvent)
 {
     UnNotifyCharacteristic(characteristicInfo.bLEDeviceInfo.MacAddress, characteristicInfo.ServiceUUID,
                            characteristicInfo.UUID, notifyEvent);
 }
예제 #11
0
 public void ReadCharacteristic(CharacteristicInfo characteristicInfo, Action <bool, BLEDeviceInfo, string> ReadEvent)
 {
     ReadCharacteristic(characteristicInfo.bLEDeviceInfo.MacAddress, characteristicInfo.ServiceUUID, characteristicInfo.UUID, ReadEvent);
 }
예제 #12
0
 public void Init(CharacteristicInfo characteristicInfo, string sendMsg)
 {
     this.characteristicInfo = characteristicInfo;
     this.sendMsg            = sendMsg;
     transform.GetComponent <Button>().onClick.AddListener(ReWrite);
 }