started integration test app
|
@ -0,0 +1 @@
|
|||
/build
|
|
@ -0,0 +1,39 @@
|
|||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.felhr.integrationapp"
|
||||
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
|
||||
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
|
||||
versionName project.VERSION_NAME
|
||||
versionCode Integer.parseInt(project.VERSION_CODE)
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
encoding "UTF-8"
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.android.support:support-v4:23.1.1'
|
||||
implementation 'com.android.support:appcompat-v7:23.1.1'
|
||||
implementation 'com.android.support:design:23.1.1'
|
||||
|
||||
implementation 'com.android.support:support-annotations:28.0.0'
|
||||
|
||||
implementation 'com.android.support:support-annotations:28.0.0'
|
||||
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
androidTestImplementation 'junit:junit:4.12'
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
|
||||
implementation 'com.squareup.okio:okio:2.1.0'
|
||||
|
||||
implementation project(':usbserial')
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
|
@ -0,0 +1,26 @@
|
|||
package com.felhr.integrationapp;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
assertEquals("com.felhr.integrationapp", appContext.getPackageName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="com.felhr.integrationapp"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-feature android:name="android.hardware.usb.host"
|
||||
android:required="true"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service
|
||||
android:name="com.felhr.integrationapp.UsbService"
|
||||
android:enabled="true">
|
||||
</service>
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
package com.felhr.integrationapp;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Created by Felipe Herranz(felhr85@gmail.com) on 24/02/2019.
|
||||
*/
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
/*
|
||||
* Notifications from UsbService will be received here.
|
||||
*/
|
||||
private final BroadcastReceiver mUsbReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
case UsbService.ACTION_USB_PERMISSION_GRANTED: // USB PERMISSION GRANTED
|
||||
Toast.makeText(context, "USB Ready", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case UsbService.ACTION_USB_PERMISSION_NOT_GRANTED: // USB PERMISSION NOT GRANTED
|
||||
Toast.makeText(context, "USB Permission not granted", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case UsbService.ACTION_NO_USB: // NO USB CONNECTED
|
||||
Toast.makeText(context, "No USB connected", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case UsbService.ACTION_USB_DISCONNECTED: // USB DISCONNECTED
|
||||
Toast.makeText(context, "USB disconnected", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case UsbService.ACTION_USB_NOT_SUPPORTED: // USB NOT SUPPORTED
|
||||
Toast.makeText(context, "USB device not supported", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
private UsbService usbService;
|
||||
private TextView display1, display2;
|
||||
private EditText editText1, editText2;
|
||||
private Button button1, button2;
|
||||
private MyHandler mHandler;
|
||||
|
||||
private final ServiceConnection usbConnection = new ServiceConnection() {
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName arg0, IBinder arg1) {
|
||||
usbService = ((UsbService.UsbBinder) arg1).getService();
|
||||
usbService.setHandler(mHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName arg0) {
|
||||
usbService = null;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
//TODO!!
|
||||
|
||||
mHandler = new MyHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
setFilters(); // Start listening notifications from UsbService
|
||||
startService(UsbService.class, usbConnection, null); // Start UsbService(if it was not started before) and Bind it
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
unregisterReceiver(mUsbReceiver);
|
||||
unbindService(usbConnection);
|
||||
}
|
||||
|
||||
private void startService(Class<?> service, ServiceConnection serviceConnection, Bundle extras) {
|
||||
if (!UsbService.SERVICE_CONNECTED) {
|
||||
Intent startService = new Intent(this, service);
|
||||
if (extras != null && !extras.isEmpty()) {
|
||||
Set<String> keys = extras.keySet();
|
||||
for (String key : keys) {
|
||||
String extra = extras.getString(key);
|
||||
startService.putExtra(key, extra);
|
||||
}
|
||||
}
|
||||
startService(startService);
|
||||
}
|
||||
Intent bindingIntent = new Intent(this, service);
|
||||
bindService(bindingIntent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
private void setFilters() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(UsbService.ACTION_USB_PERMISSION_GRANTED);
|
||||
filter.addAction(UsbService.ACTION_NO_USB);
|
||||
filter.addAction(UsbService.ACTION_USB_DISCONNECTED);
|
||||
filter.addAction(UsbService.ACTION_USB_NOT_SUPPORTED);
|
||||
filter.addAction(UsbService.ACTION_USB_PERMISSION_NOT_GRANTED);
|
||||
registerReceiver(mUsbReceiver, filter);
|
||||
}
|
||||
|
||||
/*
|
||||
* This handler will be passed to UsbService. Data received from serial port is displayed through this handler
|
||||
*/
|
||||
private static class MyHandler extends Handler {
|
||||
private final WeakReference<MainActivity> mActivity;
|
||||
|
||||
public MyHandler(MainActivity activity) {
|
||||
mActivity = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
//TODO!!
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,331 @@
|
|||
package com.felhr.integrationapp;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.hardware.usb.UsbDeviceConnection;
|
||||
import android.hardware.usb.UsbManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import com.felhr.usbserial.CDCSerialDevice;
|
||||
import com.felhr.usbserial.UsbSerialDevice;
|
||||
import com.felhr.usbserial.UsbSerialInterface;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import okio.Buffer;
|
||||
|
||||
public class UsbService extends Service {
|
||||
|
||||
public static final String TAG = "UsbService";
|
||||
|
||||
private static final int SIZE_TEST_1 = 1024;
|
||||
private static final int SIZE_TEST_2 = 2048;
|
||||
private static final int SIZE_TEST_3 = 16384;
|
||||
private static final int SIZE_TEST_4 = 65535;
|
||||
private static final int SIZE_TEST_5 = 131072;
|
||||
|
||||
private static final String TEST_1 = "test1";
|
||||
private static final String TEST_2 = "test2";
|
||||
private static final String TEST_3 = "test3";
|
||||
private static final String TEST_4 = "test4";
|
||||
private static final String TEST_5 = "test5";
|
||||
|
||||
|
||||
public static final String ACTION_USB_READY = "com.felhr.connectivityservices.USB_READY";
|
||||
public static final String ACTION_USB_ATTACHED = "android.hardware.usb.action.USB_DEVICE_ATTACHED";
|
||||
public static final String ACTION_USB_DETACHED = "android.hardware.usb.action.USB_DEVICE_DETACHED";
|
||||
public static final String ACTION_USB_NOT_SUPPORTED = "com.felhr.usbservice.USB_NOT_SUPPORTED";
|
||||
public static final String ACTION_NO_USB = "com.felhr.usbservice.NO_USB";
|
||||
public static final String ACTION_USB_PERMISSION_GRANTED = "com.felhr.usbservice.USB_PERMISSION_GRANTED";
|
||||
public static final String ACTION_USB_PERMISSION_NOT_GRANTED = "com.felhr.usbservice.USB_PERMISSION_NOT_GRANTED";
|
||||
public static final String ACTION_USB_DISCONNECTED = "com.felhr.usbservice.USB_DISCONNECTED";
|
||||
public static final String ACTION_CDC_DRIVER_NOT_WORKING = "com.felhr.connectivityservices.ACTION_CDC_DRIVER_NOT_WORKING";
|
||||
public static final String ACTION_USB_DEVICE_NOT_WORKING = "com.felhr.connectivityservices.ACTION_USB_DEVICE_NOT_WORKING";
|
||||
public static final int MESSAGE_FROM_SERIAL_PORT = 0;
|
||||
public static final int CTS_CHANGE = 1;
|
||||
public static final int DSR_CHANGE = 2;
|
||||
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
|
||||
private static final int BAUD_RATE = 9600; // BaudRate. Change this value if you need
|
||||
public static boolean SERVICE_CONNECTED = false;
|
||||
|
||||
private IBinder binder = new UsbBinder();
|
||||
|
||||
private Context context;
|
||||
private Handler mHandler;
|
||||
private UsbManager usbManager;
|
||||
private UsbDevice device;
|
||||
private UsbDeviceConnection connection;
|
||||
private UsbSerialDevice serialPort;
|
||||
|
||||
private Buffer buffer = new Buffer();
|
||||
private String mode;
|
||||
|
||||
private boolean serialPortConnected;
|
||||
|
||||
|
||||
private UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() {
|
||||
@Override
|
||||
public void onReceivedData(byte[] arg0) {
|
||||
buffer.write(arg0);
|
||||
if(mode.equals(TEST_1)){
|
||||
if(buffer.size() == SIZE_TEST_1){
|
||||
serialPort.write(buffer.readByteArray());
|
||||
mode = TEST_2;
|
||||
mHandler.obtainMessage(MESSAGE_FROM_SERIAL_PORT, "Test 1Kb completed correctly").sendToTarget();
|
||||
}
|
||||
}else if(mode.equals(TEST_2)){
|
||||
if(buffer.size() == SIZE_TEST_2){
|
||||
serialPort.write(buffer.readByteArray());
|
||||
mode = TEST_3;
|
||||
mHandler.obtainMessage(MESSAGE_FROM_SERIAL_PORT, "Test 3Kb completed correctly").sendToTarget();
|
||||
}
|
||||
|
||||
}else if(mode.equals(TEST_3)){
|
||||
if(buffer.size() == SIZE_TEST_3){
|
||||
serialPort.write(buffer.readByteArray());
|
||||
mode = TEST_4;
|
||||
mHandler.obtainMessage(MESSAGE_FROM_SERIAL_PORT, "Test 16Kb completed correctly").sendToTarget();
|
||||
}
|
||||
}else if(mode.equals(TEST_4)){
|
||||
if(buffer.size() == SIZE_TEST_4){
|
||||
serialPort.write(buffer.readByteArray());
|
||||
mode = TEST_5;
|
||||
mHandler.obtainMessage(MESSAGE_FROM_SERIAL_PORT, "Test 64Kb completed correctly").sendToTarget();
|
||||
}
|
||||
}else if(mode.equals(TEST_5)){
|
||||
if(buffer.size() == SIZE_TEST_5){
|
||||
serialPort.write(buffer.readByteArray());
|
||||
mode = TEST_1;
|
||||
mHandler.obtainMessage(MESSAGE_FROM_SERIAL_PORT, "Test 128Kb completed correctly").sendToTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* State changes in the CTS line will be received here
|
||||
*/
|
||||
private UsbSerialInterface.UsbCTSCallback ctsCallback = new UsbSerialInterface.UsbCTSCallback() {
|
||||
@Override
|
||||
public void onCTSChanged(boolean state) {
|
||||
if(mHandler != null)
|
||||
mHandler.obtainMessage(CTS_CHANGE).sendToTarget();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* State changes in the DSR line will be received here
|
||||
*/
|
||||
private UsbSerialInterface.UsbDSRCallback dsrCallback = new UsbSerialInterface.UsbDSRCallback() {
|
||||
@Override
|
||||
public void onDSRChanged(boolean state) {
|
||||
if(mHandler != null)
|
||||
mHandler.obtainMessage(DSR_CHANGE).sendToTarget();
|
||||
}
|
||||
};
|
||||
/*
|
||||
* Different notifications from OS will be received here (USB attached, detached, permission responses...)
|
||||
* About BroadcastReceiver: http://developer.android.com/reference/android/content/BroadcastReceiver.html
|
||||
*/
|
||||
private final BroadcastReceiver usbReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context arg0, Intent arg1) {
|
||||
if (arg1.getAction().equals(ACTION_USB_PERMISSION)) {
|
||||
boolean granted = arg1.getExtras().getBoolean(UsbManager.EXTRA_PERMISSION_GRANTED);
|
||||
if (granted) // User accepted our USB connection. Try to open the device as a serial port
|
||||
{
|
||||
Intent intent = new Intent(ACTION_USB_PERMISSION_GRANTED);
|
||||
arg0.sendBroadcast(intent);
|
||||
connection = usbManager.openDevice(device);
|
||||
new ConnectionThread().start();
|
||||
} else // User not accepted our USB connection. Send an Intent to the Main Activity
|
||||
{
|
||||
Intent intent = new Intent(ACTION_USB_PERMISSION_NOT_GRANTED);
|
||||
arg0.sendBroadcast(intent);
|
||||
}
|
||||
} else if (arg1.getAction().equals(ACTION_USB_ATTACHED)) {
|
||||
if (!serialPortConnected)
|
||||
findSerialPortDevice(); // A USB device has been attached. Try to open it as a Serial port
|
||||
} else if (arg1.getAction().equals(ACTION_USB_DETACHED)) {
|
||||
// Usb device was disconnected. send an intent to the Main Activity
|
||||
Intent intent = new Intent(ACTION_USB_DISCONNECTED);
|
||||
arg0.sendBroadcast(intent);
|
||||
if (serialPortConnected) {
|
||||
serialPort.close();
|
||||
}
|
||||
serialPortConnected = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* onCreate will be executed when service is started. It configures an IntentFilter to listen for
|
||||
* incoming Intents (USB ATTACHED, USB DETACHED...) and it tries to open a serial port.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate() {
|
||||
this.context = this;
|
||||
serialPortConnected = false;
|
||||
UsbService.SERVICE_CONNECTED = true;
|
||||
setFilter();
|
||||
usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
|
||||
findSerialPortDevice();
|
||||
mode = TEST_1;
|
||||
}
|
||||
|
||||
/* MUST READ about services
|
||||
* http://developer.android.com/guide/components/services.html
|
||||
* http://developer.android.com/guide/components/bound-services.html
|
||||
*/
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return binder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
return Service.START_NOT_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
serialPort.close();
|
||||
unregisterReceiver(usbReceiver);
|
||||
UsbService.SERVICE_CONNECTED = false;
|
||||
}
|
||||
|
||||
|
||||
public void setHandler(Handler mHandler) {
|
||||
this.mHandler = mHandler;
|
||||
}
|
||||
|
||||
private void findSerialPortDevice() {
|
||||
// This snippet will try to open the first encountered usb device connected, excluding usb root hubs
|
||||
HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
|
||||
if (!usbDevices.isEmpty()) {
|
||||
|
||||
// first, dump the hashmap for diagnostic purposes
|
||||
for (Map.Entry<String, UsbDevice> entry : usbDevices.entrySet()) {
|
||||
device = entry.getValue();
|
||||
Log.d(TAG, String.format("USBDevice.HashMap (vid:pid) (%X:%X)-%b class:%X:%X name:%s",
|
||||
device.getVendorId(), device.getProductId(),
|
||||
UsbSerialDevice.isSupported(device),
|
||||
device.getDeviceClass(), device.getDeviceSubclass(),
|
||||
device.getDeviceName()));
|
||||
}
|
||||
|
||||
for (Map.Entry<String, UsbDevice> entry : usbDevices.entrySet()) {
|
||||
device = entry.getValue();
|
||||
int deviceVID = device.getVendorId();
|
||||
int devicePID = device.getProductId();
|
||||
|
||||
// if (deviceVID != 0x1d6b && (devicePID != 0x0001 && devicePID != 0x0002 && devicePID != 0x0003) && deviceVID != 0x5c6 && devicePID != 0x904c) {
|
||||
if (UsbSerialDevice.isSupported(device)) {
|
||||
// There is a supported device connected - request permission to access it.
|
||||
requestUserPermission();
|
||||
break;
|
||||
} else {
|
||||
connection = null;
|
||||
device = null;
|
||||
}
|
||||
}
|
||||
if (device==null) {
|
||||
// There are no USB devices connected (but usb host were listed). Send an intent to MainActivity.
|
||||
Intent intent = new Intent(ACTION_NO_USB);
|
||||
sendBroadcast(intent);
|
||||
}
|
||||
} else {
|
||||
Log.d(TAG, "findSerialPortDevice() usbManager returned empty device list." );
|
||||
// There is no USB devices connected. Send an intent to MainActivity
|
||||
Intent intent = new Intent(ACTION_NO_USB);
|
||||
sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
|
||||
private void setFilter() {
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(ACTION_USB_PERMISSION);
|
||||
filter.addAction(ACTION_USB_DETACHED);
|
||||
filter.addAction(ACTION_USB_ATTACHED);
|
||||
registerReceiver(usbReceiver, filter);
|
||||
}
|
||||
|
||||
/*
|
||||
* Request user permission. The response will be received in the BroadcastReceiver
|
||||
*/
|
||||
private void requestUserPermission() {
|
||||
Log.d(TAG, String.format("requestUserPermission(%X:%X)", device.getVendorId(), device.getProductId() ) );
|
||||
PendingIntent mPendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
|
||||
usbManager.requestPermission(device, mPendingIntent);
|
||||
}
|
||||
|
||||
public class UsbBinder extends Binder {
|
||||
public UsbService getService() {
|
||||
return UsbService.this;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* A simple thread to open a serial port.
|
||||
* Although it should be a fast operation. moving usb operations away from UI thread is a good thing.
|
||||
*/
|
||||
private class ConnectionThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection);
|
||||
if (serialPort != null) {
|
||||
if (serialPort.open()) {
|
||||
serialPortConnected = true;
|
||||
serialPort.setBaudRate(BAUD_RATE);
|
||||
serialPort.setDataBits(UsbSerialInterface.DATA_BITS_8);
|
||||
serialPort.setStopBits(UsbSerialInterface.STOP_BITS_1);
|
||||
serialPort.setParity(UsbSerialInterface.PARITY_NONE);
|
||||
/**
|
||||
* Current flow control Options:
|
||||
* UsbSerialInterface.FLOW_CONTROL_OFF
|
||||
* UsbSerialInterface.FLOW_CONTROL_RTS_CTS only for CP2102 and FT232
|
||||
* UsbSerialInterface.FLOW_CONTROL_DSR_DTR only for CP2102 and FT232
|
||||
*/
|
||||
serialPort.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
|
||||
serialPort.read(mCallback);
|
||||
serialPort.getCTS(ctsCallback);
|
||||
serialPort.getDSR(dsrCallback);
|
||||
|
||||
//
|
||||
// Some Arduinos would need some sleep because firmware wait some time to know whether a new sketch is going
|
||||
// to be uploaded or not
|
||||
//Thread.sleep(2000); // sleep some. YMMV with different chips.
|
||||
|
||||
// Everything went as expected. Send an intent to MainActivity
|
||||
Intent intent = new Intent(ACTION_USB_READY);
|
||||
context.sendBroadcast(intent);
|
||||
} else {
|
||||
// Serial port could not be opened, maybe an I/O error or if CDC driver was chosen, it does not really fit
|
||||
// Send an Intent to Main Activity
|
||||
if (serialPort instanceof CDCSerialDevice) {
|
||||
Intent intent = new Intent(ACTION_CDC_DRIVER_NOT_WORKING);
|
||||
context.sendBroadcast(intent);
|
||||
} else {
|
||||
Intent intent = new Intent(ACTION_USB_DEVICE_NOT_WORKING);
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No driver for given device, even generic CDC driver could not be loaded
|
||||
Intent intent = new Intent(ACTION_USB_NOT_SUPPORTED);
|
||||
context.sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
<vector xmlns:aapt="http://schemas.android.com/aapt"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillType="evenOdd"
|
||||
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient
|
||||
android:endX="78.5885"
|
||||
android:endY="90.9159"
|
||||
android:startX="48.7653"
|
||||
android:startY="61.0927"
|
||||
android:type="linear">
|
||||
<item
|
||||
android:color="#44000000"
|
||||
android:offset="0.0"/>
|
||||
<item
|
||||
android:color="#00000000"
|
||||
android:offset="1.0"/>
|
||||
</gradient>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:fillType="nonZero"
|
||||
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:strokeWidth="1"/>
|
||||
</vector>
|
|
@ -0,0 +1,171 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportHeight="108"
|
||||
android:viewportWidth="108">
|
||||
<path
|
||||
android:fillColor="#008577"
|
||||
android:pathData="M0,0h108v108h-108z"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M9,0L9,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,0L19,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,0L29,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,0L39,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,0L49,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,0L59,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,0L69,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,0L79,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M89,0L89,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M99,0L99,108"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,9L108,9"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,19L108,19"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,29L108,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,39L108,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,49L108,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,59L108,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,69L108,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,79L108,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,89L108,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M0,99L108,99"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,29L89,29"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,39L89,39"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,49L89,49"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,59L89,59"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,69L89,69"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M19,79L89,79"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M29,19L29,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M39,19L39,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M49,19L49,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M59,19L59,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M69,19L69,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
<path
|
||||
android:fillColor="#00000000"
|
||||
android:pathData="M79,19L79,89"
|
||||
android:strokeColor="#33FFFFFF"
|
||||
android:strokeWidth="0.8"/>
|
||||
</vector>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||
</adaptive-icon>
|
Po Szerokość: | Wysokość: | Rozmiar: 2.9 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 4.8 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 2.0 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 2.7 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 4.4 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 6.7 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 6.2 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 10 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 8.9 KiB |
Po Szerokość: | Wysokość: | Rozmiar: 15 KiB |
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#008577</color>
|
||||
<color name="colorPrimaryDark">#00574B</color>
|
||||
<color name="colorAccent">#D81B60</color>
|
||||
</resources>
|
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<string name="app_name">IntegrationApp</string>
|
||||
</resources>
|
|
@ -0,0 +1,11 @@
|
|||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
|
@ -0,0 +1,17 @@
|
|||
package com.felhr.integrationapp;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
|
@ -1 +1 @@
|
|||
include ':usbserial', ':example', ':examplesync', ':examplestreams', ':examplemultipleports'
|
||||
include ':usbserial', ':example', ':examplesync', ':examplestreams', ':examplemultipleports', ':integrationapp'
|