コード例 #1
0
    public static void subscribe()
    {
        if (!isConnected)
        {
            return;
        }
        BTLog = "readStart!\n";

        /*BTLog += linkData.address;
         * BTLog += BluetoothData.fullUUID(linkData.service);
         * BTLog += BluetoothData.fullUUID(linkData.rCharacteristic);*/
        BluetoothLEHardwareInterface.SubscribeCharacteristicWithDeviceAddress(
            linkData.address, BluetoothData.fullUUID(linkData.service), BluetoothData.fullUUID(linkData.rCharacteristic),
            (deviceAddress, notification) => {; },
            (deviceAddress2, characteristic, data) =>
        {
            if (deviceAddress2.CompareTo(linkData.address) == 0)                     //讀資料
            {
                if (data.Length > 0)
                {
                    string s = Encoding.UTF8.GetString(data);                             ///Byte to string
                    receiveText(s);
                }
            }
        });
    }
コード例 #2
0
    public void connect(string addr)
    {
        if (isConnected)
        {
            return;
        }
        BTStatus    = false;
        linkData    = new BluetoothData();
        isConnected = false;
        readFound   = false;
        writeFound  = false;
        BTLog       = "Connecting to \n" + addr + "\n";
        BluetoothLEHardwareInterface.ConnectToPeripheral(addr, (address) => {; },
                                                         (address, serviceUUID) => {; },
                                                         (address, serviceUUID, characteristicUUID) =>
        {
            // discovered characteristic
            if (BluetoothData.isEqual(serviceUUID, peripheralList[address].service))
            {
                isConnected      = true;
                linkData.name    = peripheralList[address].name;
                linkData.address = address;
                linkData.service = peripheralList[address].service;
                if (BluetoothData.isEqual(characteristicUUID, peripheralList[address].rCharacteristic))
                {
                    readFound = true;
                    linkData.rCharacteristic = peripheralList[address].rCharacteristic;
                    BTLog += "readTrue \n";
                }
                if (BluetoothData.isEqual(characteristicUUID, peripheralList[address].wCharacteristic))
                {
                    writeFound = true;
                    linkData.wCharacteristic = peripheralList[address].wCharacteristic;
                    BTLog += "writeTrue \n";
                }

                if (readFound && writeFound)
                {
                    Invoke("delayConnect", 1f);
                    BTLog  = address + "\n";
                    BTLog += "Connected! \n";
                }
                BluetoothLEHardwareInterface.StopScan();
            }
        },
                                                         (address) =>
        {
            // this will get called when the device disconnects
            // be aware that this will also get called when the disconnect
            // is called above. both methods get call for the same action
            // this is for backwards compatibility
        });
    }
コード例 #3
0
    public void ObjectSelect()
    {
        //this.gameObject.transform.localScale = new Vector3(20, 20, 20);
        //this.gameObject.transform.DORotate(new Vector3(0, 180f, 0), 3);
        //this.gameObject.GetComponent<MeshRenderer>().materials[0].color = Color.red;
        //this.gameObject.GetComponent<MeshRenderer>().materials[1].color = Color.red;

        if (corTimeCheck == null)
        {
            startTime = DateTime.Now;
            prevTime  = DateTime.Now;
            animator.SetTrigger("Over");
            corTimeCheck = StartCoroutine(CheckTimer());
        }

        if (prevTime.AddSeconds(0.01f) < DateTime.Now && corTimeCheck != null)
        {
            prevTime = DateTime.Now;
            StopCoroutine(corTimeCheck);
            corTimeCheck = StartCoroutine(CheckTimer());
        }

        if (corTimeCheck != null && startTime.AddSeconds(2.0f) < DateTime.Now)
        {
            Debug.Log("버튼 유지 완료");
            ResetButton();
            BluetoothData data = new BluetoothData();
            data.msg       = "";
            data.dataType  = SENDMSGTYPE.MENU;
            data.musicInfo = MUSICINFO.None;
            string dataMsg;

            if (this.gameObject.transform.parent.name == "ICON_NEXT")
            {
                Message.Send <MusicRequestMsg>(new MusicRequestMsg(MUSICINFO.MUSIC_NEXT, ""));
            }
            else if (this.gameObject.transform.parent.name == "ICON_STOP")
            {
                Message.Send <MusicRequestMsg>(new MusicRequestMsg(MUSICINFO.MUSIC_PAUSE, ""));
            }
            else if (this.gameObject.transform.parent.name == "ICON_PLAY")
            {
                Message.Send <MusicRequestMsg>(new MusicRequestMsg(MUSICINFO.MUSIC_PLAY, ""));
            }
            else if (this.gameObject.transform.parent.name == "ICON_BACKWARDS")
            {
                Message.Send <MusicRequestMsg>(new MusicRequestMsg(MUSICINFO.MUSIC_PREV, ""));
            }
        }
    }
