mirror of https://github.com/rusefi/rusefi-1.git
nothing to see here
This commit is contained in:
parent
94c185ba3e
commit
d5b55137f5
|
@ -17,14 +17,34 @@
|
||||||
package com.rusefi.app;
|
package com.rusefi.app;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
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.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
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 {
|
public class rusEFI extends Activity {
|
||||||
|
private static final int VENDOR_ST = 0x0483;
|
||||||
|
private static final int ST_CDC = 0x5740;
|
||||||
|
|
||||||
/* UI elements */
|
/* UI elements */
|
||||||
private TextView mStatusView, mResultView;
|
private TextView mStatusView;
|
||||||
|
private TextView mResultView;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
@ -34,8 +54,79 @@ public class rusEFI extends Activity {
|
||||||
mStatusView = (TextView) findViewById(R.id.text_status);
|
mStatusView = (TextView) findViewById(R.id.text_status);
|
||||||
mResultView = (TextView) findViewById(R.id.text_result);
|
mResultView = (TextView) findViewById(R.id.text_result);
|
||||||
|
|
||||||
|
|
||||||
mStatusView.setText("Hello");
|
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
|
@Override
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
|
@ -12,6 +13,14 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:textAppearanceMedium"/>
|
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
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
Loading…
Reference in New Issue