kopia lustrzana https://github.com/felHR85/UsbSerial
first version of integration app
rodzic
f30817c30f
commit
203a65eb54
|
@ -11,17 +11,18 @@ 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.
|
||||
*/
|
||||
import static com.felhr.integrationapp.UsbService.MESSAGE_TEST_1;
|
||||
import static com.felhr.integrationapp.UsbService.MESSAGE_TEST_2;
|
||||
import static com.felhr.integrationapp.UsbService.MESSAGE_TEST_3;
|
||||
import static com.felhr.integrationapp.UsbService.MESSAGE_TEST_4;
|
||||
import static com.felhr.integrationapp.UsbService.MESSAGE_TEST_5;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
/*
|
||||
|
@ -33,26 +34,34 @@ public class MainActivity extends AppCompatActivity {
|
|||
switch (intent.getAction()) {
|
||||
case UsbService.ACTION_USB_PERMISSION_GRANTED: // USB PERMISSION GRANTED
|
||||
Toast.makeText(context, "USB Ready", Toast.LENGTH_SHORT).show();
|
||||
statusText.setText("USB connected. Run Python tests");
|
||||
break;
|
||||
case UsbService.ACTION_USB_PERMISSION_NOT_GRANTED: // USB PERMISSION NOT GRANTED
|
||||
Toast.makeText(context, "USB Permission not granted", Toast.LENGTH_SHORT).show();
|
||||
resetTestTextViews();
|
||||
statusText.setText("Connect USB Device");
|
||||
break;
|
||||
case UsbService.ACTION_NO_USB: // NO USB CONNECTED
|
||||
Toast.makeText(context, "No USB connected", Toast.LENGTH_SHORT).show();
|
||||
resetTestTextViews();
|
||||
statusText.setText("Connect USB Device");
|
||||
break;
|
||||
case UsbService.ACTION_USB_DISCONNECTED: // USB DISCONNECTED
|
||||
Toast.makeText(context, "USB disconnected", Toast.LENGTH_SHORT).show();
|
||||
resetTestTextViews();
|
||||
statusText.setText("Connect USB Device");
|
||||
break;
|
||||
case UsbService.ACTION_USB_NOT_SUPPORTED: // USB NOT SUPPORTED
|
||||
Toast.makeText(context, "USB device not supported", Toast.LENGTH_SHORT).show();
|
||||
resetTestTextViews();
|
||||
statusText.setText("Connect USB Device");
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
private UsbService usbService;
|
||||
private TextView display1, display2;
|
||||
private EditText editText1, editText2;
|
||||
private Button button1, button2;
|
||||
private TextView test1, test2, test3, test4, test5;
|
||||
private TextView statusText;
|
||||
private MyHandler mHandler;
|
||||
|
||||
private final ServiceConnection usbConnection = new ServiceConnection() {
|
||||
|
@ -72,9 +81,12 @@ public class MainActivity extends AppCompatActivity {
|
|||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
//TODO!!
|
||||
|
||||
test1 = findViewById(R.id.test_1_result);
|
||||
test2 = findViewById(R.id.test_2_result);
|
||||
test3 = findViewById(R.id.test_3_result);
|
||||
test4 = findViewById(R.id.test_4_result);
|
||||
test5 = findViewById(R.id.test_5_result);
|
||||
statusText = findViewById(R.id.status);
|
||||
mHandler = new MyHandler(this);
|
||||
}
|
||||
|
||||
|
@ -118,6 +130,14 @@ public class MainActivity extends AppCompatActivity {
|
|||
registerReceiver(mUsbReceiver, filter);
|
||||
}
|
||||
|
||||
private void resetTestTextViews(){
|
||||
test1.setText("TEST1: Not Passed");
|
||||
test2.setText("TEST2: Not Passed");
|
||||
test3.setText("TEST3: Not Passed");
|
||||
test4.setText("TEST4: Not Passed");
|
||||
test5.setText("TEST5: Not Passed");
|
||||
}
|
||||
|
||||
/*
|
||||
* This handler will be passed to UsbService. Data received from serial port is displayed through this handler
|
||||
*/
|
||||
|
@ -130,8 +150,27 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
String data = (String) msg.obj;
|
||||
switch (msg.what) {
|
||||
//TODO!!
|
||||
case MESSAGE_TEST_1:
|
||||
mActivity.get().test1.setText(data);
|
||||
break;
|
||||
|
||||
case MESSAGE_TEST_2:
|
||||
mActivity.get().test2.setText(data);
|
||||
break;
|
||||
|
||||
case MESSAGE_TEST_3:
|
||||
mActivity.get().test3.setText(data);
|
||||
break;
|
||||
|
||||
case MESSAGE_TEST_4:
|
||||
mActivity.get().test4.setText(data);
|
||||
break;
|
||||
|
||||
case MESSAGE_TEST_5:
|
||||
mActivity.get().test5.setText(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,11 @@ public class UsbService extends Service {
|
|||
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 MESSAGE_TEST_1 = 0;
|
||||
public static final int MESSAGE_TEST_2 = 1;
|
||||
public static final int MESSAGE_TEST_3 = 2;
|
||||
public static final int MESSAGE_TEST_4 = 3;
|
||||
public static final int MESSAGE_TEST_5 = 4;
|
||||
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";
|
||||
|
@ -80,32 +84,32 @@ public class UsbService extends Service {
|
|||
if(buffer.size() == SIZE_TEST_1){
|
||||
serialPort.write(buffer.readByteArray());
|
||||
mode = TEST_2;
|
||||
mHandler.obtainMessage(MESSAGE_FROM_SERIAL_PORT, "Test 1Kb completed correctly").sendToTarget();
|
||||
mHandler.obtainMessage(MESSAGE_TEST_1, "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();
|
||||
mHandler.obtainMessage(MESSAGE_TEST_2, "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();
|
||||
mHandler.obtainMessage(MESSAGE_TEST_3, "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();
|
||||
mHandler.obtainMessage(MESSAGE_TEST_4, "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();
|
||||
mHandler.obtainMessage(MESSAGE_TEST_5, "Test 128Kb completed correctly").sendToTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,4 +4,58 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Integration Tests"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/test_1_result"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:text="TEST1: Not Passed"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/test_2_result"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:text="TEST2: Not Passed"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/test_3_result"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:text="TEST3: Not Passed"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/test_4_result"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:text="TEST4: Not Passed"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/test_5_result"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:text="TEST5: Not Passed"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/status"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Connect USB Device"
|
||||
android:layout_marginTop="20dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||
|
||||
</LinearLayout>
|
Ładowanie…
Reference in New Issue