コード例 #4
0
        //>> 2018-06-07 최진호 블루투스 통신

        /********************************************
         * 2018-06-07 최진호
         * msg : 블루투스로 전송할 메세지
         * 블루투스를 통해 연결된 단말기로 msg 전송
         *******************************************/

        public void BluetoothSendMsg(string msg, SENDMSGTYPE type, MUSICINFO musicInfo = MUSICINFO.None, Menu menu = Menu.None)
        {
            BluetoothData tempData = new BluetoothData();

            tempData.dataType  = type;
            tempData.msg       = msg;
            tempData.musicInfo = musicInfo;
            tempData.menu      = menu;

            string sendMsg = JsonUtility.ToJson(tempData);

            //_instance.AJO.Call("SendMsg", sendMsg);

            ListMsg.Add(sendMsg);
        }
コード例 #5
0
        public async Task <BluetoothData> ReadAsync(byte[] buffer, int offset, int count)
        {
            Enable();

            try
            {
                int data = await _inputStream.ReadAsync(buffer, offset, count);

                var result = new BluetoothData(true, data);
                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Close();
                return(new BluetoothData(false));
            }
        }
コード例 #6
0
 private void addPeripheral(string address, string name)
 {
     if (peripheralList == null)
     {
         peripheralList = new Dictionary <string, BluetoothData>();
     }
     if (!peripheralList.ContainsKey(address))
     {
         BTLog += ("Found " + address + " \n");
         peripheralList[address] = new BluetoothData(name, address);
         //新增一個可點擊連線的按鈕
         GetComponent <BTManager>().addPeripheralButton(address, name);
     }
     else
     {
         BTLog += "No address found \n";
     }
 }
コード例 #7
0
    //Data송신
    public void SendBluetoothMsg(string msg, SENDMSGTYPE type, MUSICINFO musicInfo = MUSICINFO.None, Menu menu = Menu.None)
    {
        BluetoothData data = new BluetoothData
        {
            msg       = msg,
            dataType  = type,
            musicInfo = musicInfo,
            menu      = menu
        };

        string dataMsg = JsonUtility.ToJson(data);

        try
        {
            serialPort.Write(dataMsg);
        }
        catch (Exception e)
        {
            Debug.Log(e.ToString());
        }
    }
コード例 #8
0
    public void ObjectSelect()
    {
        if (corTimeCheck == null)
        {
            Debug.Log("최초 터치");
            a         = 0;
            startTime = DateTime.Now;
            prevTime  = DateTime.Now;
            animator.SetTrigger("Over");
            loading.GetComponent <MeshRenderer>().material.SetFloat("_AlphaVal", 0.0f);
            corTimeCheck = StartCoroutine(CheckTimer());
        }

        if (prevTime.AddSeconds(0.01f) < DateTime.Now && corTimeCheck != null)
        {
            prevTime = DateTime.Now;
            StopCoroutine(corTimeCheck);
            corTimeCheck = StartCoroutine(CheckTimer());
        }

        if (corTimeCheck != null && startTime.AddSeconds(2.0f) < DateTime.Now)
        {
            Debug.Log("버튼 유지 완료");
            ResetButton();
            BluetoothData data = new BluetoothData();
            data.msg       = "";
            data.dataType  = SENDMSGTYPE.MENU;
            data.musicInfo = MUSICINFO.None;
            string dataMsg;

            if (this.gameObject.transform.parent.name == "ICON_HOME")
            {
                Debug.Log("메인");
                data.menu = Menu.Main;
                dataMsg   = JsonUtility.ToJson(data);
                Message.Send <TabletMotionMsg>(new TabletMotionMsg(dataMsg));
                Message.Send <RunMenuMsg>(new RunMenuMsg(Menu.None));
            }
            else if (this.gameObject.transform.parent.name == "ICON_CLOCK")
            {
                data.menu = Menu.Watch;
                dataMsg   = JsonUtility.ToJson(data);
                Message.Send <TabletMotionMsg>(new TabletMotionMsg(dataMsg));
                Message.Send <RunMenuMsg>(new RunMenuMsg(Menu.Watch));
            }
            else if (this.gameObject.transform.parent.name == "ICON_GAME")
            {
                data.dataType = SENDMSGTYPE.GAME;
                data.msg      = GameType.RhythmGame.ToString();;
                dataMsg       = JsonUtility.ToJson(data);
                Message.Send <TabletMotionMsg>(new TabletMotionMsg(dataMsg));
                Message.Send <RunMenuMsg>(new RunMenuMsg(Menu.Game));
            }
            else if (this.gameObject.transform.parent.name == "ICON_MUSIC")
            {
                data.menu = Menu.Music;
                dataMsg   = JsonUtility.ToJson(data);
                Message.Send <TabletMotionMsg>(new TabletMotionMsg(dataMsg));
                Message.Send <RunMenuMsg>(new RunMenuMsg(Menu.Music));
            }
            else if (this.gameObject.transform.parent.name == "ICON_HOLOSTAR")
            {
                data.menu = Menu.HoloStar;
                dataMsg   = JsonUtility.ToJson(data);
                Message.Send <TabletMotionMsg>(new TabletMotionMsg(dataMsg));
                Message.Send <RunMenuMsg>(new RunMenuMsg(Menu.HoloStar));
            }
            else if (this.gameObject.transform.parent.name == "ICON_OPTION")
            {
                data.menu = Menu.Option;
                dataMsg   = JsonUtility.ToJson(data);
                Message.Send <TabletMotionMsg>(new TabletMotionMsg(dataMsg));
                Message.Send <RunMenuMsg>(new RunMenuMsg(Menu.Option));
            }
        }
    }