Sickle Cell App With Usb Integration (Added Validation for Each Step )

This commit is contained in:
Ramandeep
2022-01-24 12:35:09 +05:30
parent e780c9c9fd
commit b37dd9fc93
6 changed files with 310 additions and 270 deletions

View File

@@ -32,6 +32,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.github.felHR85:UsbSerial:6.1.0'
implementation 'com.github.ybq:Android-SpinKit:1.4.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'

View File

@@ -14,15 +14,24 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.github.ybq.android.spinkit.sprite.Sprite;
import com.github.ybq.android.spinkit.style.ChasingDots;
import com.github.ybq.android.spinkit.style.DoubleBounce;
import com.github.ybq.android.spinkit.style.FoldingCube;
import com.github.ybq.android.spinkit.style.ThreeBounce;
import com.github.ybq.android.spinkit.style.Wave;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
@@ -34,6 +43,10 @@ public class Serial_Com extends AppCompatActivity {
public static flag_pojo fobj = new flag_pojo();
int flag=0;
int dev=0;int bas=0;int ru=0;
public static connect_base_flag start_obj = new connect_base_flag();
// ProgressBar progressBar;
/*
* Notifications from UsbService will be received here.
*/
@@ -96,6 +109,11 @@ int dev=0;int bas=0;int ru=0;
Button baseli=(Button) findViewById(R.id.baseline_c);
Button runi=(Button) findViewById(R.id.run_c);
Button next=(Button) findViewById(R.id.next_c);
/* progressBar = (ProgressBar)findViewById(R.id.spin_kit);
Sprite doubleBounce = new ChasingDots();
progressBar.setIndeterminateDrawable(doubleBounce);
progressBar.bringToFront();*/
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -119,49 +137,58 @@ int dev=0;int bas=0;int ru=0;
Log.e("f 555 pixel ", obj.getF_555());
ab_427 = Math.log(Double.parseDouble(obj.getF_427()) / Double.parseDouble(obj.getI_427()));
Log.e("ab 427 ", String.valueOf(ab_427));
ab_555 = Math.log(Double.parseDouble(obj.getF_555()) / Double.parseDouble(obj.getI_555()));
Log.e("ab 555 ", String.valueOf(ab_555));
ratio = ab_555 / ab_427;
Log.e("ratio ", String.valueOf(ratio));
if (ratio < 0.32) {
result = "Healthy";
Log.e("result ", String.valueOf(result));
textViewTitle.setText(result);
} else if (ratio > 0.32 && ratio < 0.475) {
result = "SCT";
Log.e("result ", String.valueOf(result));
textViewTitle.setText(result);
} else if (ratio > 0.475) {
ab_427 = Math.log(Double.parseDouble(obj.getF_427()) / Double.parseDouble(obj.getI_427()));
Log.e("ab 427 ", String.valueOf(ab_427));
result = "SCD";
textViewTitle.setText(result);
Log.e("result ", String.valueOf(result));
ab_555 = Math.log(Double.parseDouble(obj.getF_555()) / Double.parseDouble(obj.getI_555()));
Log.e("ab 555 ", String.valueOf(ab_555));
} else {
ratio = ab_555 / ab_427;
textViewTitle.setText("No Result Try Again");
Log.e("ratio ", String.valueOf(ratio));
if (ratio < 0.32) {
result = "Healthy";
Log.e("result ", String.valueOf(result));
textViewTitle.setText(result);
} else if (ratio > 0.32 && ratio < 0.475) {
result = "SCT";
Log.e("result ", String.valueOf(result));
textViewTitle.setText(result);
} else if (ratio > 0.475) {
result = "SCD";
textViewTitle.setText(result);
Log.e("result ", String.valueOf(result));
} else {
textViewTitle.setText("No Result Try Again");
}
}
} else {
Toast.makeText(Serial_Com.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
}
/* Intent intent=new Intent (Serial_Com.this,run23.class);
startActivity(intent);*/
}
dev=0;ru=0;bas=0;
obj.setI_427(null);
obj.setI_555(null);
obj.setF_427(null);
obj.setF_555(null);
}
@@ -173,73 +200,73 @@ int dev=0;int bas=0;int ru=0;
{
@Override
public void onClick (View v){
fobj.setRun_flag(1);
// progressBar.setVisibility(View.GONE);
fobj.setRun_flag(1);
fobj.setBaseline_flag(0);
fobj.setConnect_flag(0);
ru=1;
if (bas == 1 && dev == 1) {
if (usbService != null) {
try {
int number427 = Integer.valueOf(obj.getX_427());
Thread.sleep(1000);
int number555 = Integer.valueOf(obj.getX_555());
Log.e("Final x value 555", String.valueOf(number555));
Thread.sleep(1000);
String string44 = "print " + number427 + "\r";
usbService.write(string44.getBytes());
Thread.sleep(4000);
Thread.sleep(2000);
String string45 = "print " + number555 + "\r";
usbService.write(string45.getBytes());
Thread.sleep(4000);
Thread.sleep(2000);
} catch (Exception e) {
Toast.makeText(Serial_Com.this, "Perform Run Step Again ", Toast.LENGTH_SHORT).show();
} catch (InterruptedException e) {
e.printStackTrace();
}
if( obj.getF_427() == null && "".equals(obj.getF_427()))
{
Toast.makeText(Serial_Com.this, "Perform Run Step Again ", Toast.LENGTH_SHORT).show();
}
else if( obj.getF_555() == null && "".equals(obj.getF_555()))
{
Toast.makeText(Serial_Com.this, "Perform Run Step Again ", Toast.LENGTH_SHORT).show();
}
else if(((obj.getF_555().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*") ||(obj.getF_427().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*")))
{
Toast.makeText(Serial_Com.this, "Perform Run Step Again ", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(Serial_Com.this, "Done", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(Serial_Com.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
}
/* try {
Thread.sleep(1000);
int number427=Integer.valueOf(obj.getX_427());
Thread.sleep(1000);
int number555=Integer.valueOf(obj.getX_555());
Log.e("Final x value 555", String.valueOf(number555));
Thread.sleep(1000);
String string44 = "print "+number427+"\r";
usbService.write(string44.getBytes());
Thread.sleep(1000);
String string45 = "print "+number555+"\r";
usbService.write(string45.getBytes());
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
*/
} else {
Toast.makeText(Serial_Com.this, "Set Device and Baseline PAramter before ", Toast.LENGTH_SHORT).show();
Toast.makeText(Serial_Com.this, "Set Device and Baseline Parameter before ", Toast.LENGTH_SHORT).show();
}
@@ -253,23 +280,26 @@ Log.e("Final x value 555", String.valueOf(number555));
baseli.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fobj.setBaseline_flag(1);
fobj.setRun_flag(0);
fobj.setConnect_flag(0);
bas=1;
ru=0;
if(dev==1) {
if (flag == 0) {
Log.e("X value 427 usb service", obj.getX_427());
Log.e("X value 555 usb service", obj.getX_555());
String string22 = "led2 50\r";
usbService.write(string22.getBytes());
String string1 = "autoset\r";
usbService.write(string1.getBytes());
try {
Thread.sleep(Long.parseLong("1000"));
String string4 = "run\r";
@@ -291,12 +321,37 @@ Log.e("Final x value 555", String.valueOf(number555));
usbService.write(string44.getBytes());
Thread.sleep(2000);
Thread.sleep(4000);
String string45 = "print " + number555 + "\r";
usbService.write(string45.getBytes());
Thread.sleep(2000);
Thread.sleep(4000);
if(((obj.getI_555().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*") ||(obj.getI_427().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*")))
{
Toast.makeText(Serial_Com.this, "Perform Baseline Step Again ", Toast.LENGTH_SHORT).show();
}
if( obj.getI_427() == null && "".equals(obj.getI_427()))
{
Toast.makeText(Serial_Com.this, "Perform Baseline Step Again ", Toast.LENGTH_SHORT).show();
}
else if( obj.getI_555() == null && "".equals(obj.getI_555()))
{
Toast.makeText(Serial_Com.this, "Perform Baseline Step Again ", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(Serial_Com.this, "Done", Toast.LENGTH_SHORT).show();
}
} catch (InterruptedException e) {
@@ -305,55 +360,6 @@ Log.e("Final x value 555", String.valueOf(number555));
/* String string22 = "led2 50\r";
usbService.write(string22.getBytes());
String string1 = "autoset\r";
usbService.write(string1.getBytes());
try {
Thread.sleep(Long.parseLong("1000"));
String string4 = "run\r";
Thread.sleep(2000);
usbService.write(string4.getBytes());
Thread.sleep(2000);
int number1=45;
Thread.sleep(2000);
usbService.write(string4.getBytes());
Thread.sleep(2000);
String string44 = "print "+number1+"\r";
usbService.write(string44.getBytes());
Thread.sleep(2000);
String string = data + "\r";
usbService.write(string.getBytes());
} catch (InterruptedException e) {
e.printStackTrace();
}*/
// if UsbService was correctly binded, Send data
} else {
Toast.makeText(Serial_Com.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
@@ -370,81 +376,43 @@ Log.e("Final x value 555", String.valueOf(number555));
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
start_obj.setConnect_first_flag(1);
fobj.setConnect_flag(1);
fobj.setBaseline_flag(0);
fobj.setRun_flag(0);
dev=1;
textViewTitle.setText("");
if (flag==0) {
try {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
String string22 = "read\r";
String string22 = "read\r";
usbService.write(string22.getBytes());
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
/* String string22 = "led2 50\r";
usbService.write(string22.getBytes());
String string1 = "autoset\r";
usbService.write(string1.getBytes());
try {
Thread.sleep(Long.parseLong("1000"));
String string4 = "run\r";
Thread.sleep(2000);
usbService.write(string4.getBytes());
Thread.sleep(2000);
int number1=45;
Thread.sleep(2000);
usbService.write(string4.getBytes());
Thread.sleep(2000);
String string44 = "print "+number1+"\r";
usbService.write(string44.getBytes());
Thread.sleep(2000);
usbService.write(string22.getBytes());
}
}, 5000);
String string = data + "\r";
usbService.write(string.getBytes());
} catch (InterruptedException e) {
e.printStackTrace();
}*/
// if UsbService was correctly binded, Send data
}
else
{
Toast.makeText(Serial_Com.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
}
}
});

View File

@@ -12,7 +12,10 @@ import android.hardware.usb.UsbManager;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;
import com.felhr.usbserial.CDCSerialDevice;
import com.felhr.usbserial.UsbSerialDevice;
@@ -26,6 +29,8 @@ import java.util.Map;
import static shanmukha.in.sickle_cell.Serial_Com.fobj;
public class UsbService extends Service {
private Context appContext;
public static final String TAG = "UsbService";
@@ -355,7 +360,7 @@ public class UsbService extends Service {
byte[] received = new byte[n];
System.arraycopy(buffer, 0, received, 0, n);
String receivedStr = new String(received);
Log.e("Recived Data", receivedStr);
// Log.e("Recived Data", receivedStr);
String data = null;
data = new String(received);
@@ -364,57 +369,109 @@ public class UsbService extends Service {
if (fobj.getConnect_flag() == 1) {
if (data.contains(",")) {
try {
Thread.sleep(Long.parseLong("4000"));
} catch (InterruptedException e) {
e.printStackTrace();
try {
if (data.contains(",")) {
String[] namesList = data.split(",");
Double d5 = new Double(namesList[3]);
ddash_427 = (float) (Float.parseFloat(String.valueOf((d5))) - 427.00);
ddash_555 = (float) (Float.parseFloat(String.valueOf((d5))) - 555.00);
BigDecimal d3 = new BigDecimal(namesList[2]);
BigDecimal d1 = new BigDecimal(namesList[1]);
Double d8 = (Double) (-d3.doubleValue() + Math.sqrt(Math.pow(d3.doubleValue(), 2) - 4 * (d1).doubleValue() * ddash_427));
d8 = d8 / (2 * d1.doubleValue());
BigDecimal d11 = new BigDecimal(d8);
wl_427 = (int) Math.round(d8);
obj.setX_427(String.valueOf(wl_427));
Log.e("Value x 427 ", String.valueOf(wl_427));
Log.e("Value x 427 obj ", String.valueOf(obj.getX_427()));
Double d9 = (Double) (-d3.doubleValue() + Math.sqrt(Math.pow(d3.doubleValue(), 2) - 4 * (d1).doubleValue() * ddash_555));
d9 = d9 / (2 * d1.doubleValue());
BigDecimal d12 = new BigDecimal(d9);
wl_555 = (int) Math.round(d9);
Log.e("Value x 555 ", String.valueOf(wl_555));
obj.setX_555(String.valueOf(wl_555));
Log.e("Value x 555 obj ", String.valueOf(obj.getX_555()));
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
if( !(obj.getX_427() == null) && !("".equals(obj.getX_427())))
{
Toast.makeText(UsbService.this, "Done", Toast.LENGTH_SHORT).show();
}
else if( !(obj.getX_555() == null) && !("".equals(obj.getX_555())))
{
Toast.makeText(UsbService.this, "Done", Toast.LENGTH_SHORT).show();
}
}
});
}
String[] namesList = data.split(",");
try {
Thread.sleep(Long.parseLong("4000"));
} catch (InterruptedException e) {
e.printStackTrace();
}
Double d5 = new Double(namesList[3]);
ddash_427 = (float) (Float.parseFloat(String.valueOf((d5))) - 427.00);
ddash_555 = (float) (Float.parseFloat(String.valueOf((d5))) - 555.00);
} catch (Exception e) {
BigDecimal d3 = new BigDecimal(namesList[2]);
BigDecimal d1 = new BigDecimal(namesList[1]);
Double d8 = (Double) (-d3.doubleValue() + Math.sqrt(Math.pow(d3.doubleValue(), 2) - 4 * (d1).doubleValue() * ddash_427));
d8 = d8 / (2 * d1.doubleValue());
BigDecimal d11 = new BigDecimal(d8);
wl_427 = (int) Math.round(d8);
obj.setX_427(String.valueOf(wl_427));
Log.e("Value x 427 ", String.valueOf(wl_427));
Log.e("Value x 427 obj ", String.valueOf(obj.getX_427()));
Double d9 = (Double) (-d3.doubleValue() + Math.sqrt(Math.pow(d3.doubleValue(), 2) - 4 * (d1).doubleValue() * ddash_555));
d9 = d9 / (2 * d1.doubleValue());
BigDecimal d12 = new BigDecimal(d9);
wl_555 = (int) Math.round(d9);
Log.e("Value x 555 ", String.valueOf(wl_555));
obj.setX_555(String.valueOf(wl_555));
Log.e("Value x 555 obj ", String.valueOf(obj.getX_555()));
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Try Again ",
Toast.LENGTH_SHORT).show();
}
});
}
}
if (fobj.getRun_flag()==1)
{
fobj.setBaseline_flag(0);
if (data.contains(String.valueOf(obj.getX_427()))) {
Log.e("final 427 value yes", String.valueOf(data));
String ds2 = data.substring(data.lastIndexOf(":") + 1).trim();
f_427 = ds2;
@@ -422,18 +479,17 @@ public class UsbService extends Service {
obj.setF_427(ds2);
Log.e("Value of initial 427", String.valueOf(f_427));
Log.e("Value of Final ob 427", obj.getF_427());
}
if (data.contains(String.valueOf(obj.getX_555()))) {
Log.e("i 555 value yes", String.valueOf(data));
String ds2 = data.substring(data.lastIndexOf(":") + 1).trim();
f_555 = ds2;
ds2=ds2.replace("OK [0]","");
obj.setF_555(ds2);
Log.e("Value of Final ob 555", obj.getF_555());
Log.e("Value of final 555", String.valueOf(f_555));
}
@@ -441,59 +497,41 @@ public class UsbService extends Service {
}
if (fobj.getBaseline_flag() == 1) {
fobj.setRun_flag(0);
if (data.contains(String.valueOf(obj.getX_427()))) {
Log.e("i 427 value yes", String.valueOf(data));
String ds1 = data.substring(data.lastIndexOf(":") + 1).trim();
i_427 = ds1;
try {
Thread.sleep(Long.parseLong("1000"));
} catch (InterruptedException e) {
e.printStackTrace();
}
ds1=ds1.replace("OK [0]","");
try {
Thread.sleep(Long.parseLong("1000"));
} catch (InterruptedException e) {
e.printStackTrace();
}
Log.e("this is i value",ds1);
obj.setI_427(ds1);
Log.e("Value of initial 427", String.valueOf(i_427));
Log.e("Value of I ob 427", obj.getI_427());
}
if (data.contains(String.valueOf(obj.getX_555()))) {
Log.e("i 555 value ", String.valueOf(data));
String ds2 = data.substring(data.lastIndexOf(":") + 1).trim();
i_555 = ds2;
try {
Thread.sleep(Long.parseLong("1000"));
} catch (InterruptedException e) {
e.printStackTrace();
}
ds2=ds2.replace("OK [0]","");
try {
Thread.sleep(Long.parseLong("1000"));
} catch (InterruptedException e) {
e.printStackTrace();
}
obj.setI_555(ds2);
Log.e("Value of initial 555", String.valueOf(i_555));
Log.e("Value of obj in 427", obj.getI_427());
Log.e("Value of obj in 555", obj.getI_555());
Log.e("Value of Intial ob 555", obj.getI_555());
}
}
}
}
}
}
}

View File

@@ -1,20 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="@android:color/holo_blue_light"/>
<corners
android:radius="16dp" />
<padding
android:left="1dp"
android:right="1dp"
android:top="1dp"
android:bottom="1dp"/>
<solid android:color="@android:color/holo_blue_dark"/>
</shape>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<gradient android:angle="-90" android:startColor="@color/colorPrimary" android:endColor="#689a92" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<solid android:color="#58857e"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<gradient android:angle="-90" android:startColor="#8dbab3" android:endColor="#58857e" />
</shape>
</item>
</selector>

View File

@@ -1,11 +1,10 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
android:background="@drawable/background"
>
<TextView
@@ -15,6 +14,7 @@
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="serial_port"
android:layout_centerInParent="true"
android:visibility="gone"
android:textAppearance="?android:attr/textAppearanceLarge"/>
@@ -37,7 +37,9 @@
android:layout_height="wrap_content"
android:text="Set Baseline"
android:id="@+id/baseline_c"
android:layout_below="@id/buttonSend"
android:layout_centerInParent="true"
android:layout_below="@id/buttonSend"
android:layout_alignParentLeft="true"
android:layout_margin="15dp"
@@ -45,14 +47,32 @@ android:layout_below="@id/buttonSend"
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Run"
android:text="Run After Placing Sample"
android:id="@+id/run_c"
android:layout_below="@id/baseline_c"
android:layout_margin="15dp"
android:layout_centerInParent="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<com.github.ybq.android.spinkit.SpinKitView
android:id="@+id/spin_kit"
android:visibility="gone"
style="@style/SpinKitView.Large.Circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="12dp"
android:layout_marginTop="170dp"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true"
app:SpinKit_Color="@color/colorAccent" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -61,6 +81,7 @@ android:layout_below="@id/buttonSend"
android:layout_below="@id/run_c"
android:layout_alignParentLeft="true"
android:layout_margin="15dp"
android:layout_centerInParent="true"
android:layout_alignParentStart="true"/>
@@ -76,6 +97,7 @@ android:layout_below="@id/buttonSend"
android:layout_alignParentLeft="true"
android:layout_margin="15dp"
android:layout_centerInParent="true"
android:layout_alignParentStart="true"/>
@@ -89,16 +111,21 @@ android:layout_below="@id/buttonSend"
<TextView
android:textSize="30dp"
android:text="Result"
android:textSize="26dp"
android:text="Test Result Display Here"
android:gravity="center"
android:id="@+id/textViewTitle1"
android:textColor="@android:color/white"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="34dp"
android:layout_below="@id/con"
android:layout_centerInParent="true"
/>
</RelativeLayout>

View File

@@ -4,6 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/wvHelp1"
@@ -24,6 +25,7 @@
android:layout_height="wrap_content"
android:id="@+id/sicklecell"
android:textSize="20dp"
android:textColor="@android:color/white"
android:layout_centerHorizontal="true"
android:layout_below="@id/image1"
android:text="Sickle Cell App"/>