Exemplo n.º 1
0
 void SendByte(byte value)
 {
     byte[] data = new byte[] { value };
     BluetoothLEHardwareInterface.WriteCharacteristic(_deviceAddress, ServiceUUID, WriteCharacteristic, data, data.Length, true, (characteristicUUID) => {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
 }
Exemplo n.º 2
0
 private void SendCommand(byte[] ch1, bool queue)
 {
     if (!BluetoothLE.connectState)
     {
         return;
     }
     this.calculateChecksum(ref ch1);
     if (this.debugOutput)
     {
         string empty    = string.Empty;
         byte[] numArray = ch1;
         for (int i = 0; i < (int)numArray.Length; i++)
         {
             byte num = numArray[i];
             empty = string.Concat(empty, string.Format("{0:X2}", num));
         }
     }
     if (queue)
     {
         this.commandQueue.Add(ch1);
     }
     else
     {
         BluetoothLEHardwareInterface.WriteCharacteristic(this.uuids[this.connectedDevice], this.serviceUUID, this.characteristicUUID, ch1, 20, this.ack, new Action <string>(this.Result));
         Debug.Log("*** Debug: Send command!");
         if (ch1[0] == 11)
         {
             BluetoothLE.writeState = (ch1[1] == 0 ? true : ch1[1] == 2);
         }
     }
 }
Exemplo n.º 3
0
 void SendByte(byte value)
 {
     byte[] data = new byte[] { value };
     BluetoothLEHardwareInterface.WriteCharacteristic(_connectedID, _serviceUUID, _writeCharacteristicUUID, data, data.Length, true, (characteristicUUID) => {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
 }
Exemplo n.º 4
0
 public void ExecStartSensing()
 {
     byte[] data = createSendMessage(new byte[] { /*0x40, 0x01*/ 0x44, 0x01, 0x02, 0x03, 0x03, 0x07, 0x02, 0x07, 0x02, 0xFF, 0xFF });
     BluetoothLEHardwareInterface.WriteCharacteristic(m_DeviceAddress, ServiceUUID, GENERAL_PURPOSE_CONTROL, data, data.Length, true, (characteristicUUID) => {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
 }
Exemplo n.º 5
0
 private void setServoPos(bool queue)
 {
     byte[] numArray = new byte[] { 8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 };
     for (int i = 0; i < 8; i++)
     {
         byte[] numArray1 = this.actualPos;
         byte   num       = this.adjust(this.actualPos[i], this.targetPos[i]);
         byte   num1      = num;
         numArray1[i]    = num;
         numArray[i + 1] = num1;
     }
     this.calculateChecksum(ref numArray);
     if (BluetoothLE.connectState && BluetoothLE.writeState)
     {
         if (queue)
         {
             this.commandQueue.Add(numArray);
         }
         else
         {
             BluetoothLEHardwareInterface.WriteCharacteristic(this.uuids[this.connectedDevice], this.serviceUUID, this.characteristicUUID, numArray, 20, this.ack, new Action <string>(this.setResult));
         }
         StringBuilder stringBuilder = new StringBuilder();
         for (int j = 1; j <= 8; j++)
         {
             stringBuilder.Append(string.Concat(numArray[j].ToString("X2"), " "));
         }
         if (this.debugOutput)
         {
             Debug.Log(string.Concat(new object[] { "*** setServoPos: ", stringBuilder.ToString(), " (", Time.realtimeSinceStartup, ")" }));
         }
     }
 }
Exemplo n.º 6
0
 private void WriteCharacteristic(byte[] data)
 {
     BluetoothLEHardwareInterface.WriteCharacteristic(deviceAddress, ServiceUUID, RXUUID, data.ToArray(), data.Length, true, (characteristicUUID) =>
     {
         BluetoothLEHardwareInterface.Log("Write Succeeded with characteristic: " + characteristicUUID);
     });
 }
Exemplo n.º 7
0
    public void SendByteR(byte value)
    {
        byte[] data = new byte[] { value };

        BluetoothLEHardwareInterface.WriteCharacteristic(device_right.Address, FullUUID(ServiceUUID), FullUUID(WriteCharacteristic), data, data.Length, true, (characteristicUUID) => {
        });
    }
Exemplo n.º 8
0
 void sendBytesBluetooth(byte[] data)
 {
     BluetoothLEHardwareInterface.Log(string.Format("data length: {0} data {1} uuid: {2}", data.Length.ToString(), ASCIIEncoding.UTF8.GetString(data), _writeCharacteristicUUID));
     BluetoothLEHardwareInterface.WriteCharacteristic(_connectedID, _serviceUUID, _writeCharacteristicUUID, data, data.Length, false, (characteristicUUID) => {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
 }
    private IEnumerator SendArduino()
    {
        yield return(new WaitForSeconds(1.0f));  //wait awhile before playing song

        WaitForSeconds wait = new WaitForSeconds(0.5f);

        string[] lines = d.TextFile.text.Split('\n');
        foreach (string line in lines)
        {
            if (!string.IsNullOrWhiteSpace(line))     // beat contains notes
            {
                print(line);
                foreach (string note in Regex.Split(line, " "))
                {
                    int key = int.Parse(note);
                    print("sending " + key + ": " + dict[key]);
                    // stream.Write(dict[key]);
                    var data = Encoding.UTF8.GetBytes(dict[key]);
                    BluetoothLEHardwareInterface.WriteCharacteristic(_hm10, ServiceUUID, Characteristic, data, data.Length, false, (characteristicUUID) => {
                        BluetoothLEHardwareInterface.Log("Write Succeeded");
                    });
                }
            }
            yield return(wait); //tempo of song
        }
        StartCoroutine(ReturnPlayer(1.0f));
    }
Exemplo n.º 10
0
 public void SendBytes(byte[] data)
 {
     BluetoothLEHardwareInterface.WriteCharacteristic(_deviceAddress, ServiceUUID, TransforUUID, data, data.Length, true, (characteristicUUID) =>
     {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
 }
 void SendBytes(byte[] data)
 {
     BluetoothLEHardwareInterface.Log(string.Format("data length: {0} uuid: {1}", data.Length.ToString(), FullUUID(_writeCharacteristicUUID)));
     BluetoothLEHardwareInterface.WriteCharacteristic(_connectedID, FullUUID(_serviceUUID), FullUUID(_writeCharacteristicUUID), data, data.Length, true, (characteristicUUID) => {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
 }
Exemplo n.º 12
0
 public void Send(string message)
 {
     byte[] data = System.Text.Encoding.UTF8.GetBytes(message);
     BluetoothLEHardwareInterface.WriteCharacteristic(_deviceAddress, ServiceUUID, WriteCharacteristic, data, data.Length, true, (characteristicUUID) => {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
 }
Exemplo n.º 13
0
    // What happens when song playing is done.
    private IEnumerator ReturnPlayer(float waitTime)
    {
        anim.SetBool("isPlaying", false);
        anim2.SetBool("isPulsing", true);
        yield return(new WaitForSeconds(waitTime));  //wait awhile before returning disc to slot

        canRotatePlayer = false;
        scroll.GetComponent <ScrollRect>().enabled = true;
        d.transform.SetParent(d.parent);
        d.parentToReturnTo = d.parent;
        d = null;
        foreach (Draggable cd in CdList)
        {
            if (cd.name != title)
            {
                cd.draggable = true;
            }
        }
        yield return(new WaitForSeconds(10));

        if (!canRotatePlayer)
        {
            var data = Encoding.UTF8.GetBytes("z");    // stop motor
            BluetoothLEHardwareInterface.WriteCharacteristic(_hm10, ServiceUUID, Characteristic, data, data.Length, false, (characteristicUUID) => {
                BluetoothLEHardwareInterface.Log("Write Succeeded");
            });
        }
    }
Exemplo n.º 14
0
    // What happens during song play.
    private IEnumerator SendArduino()
    {
        anim.SetBool("isPlaying", true);
        anim2.SetBool("isPulsing", false);
        d.RetrieveFromDatabase();
        yield return(new WaitForSeconds(1.0f));  //wait awhile before getting popularity score & playing song

        print("Playing Track: " + d.getTitle() + " of popularity " + d.getPopularity());
        Song song = new Song();

        song.setPopularity(d.getPopularity() + 1);        // update view count
        song.setTitle(d.getTitle());
        RestClient.Put("https://pico-86a8b.firebaseio.com/" + d.getTitle() + ".json", song);

        WaitForSeconds wait = new WaitForSeconds(0.5f);

        string[] lines = d.TextFile.text.Split('\n');
        foreach (string line in lines)
        {
            if (!string.IsNullOrWhiteSpace(line))     // beat contains notes
            {
                foreach (string note in Regex.Split(line, " "))
                {
                    int key = int.Parse(note);
                    // stream.Write(dict[key]);
                    var data = Encoding.UTF8.GetBytes(dict[key]);
                    BluetoothLEHardwareInterface.WriteCharacteristic(_hm10, ServiceUUID, Characteristic, data, data.Length, false, (characteristicUUID) => {
                        BluetoothLEHardwareInterface.Log("Write Succeeded");
                    });
                }
            }
            yield return(wait); //tempo of song
        }
        StartCoroutine(ReturnPlayer(1.0f));
    }
Exemplo n.º 15
0
 void SendString(string s)
 {
     byte[] data = Encoding.ASCII.GetBytes(s);
     print("Sending String");
     BluetoothLEHardwareInterface.WriteCharacteristic(_deviceAddress, ServiceUUID, WriteCharacteristic, data, data.Length, true, (characteristicUUID) => {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
 }
Exemplo n.º 16
0
    private void SendValue(int value, string serviceUID, string characteristicUUID)
    {
        string fullService        = FullUUID(serviceUID);
        string fullCharacteristic = FullUUID(characteristicUUID);

        byte[] data = BitConverter.GetBytes(value);
        BluetoothLEHardwareInterface.WriteCharacteristic(ConnectedToAdr, fullService, fullCharacteristic, data, data.Length, false, null);
    }
 void SendString(string value)
 {
     if (_connected && value != null && value.Length > 0)
     {
         var data = Encoding.UTF8.GetBytes(value);
         BluetoothLEHardwareInterface.WriteCharacteristic(_JDY16, ServiceUUID, Characteristic, data, data.Length, false, (characteristicUUID) => { BluetoothLEHardwareInterface.Log("Write Succeeded"); });
     }
 }
    void SendByte(byte value)
    {
        byte[] data = new byte[] { value };

        BluetoothLEHardwareInterface.WriteCharacteristic(_ezzence, ServiceUUID, Characteristic, data, data.Length, true, (characteristicUUID) => {
            BluetoothStatus.text = "Write Byte Succeeded";
            BluetoothLEHardwareInterface.Log("Write Byte Succeeded");
        });
    }
Exemplo n.º 19
0
    public void StartDrag()
    {
        dragging = true;
        var data = Encoding.UTF8.GetBytes("w");

        BluetoothLEHardwareInterface.WriteCharacteristic(_hm10, ServiceUUID, Characteristic, data, data.Length, false, (characteristicUUID) => {
            BluetoothLEHardwareInterface.Log("Write Succeeded");
        });
    }
Exemplo n.º 20
0
 public void WriteDevice(NetworkDevice device, byte[] bytes, Action onWritten)
 {
     BluetoothLEHardwareInterface.WriteCharacteristic(device.Address, SampleCharacteristic.ServiceUUID, SampleCharacteristic.CharacteristicUUID, bytes, bytes.Length, true, (Characteristic) => {
         if (onWritten != null)
         {
             onWritten();
         }
     });
 }
Exemplo n.º 21
0
 //Send a byte array to BSN
 public static void SendBytesBSN(byte[] data, string bsnAddress, string serviceUUID, string writeCharacteristicUUID)
 {
     BluetoothLEHardwareInterface.Log(string.Format("data length: {0} uuid: {1}", data.Length.ToString(), FullBSNUUID(writeCharacteristicUUID)));
     BluetoothLEHardwareInterface.WriteCharacteristic(bsnAddress, FullBSNUUID(serviceUUID), FullBSNUUID(writeCharacteristicUUID), data, data.Length, true, (characteristicUUID) =>
     {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
     Debug.Log("ESCREVEU COM SUCESSO");
 }
Exemplo n.º 22
0
 void SendByte(byte value)
 {
     byte[] data = new byte[] { value };
     // notice that the 6th parameter is false. this is because the HM10 doesn't support withResponse writing to its characteristic.
     // some devices do support this setting and it is prefered when they do so that you can know for sure the data was received by
     // the device
     BluetoothLEHardwareInterface.WriteCharacteristic(_hm10, ServiceUUID, Characteristic, data, data.Length, false, (characteristicUUID) => {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
 }
Exemplo n.º 23
0
 public void SendByteArray(byte[] data)
 {
     // 6th Parameter is false since EH-MC17 doesn't support write with notify afaik
     BluetoothLEHardwareInterface.WriteCharacteristic(_addressToConnect, ServiceUUIDs[0], writeUUID, data, data.Length, false, (characteristicUUID) => {
         msg = "Byte sent: ";
         foreach (byte b in data)
         {
             msg += b.ToString("X2") + " ";
         }
     });
 }
Exemplo n.º 24
0
    public IEnumerator Countdown()
    {
        yield return(new WaitForSeconds(10));

        if (!DropZone.canRotatePlayer)
        {
            var data = Encoding.UTF8.GetBytes("z");
            BluetoothLEHardwareInterface.WriteCharacteristic(_hm10, ServiceUUID, Characteristic, data, data.Length, false, (characteristicUUID) => {
                BluetoothLEHardwareInterface.Log("Write Succeeded");
            });
        }
    }
Exemplo n.º 25
0
 public void WriteCharacteristic(
     string name,
     string service,
     string characteristic,
     byte[] data,
     int length,
     bool withResponse,
     Action <string> action
     )
 {
     BluetoothLEHardwareInterface.WriteCharacteristic(name, service, characteristic, data, length, withResponse, action);
 }
Exemplo n.º 26
0
 private void CentralSendMessage(BluetoothMessage message)
 {
     MyDebug.LogGreen("CentralSendMessage");
     MyDebug.LogGreen("index:" + message.index);
     MyDebug.LogGreen("result:" + message.result);
     MyDebug.LogGreen("name:" + message.name);
     MyDebug.LogGreen("Length:" + message.data.Length);
     BluetoothLEHardwareInterface.WriteCharacteristic(CurPeripheralInstance.address, ServiceUUID, WriteUUID, message.data, message.data.Length, true, (characteristicUUID) =>
     {
         BluetoothLEHardwareInterface.Log("Write Succeeded");
     });
 }
    void SendString(string value)
    {
        var data = Encoding.UTF8.GetBytes(value);

        // notice that the 6th parameter is set to "true". this can also be false depending if the device supports withResponse writing to its characteristic.
        // some devices do support this setting and it is prefered when they do so that you can know for sure the data was received by the device
        // I believe Ezzence should support this, therefore is set to true.

        BluetoothLEHardwareInterface.WriteCharacteristic(_ezzence, ServiceUUID, Characteristic, data, data.Length, true, (characteristicUUID) => {
            BluetoothStatus.text = "Write String Succeeded";
            BluetoothLEHardwareInterface.Log("Write String Succeeded");
        });
    }
    public BluetoothOperation(string _deviceAddress,
                              string ServiceUUID,
                              string CharacteristicUUID,
                              byte[] data)
    {
        request = bytesToStr(data);

        Debug.Log("WriteCharacteristic request = " + request);
        isOperation = true;
        isSuccess   = false;
        BluetoothLEHardwareInterface.WriteCharacteristic(_deviceAddress, ServiceUUID, CharacteristicUUID, data, data.Length, true, (str) => {
        });
    }
Exemplo n.º 29
0
 public void SendPIN()
 {
     if (this.debugOutput)
     {
         Debug.Log("*** BLE SendPIN");
     }
     byte[] numArray = new byte[20];
     numArray[0] = 26;
     numArray[1] = 1;
     numArray[3] = 1;
     byte[] numArray1 = numArray;
     this.calculateChecksum(ref numArray1);
     BluetoothLEHardwareInterface.WriteCharacteristic(this.uuids[this.connectedDevice], this.serviceUUID, this.characteristicUUID, numArray1, 20, this.ack, new Action <string>(this.Result));
 }
Exemplo n.º 30
0
    public void SendByte(byte value)
    {
        byte[] data = new byte[] { value };
        BluetoothLEHardwareInterface.WriteCharacteristic(device_left.Address, FullUUID(ServiceUUID), FullUUID(WriteCharacteristic), data, data.Length, true, (characteristicUUID) => {
        });

        BluetoothLEHardwareInterface.WriteCharacteristic(device_right.Address, FullUUID(ServiceUUID), FullUUID(WriteCharacteristic), data, data.Length, true, (characteristicUUID) => {
        });

        if (value == '1')
        {
            device_left.Initialized  = true;
            device_right.Initialized = true;
        }
    }