mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-18 03:52:11 +01:00
AndroidGCS HID: Use the dettached message to shut down HID telemetry properly
This commit is contained in:
parent
daab45d14d
commit
3ea9ecd53b
@ -64,6 +64,7 @@ public class HidUAVTalk extends TelemetryTask {
|
|||||||
|
|
||||||
private boolean readPending = false;
|
private boolean readPending = false;
|
||||||
private boolean writePending = false;
|
private boolean writePending = false;
|
||||||
|
private IntentFilter deviceAttachedFilter;
|
||||||
|
|
||||||
public HidUAVTalk(OPTelemetryService service) {
|
public HidUAVTalk(OPTelemetryService service) {
|
||||||
super(service);
|
super(service);
|
||||||
@ -73,7 +74,7 @@ public class HidUAVTalk extends TelemetryTask {
|
|||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
|
|
||||||
CleanUpAndClose();
|
CleanUpAndClose();
|
||||||
//hostDisplayActivity.unregisterReceiver(usbReceiver);
|
telemService.unregisterReceiver(usbReceiver);
|
||||||
telemService.unregisterReceiver(usbPermissionReceiver);
|
telemService.unregisterReceiver(usbPermissionReceiver);
|
||||||
|
|
||||||
super.disconnect();
|
super.disconnect();
|
||||||
@ -110,6 +111,11 @@ public class HidUAVTalk extends TelemetryTask {
|
|||||||
permissionFilter = new IntentFilter(ACTION_USB_PERMISSION);
|
permissionFilter = new IntentFilter(ACTION_USB_PERMISSION);
|
||||||
telemService.registerReceiver(usbPermissionReceiver, permissionFilter);
|
telemService.registerReceiver(usbPermissionReceiver, permissionFilter);
|
||||||
|
|
||||||
|
deviceAttachedFilter = new IntentFilter();
|
||||||
|
//deviceAttachedFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
|
||||||
|
deviceAttachedFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
|
||||||
|
telemService.registerReceiver(usbReceiver, deviceAttachedFilter);
|
||||||
|
|
||||||
// Go through all the devices plugged in
|
// Go through all the devices plugged in
|
||||||
HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
|
HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
|
||||||
if (DEBUG) Log.d(TAG, "Found " + deviceList.size() + " devices");
|
if (DEBUG) Log.d(TAG, "Found " + deviceList.size() + " devices");
|
||||||
@ -176,7 +182,6 @@ public class HidUAVTalk extends TelemetryTask {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* TODO: Detect dettached events and close the connection
|
|
||||||
private final BroadcastReceiver usbReceiver = new BroadcastReceiver()
|
private final BroadcastReceiver usbReceiver = new BroadcastReceiver()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -195,8 +200,10 @@ public class HidUAVTalk extends TelemetryTask {
|
|||||||
{
|
{
|
||||||
if (device.equals(currentDevice))
|
if (device.equals(currentDevice))
|
||||||
{
|
{
|
||||||
|
if (DEBUG) Log.d(TAG, "Matching device disconnected");
|
||||||
|
|
||||||
// call your method that cleans up and closes communication with the device
|
// call your method that cleans up and closes communication with the device
|
||||||
CleanUpAndClose();
|
disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -213,7 +220,7 @@ public class HidUAVTalk extends TelemetryTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}; */
|
};
|
||||||
|
|
||||||
|
|
||||||
protected void CleanUpAndClose() {
|
protected void CleanUpAndClose() {
|
||||||
@ -314,8 +321,10 @@ public class HidUAVTalk extends TelemetryTask {
|
|||||||
if (returned == readRequest) {
|
if (returned == readRequest) {
|
||||||
if (DEBUG) Log.d(TAG, "Received read request");
|
if (DEBUG) Log.d(TAG, "Received read request");
|
||||||
readData();
|
readData();
|
||||||
} else
|
} else {
|
||||||
Log.e(TAG, "Received unknown USB response");
|
Log.e(TAG, "Received unknown USB response");
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +337,8 @@ public class HidUAVTalk extends TelemetryTask {
|
|||||||
if (DEBUG) Log.d(TAG, "Starting HID write thread");
|
if (DEBUG) Log.d(TAG, "Starting HID write thread");
|
||||||
while(!shutdown) {
|
while(!shutdown) {
|
||||||
try {
|
try {
|
||||||
sendDataSynchronous();
|
if (sendDataSynchronous() == false)
|
||||||
|
break;
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -436,15 +446,18 @@ public class HidUAVTalk extends TelemetryTask {
|
|||||||
* Send a packet if data is available
|
* Send a packet if data is available
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
public void sendDataSynchronous() throws InterruptedException {
|
public boolean sendDataSynchronous() throws InterruptedException {
|
||||||
|
|
||||||
ByteBuffer packet = outTalkStream.getHIDpacketBlocking();
|
ByteBuffer packet = outTalkStream.getHIDpacketBlocking();
|
||||||
if (packet != null) {
|
if (packet != null) {
|
||||||
if (DEBUG) Log.d(TAG, "sendDataSynchronous() Writing to device()");
|
if (DEBUG) Log.d(TAG, "sendDataSynchronous() Writing to device()");
|
||||||
|
|
||||||
if (usbDeviceConnection.bulkTransfer(usbEndpointWrite, packet.array(), MAX_HID_PACKET_SIZE, 1000) < 0)
|
if (usbDeviceConnection.bulkTransfer(usbEndpointWrite, packet.array(), MAX_HID_PACKET_SIZE, 1000) < 0) {
|
||||||
Log.e(TAG, "Failed to perform bult write");
|
Log.e(TAG, "Failed to perform bulk write");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********** Helper classes for telemetry streams ************/
|
/*********** Helper classes for telemetry streams ************/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user