128 lines
4.3 KiB
C++
128 lines
4.3 KiB
C++
/* RANDOM GENERATED UUID
|
|
*
|
|
* UUID generator: https://www.uuidgenerator.net/
|
|
*
|
|
* Binary to hex: http://www.binaryhexconverter.com/binary-to-hex-converter
|
|
*
|
|
* Hex to decimal: http://www.binaryhexconverter.com/hex-to-decimal-converter
|
|
*
|
|
*
|
|
e3ef0090-6b09-4f8a-a5c9-c0a7e9ddad83 ---> pack(IR,BATTERY,TILT,UP/DOWN,LEFT/RIGHT,q1,q2,q3,q4,q5,q6,q7,q8) (notify) 13 bytes
|
|
|
|
e3ef0090-6b09-4f8a-a5c9-c0a7e9ddad86 ---> SENSOR PHYSICAL POSITION (write) 1 bytes
|
|
e3ef0090-6b09-4f8a-a5c9-c0a7e9ddad88 ---> SENSOR STATE (write) 1 bytes
|
|
|
|
Complete Factory RESET:
|
|
|
|
SF,2
|
|
|
|
Create Private Service:
|
|
|
|
Write 08 Write value of characteristic with acknowledgment from client to server.
|
|
Read 02 Read value of characteristic. Value is sent from server to client.
|
|
Notify 10 Notify changes in value of characteristic.
|
|
|
|
EX:
|
|
|
|
PZ Clear all private service and characteristics settings
|
|
PS,E3EF00906B094F8AA5C9C0A7E9DDAD83
|
|
PC,E3EF00906B094F8AA5C9C0A7E9DDAD83,10,0D // Notify, 13 bytes
|
|
|
|
OR
|
|
|
|
PC,E3EF00906B094F8AA5C9C0A7E9DDAD83,08,02 // Write, 2 bytes
|
|
|
|
R,1 // reboot
|
|
LS // list services
|
|
|
|
*
|
|
*/
|
|
|
|
void initBluetooth(){
|
|
digitalWrite(CMD, HIGH);
|
|
|
|
Serial1.begin(115200);
|
|
delay(1000);
|
|
sendBle("SF,2", "AOK"); // RESET DEVICE
|
|
sendBle("SB,3", "AOK"); // Set the baud rate to 38400
|
|
sendBle("R,1", "Reboot"); // Reboot device
|
|
Serial.println("RESET DEVICE");
|
|
|
|
Serial1.begin(38400);
|
|
delay(1000);
|
|
if (sendBle("SS,C0000001", "AOK")) Serial.println("Activate Private Services");
|
|
else Serial.println("Fail Activate Private Services");
|
|
if (sendBle("SR,24004000", "AOK")) Serial.println("Set device as peripheral, no direct advertisement and enable Apple Bueetooth");
|
|
else Serial.println("Fail Set device as peripheral, no direct advertisement and enable Apple Bueetooth");
|
|
if (sendBle("ST,0064,0002,0064", "AOK")) Serial.println("Set the interval to 125 ms, latency to 2, and time-out to 1 second");
|
|
else Serial.println("Fail Set the interval to 125 ms, latency to 2, and time-out to 1 second");
|
|
if (sendBle("SN,hybridPLAY", "AOK")) Serial.println("Set the name of the device to hybridPLAY");
|
|
else Serial.println("Fail Set the name of the device to hybridPLAY");
|
|
if (sendBle("SP,4", "AOK")) Serial.println("Set TX power value");
|
|
else Serial.println("Fail Set TX power value");
|
|
if (sendBle("SB,3", "AOK")) Serial.println("Set the baud rate to 38400");
|
|
else Serial.println("Fail Set the baud rate to 38400");
|
|
if (sendBle("R,1", "Reboot")) Serial.println("Reboot device");
|
|
else Serial.println("Fail Reboot device");
|
|
delay(1000);
|
|
digitalWrite(CMD, LOW);
|
|
// skipRemainderOfResponse(3000);
|
|
|
|
}
|
|
|
|
void updateBTServices(){
|
|
|
|
// PACK SENSOR DATA
|
|
if(prevValIR != valIR || prevValBattery != valBattery){
|
|
Serial1.print("SUW,E3EF00906B094F8AA5C9C0A7E9DDAD83,");
|
|
|
|
// IR (00,64)HEX ---> (0,100)DEC
|
|
Serial1.print(intToHexString(valIR));
|
|
|
|
// BATTERY (00,64)HEX ---> (0,100)DEC
|
|
Serial1.print(intToHexString(valBattery));
|
|
|
|
// TILT (00,01)HEX ---> (0,1)DEC
|
|
Serial1.print("00");
|
|
|
|
// UP/DOWN (00,01,02)HEX ---> (0,1,2)DEC ---> 0 UP - 1 OFF - 2 DOWN
|
|
Serial1.print("01");
|
|
|
|
// LEFT/RIGHT (00,01,02)HEX ---> (0,1,2)DEC ---> 0 LEFT - 1 OFF - 2 RIGHT
|
|
Serial1.print("01");
|
|
|
|
// QUATERNIONS for Position in Space
|
|
|
|
// Q1 (00,64)HEX ---> (0,100)DEC
|
|
Serial1.print("00");
|
|
// Q2 (00,64)HEX ---> (0,100)DEC
|
|
Serial1.print("00");
|
|
// Q3 (00,64)HEX ---> (0,100)DEC
|
|
Serial1.print("00");
|
|
// Q4 (00,64)HEX ---> (0,100)DEC
|
|
Serial1.print("00");
|
|
// Q5 (00,64)HEX ---> (0,100)DEC
|
|
Serial1.print("00");
|
|
// Q6 (00,64)HEX ---> (0,100)DEC
|
|
Serial1.print("00");
|
|
// Q7 (00,64)HEX ---> (0,100)DEC
|
|
Serial1.print("00");
|
|
// Q8 (00,64)HEX ---> (0,100)DEC
|
|
Serial1.print("00");
|
|
|
|
Serial1.println();
|
|
|
|
// reset flags
|
|
prevValIR = valIR;
|
|
prevValBattery = valBattery;
|
|
}
|
|
|
|
// Battery
|
|
if((millis()-timerBattery) >= 60000){ // read battery level every minute
|
|
timerBattery = millis();
|
|
readBattery();
|
|
}
|
|
|
|
}
|
|
|