-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for multiple bluetooth devices #45
base: master
Are you sure you want to change the base?
Conversation
@@ -47,7 +47,7 @@ | |||
private DiscoveryCallback discoveryCallback; | |||
private BluetoothCallback bluetoothCallback; | |||
|
|||
private ReceiveThread receiveThread; | |||
private ArrayList<ReceiveThread> receiveThreads = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer the use of List
here :
List<ReceiveThread> receiveThreads;
and initialize it with the other variables in the initialize()
method :
receiveThreads = new ArrayList<>();
*/ | ||
public void disconnect() { | ||
for (ReceiveThread receiveThread: receiveThreads) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to able to control each socket separately. We should not disconnect every socket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you should rename the method disconnectAll()
@@ -315,11 +336,33 @@ public boolean isConnected(){ | |||
} | |||
|
|||
/** | |||
* Send string message to the connected device. | |||
* Send string message to all the connected devices. | |||
* @param msg String message. | |||
* @param charset Charset used to encode the String. Default charset is UTF-8. | |||
*/ | |||
public void send(String msg, String charset){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, can you rename it to sendToAll()
?
@@ -478,7 +513,8 @@ public void run() { | |||
try { | |||
socket.connect(); | |||
connected = true; | |||
receiveThread = new ReceiveThread(socket, device); | |||
ReceiveThread receiveThread = new ReceiveThread(socket, device); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we should be able to differentiate messages from callbacks. We should know which socket triggered which callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need it. Do you have update for this?
bluetooth.setDeviceCallback(new DeviceCallback() {
@Override
public void onMessage(BluetoothDevice device, byte[] message) {
}
}
Here are the changes that would resolve #42, adding in support for multiple Bluetooth connections. I have been unable to fully test the functionality yet, but will be able to do so in the next week as I will be around the hardware then. If you have any suggestions or ideas for additional changes, let me know!