nothing to see here
This commit is contained in:
parent
94c185ba3e
commit
d5b55137f5
|
@ -17,14 +17,34 @@
|
|||
package com.rusefi.app;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.hardware.usb.UsbDeviceConnection;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.hoho.android.usbserial.driver.CdcAcmSerialDriver;
|
||||
import com.hoho.android.usbserial.driver.ProbeTable;
|
||||
import com.hoho.android.usbserial.driver.UsbSerialDriver;
|
||||
import com.hoho.android.usbserial.driver.UsbSerialPort;
|
||||
import com.hoho.android.usbserial.driver.UsbSerialProber;
|
||||
import com.hoho.android.usbserial.util.SerialInputOutputManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class rusEFI extends Activity {
|
||||
private static final int VENDOR_ST = 0x0483;
|
||||
private static final int ST_CDC = 0x5740;
|
||||
|
||||
/* UI elements */
|
||||
private TextView mStatusView, mResultView;
|
||||
private TextView mStatusView;
|
||||
private TextView mResultView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -34,8 +54,79 @@ public class rusEFI extends Activity {
|
|||
mStatusView = (TextView) findViewById(R.id.text_status);
|
||||
mResultView = (TextView) findViewById(R.id.text_result);
|
||||
|
||||
|
||||
mStatusView.setText("Hello");
|
||||
|
||||
handleButton();
|
||||
}
|
||||
|
||||
private void handleButton() {
|
||||
mResultView.append("rusEFI app v0.0000001\n");
|
||||
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
||||
|
||||
// listDevices(manager);
|
||||
|
||||
ProbeTable customTable = new ProbeTable();
|
||||
customTable.addProduct(VENDOR_ST, ST_CDC, CdcAcmSerialDriver.class);
|
||||
UsbSerialProber prober = new UsbSerialProber(customTable);
|
||||
// todo: handle both custom ST CDC and default hard-coded USB chips
|
||||
|
||||
List<UsbSerialDriver> availableDrivers = prober.findAllDrivers(manager);
|
||||
if (availableDrivers.isEmpty()) {
|
||||
mStatusView.setText("Not connected");
|
||||
mResultView.append("No devices " + new Date());
|
||||
return;
|
||||
}
|
||||
mStatusView.setText("rusEFI: " + availableDrivers.size() + " device(s)");
|
||||
|
||||
UsbSerialDriver driver = availableDrivers.get(0);
|
||||
UsbDeviceConnection connection = manager.openDevice(driver.getDevice());
|
||||
if (connection == null) {
|
||||
// add UsbManager.requestPermission(driver.getDevice(), ..) handling here
|
||||
mStatusView.setText("Unable to open");
|
||||
return;
|
||||
}
|
||||
|
||||
UsbSerialPort port = driver.getPorts().get(0); // Most devices have just one port (port 0)
|
||||
try {
|
||||
port.open(connection);
|
||||
port.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE);
|
||||
|
||||
port.write("t".getBytes(), 500);
|
||||
|
||||
SerialInputOutputManager usbIoManager = new SerialInputOutputManager(port, new SerialInputOutputManager.Listener() {
|
||||
@Override
|
||||
public void onNewData(final byte[] data) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mResultView.append(new String(data));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRunError(Exception e) {
|
||||
}
|
||||
});
|
||||
Executors.newSingleThreadExecutor().submit(usbIoManager);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void listDevices(UsbManager manager) {
|
||||
for (final UsbDevice usbDevice : manager.getDeviceList().values()) {
|
||||
mResultView.append(usbDevice.getDeviceName() + " " + usbDevice.getVendorId() + " " + usbDevice.getProductId() + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user touches the button
|
||||
*/
|
||||
public void sendMessage(View view) {
|
||||
handleButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
|
@ -12,6 +13,14 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:textAppearanceMedium"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Try"
|
||||
android:onClick="sendMessage"
|
||||
/>
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
|
Loading…
Reference in New Issue