blueToothAdapter = BluetoothAdapter.getDefaultAdapter();
Set<BluetoothDevice> bondedDevices = blueToothAdapter.getBondedDevices();
bondedDevicesStringList = new ArrayList<String>();
for (BluetoothDevice bondedDevice : bondedDevices) {
bondedDevicesStringList.add(bondedDevice.getName() + " #" + bondedDevice.getAddress());
}
public static final String CONTROLLER_UUID = "00001101-0000-1000-8000-00805F9B34FB";
public boolean connect(String deviceAddress) {
BluetoothAdapter blueToothAdapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice blueToothDevice = blueToothAdapter.getRemoteDevice(deviceAddress);
try {
socket = blueToothDevice.createRfcommSocketToServiceRecord(UUID.fromString(Main.CONTROLLER_UUID));
// socket = blueToothDevice.createInsecureRfcommSocketToServiceRecord(UUID.fromString(Main.CONTROLLER_UUID));
socket.connect();
return true;
} catch (IOException e) {
Log.e(Main.CONTROLLER_TAG, e.getMessage(), e);
return false;
}
}
private BluetoothSocket socket;
private DataOutputStream out;
public Sender(BluetoothSocket socket) throws IOException {
this.socket = socket;
out = new DataOutputStream(socket.getOutputStream());
}
public void sendCommand(String command) {
try {
out.writeChars(command);
out.flush();
Log.i(Main.CONTROLLER_TAG, "Executing command " + command);
} catch (IOException e) {
Log.e(Main.CONTROLLER_TAG, "Error executing command " + command, e);
}
}
if (Serial3.available() > 0) {
byte originalValue = Serial3.read();
if (originalValue == 0) return;
char valueRead = (char) originalValue;
#ifdef DEBUG_CONTROLLER_FIRMWARE
Serial.print("Original value read ");
Serial.println(originalValue);
Serial.print("Value read ");
Serial.println(valueRead);
#endif