Added First Parameter Step , Stored the device paramters , first paramters and baseline paramters
This commit is contained in:
@@ -11,20 +11,20 @@
|
||||
android:roundIcon="@drawable/shanmukha_logo_small"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name="shanmukha.in.sickle_cell.SplashScreen" android:screenOrientation="portrait"><intent-filter>
|
||||
<activity android:name="shanmukha.in.sickle_cell.UI.SplashScreen" android:screenOrientation="portrait"><intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="shanmukha.in.sickle_cell.Serial_Com" android:screenOrientation="portrait"> <intent-filter>
|
||||
</activity>
|
||||
<activity android:name="shanmukha.in.sickle_cell.UI.SerialData" android:screenOrientation="portrait"> <intent-filter>
|
||||
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
|
||||
</intent-filter></activity>
|
||||
|
||||
<service
|
||||
android:name="shanmukha.in.sickle_cell.UsbService"
|
||||
android:name="shanmukha.in.sickle_cell.Service.UsbService"
|
||||
android:enabled="true">
|
||||
</service>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package shanmukha.in.sickle_cell.Model;
|
||||
|
||||
public class PojoStatus {
|
||||
private int device_para_flag;
|
||||
private int org_para_flag;
|
||||
private int base_para_flag;
|
||||
|
||||
public int getBase_para_flag() {
|
||||
return base_para_flag;
|
||||
}
|
||||
|
||||
public void setBase_para_flag(int base_para_flag) {
|
||||
this.base_para_flag = base_para_flag;
|
||||
}
|
||||
|
||||
public int getDevice_para_flag() {
|
||||
return device_para_flag;
|
||||
}
|
||||
|
||||
public void setDevice_para_flag(int device_para_flag) {
|
||||
this.device_para_flag = device_para_flag;
|
||||
}
|
||||
|
||||
public int getOrg_para_flag() {
|
||||
return org_para_flag;
|
||||
}
|
||||
|
||||
public void setOrg_para_flag(int org_para_flag) {
|
||||
this.org_para_flag = org_para_flag;
|
||||
}
|
||||
}
|
||||
@@ -1,540 +0,0 @@
|
||||
package shanmukha.in.sickle_cell;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.DialogInterface;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.os.Bundle;
|
||||
|
||||
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.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;
|
||||
import java.util.Set;
|
||||
|
||||
import static shanmukha.in.sickle_cell.UsbService.obj;
|
||||
|
||||
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.
|
||||
*/
|
||||
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
|
||||
flag=0;
|
||||
|
||||
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();
|
||||
flag=1;
|
||||
|
||||
break;
|
||||
case UsbService.ACTION_NO_USB: // NO USB CONNECTED
|
||||
Toast.makeText(context, "No USB connected", Toast.LENGTH_SHORT).show();
|
||||
flag=1;
|
||||
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 MyHandler mHandler;
|
||||
double ratio,ab_427,ab_555;
|
||||
private static final String ACTION_USB_PERMISSION = "shanmukha.in.sickle_cell.USB_PERMISSION";
|
||||
private TextView textViewTitle ;
|
||||
String result;
|
||||
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_serial);
|
||||
|
||||
mHandler = new MyHandler(this);
|
||||
textViewTitle=findViewById(R.id.textViewTitle1);
|
||||
|
||||
Button sendButton = (Button) findViewById(R.id.buttonSend);
|
||||
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) {
|
||||
if (dev == 1 && bas == 1 && ru == 1) {
|
||||
|
||||
|
||||
if (flag != 1) {
|
||||
|
||||
|
||||
Log.e("x 427 pixel ", obj.getX_427());
|
||||
Log.e("x 555 pixel ", obj.getX_555());
|
||||
|
||||
|
||||
Log.e("i 427 pixel ", obj.getI_427());
|
||||
|
||||
Log.e("i 555 pixel ", obj.getI_555());
|
||||
|
||||
|
||||
Log.e("f 427 pixel ", obj.getF_427());
|
||||
|
||||
|
||||
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) {
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
runi.setOnClickListener(new View.OnClickListener()
|
||||
|
||||
{
|
||||
@Override
|
||||
public void onClick (View v){
|
||||
// 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());
|
||||
|
||||
int number555 = Integer.valueOf(obj.getX_555());
|
||||
|
||||
|
||||
|
||||
|
||||
String string44 = "print " + number427 + "\r";
|
||||
usbService.write(string44.getBytes());
|
||||
Thread.sleep(4000);
|
||||
|
||||
String string45 = "print " + number555 + "\r";
|
||||
usbService.write(string45.getBytes());
|
||||
Thread.sleep(4000);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(Serial_Com.this, "Perform Run Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(Serial_Com.this, "Set Device and Baseline Parameter before ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
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) {
|
||||
|
||||
|
||||
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 number427 = Integer.valueOf(obj.getX_427());
|
||||
Thread.sleep(1000);
|
||||
|
||||
int number555 = Integer.valueOf(obj.getX_555());
|
||||
|
||||
|
||||
Thread.sleep(2000);
|
||||
String string44 = "print " + number427 + "\r";
|
||||
usbService.write(string44.getBytes());
|
||||
|
||||
|
||||
Thread.sleep(4000);
|
||||
String string45 = "print " + number555 + "\r";
|
||||
usbService.write(string45.getBytes());
|
||||
|
||||
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(Serial_Com.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Toast.makeText(Serial_Com.this, "Get Device Parameters First ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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) {
|
||||
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String string22 = "read\r";
|
||||
|
||||
usbService.write(string22.getBytes());
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Toast.makeText(Serial_Com.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@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<Serial_Com> mActivity;
|
||||
|
||||
public MyHandler(Serial_Com activity) {
|
||||
mActivity = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case UsbService.MESSAGE_FROM_SERIAL_PORT:
|
||||
String data = (String) msg.obj;
|
||||
break;
|
||||
|
||||
case UsbService.SYNC_READ:
|
||||
String buffer = (String) msg.obj;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onClickconectar(View view) {
|
||||
UsbService sf=new UsbService();
|
||||
HashMap<String, UsbDevice> usbDevices = sf.usbManager.getDeviceList();
|
||||
if (!usbDevices.isEmpty()) {
|
||||
boolean keep = true;
|
||||
for (Map.Entry<String, UsbDevice> entry : usbDevices.entrySet()) {
|
||||
flag=0;
|
||||
|
||||
sf.device = entry.getValue();
|
||||
int deviceVID = sf.device.getVendorId();
|
||||
if (deviceVID == 0x0403 || deviceVID == 0x0403)// Arduino Vendor ID
|
||||
//if(deviceVID == 0x2341)// Arduino Vendor ID
|
||||
{
|
||||
PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
|
||||
sf.usbManager.requestPermission(sf.device, pi);
|
||||
keep = false;
|
||||
} else {
|
||||
sf.connection = null;
|
||||
sf.device = null;
|
||||
}
|
||||
|
||||
if (!keep)
|
||||
break;
|
||||
flag=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setCancelable(false);
|
||||
builder.setMessage("Do you want to Exit ?");
|
||||
|
||||
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
finishAffinity();
|
||||
finish();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package shanmukha.in.sickle_cell;
|
||||
package shanmukha.in.sickle_cell.Service;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
@@ -13,7 +13,6 @@ 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;
|
||||
|
||||
@@ -26,13 +25,17 @@ import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static shanmukha.in.sickle_cell.Serial_Com.fobj;
|
||||
import shanmukha.in.sickle_cell.Model.PojoParameters;
|
||||
|
||||
import static shanmukha.in.sickle_cell.UI.SerialData.fobj;
|
||||
|
||||
|
||||
public class UsbService extends Service {
|
||||
private Context appContext;
|
||||
|
||||
|
||||
public static final String TAG = "UsbService";
|
||||
public static int tr = 0;
|
||||
|
||||
public static final String ACTION_USB_READY = "USB_READY";
|
||||
public static final String ACTION_USB_ATTACHED = "USB_DEVICE_ATTACHED";
|
||||
@@ -62,14 +65,10 @@ public class UsbService extends Service {
|
||||
private UsbSerialDevice serialPort;
|
||||
float a, b, c, d, ddash_427, ddash_555;
|
||||
int wl_427, wl_555;
|
||||
String i_427, i_555,f_427,f_555;
|
||||
public static pojo obj = new pojo();
|
||||
String i_427, i_555, f_427, f_555, o_427, o_555;
|
||||
public static PojoParameters obj = new PojoParameters();
|
||||
private boolean serialPortConnected;
|
||||
/*
|
||||
* Data received from serial port will be received here. Just populate onReceivedData with your code
|
||||
* In this particular example. byte stream is converted to String and send to UI thread to
|
||||
* be treated there.
|
||||
*/
|
||||
|
||||
private UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() {
|
||||
@Override
|
||||
public void onReceivedData(byte[] arg0) {
|
||||
@@ -105,7 +104,6 @@ public class UsbService extends Service {
|
||||
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);
|
||||
@@ -116,11 +114,10 @@ public class UsbService extends Service {
|
||||
Log.e("Value x 555 obj ", String.valueOf(obj.getX_555()));
|
||||
|
||||
|
||||
}
|
||||
} catch (UnsupportedEncodingException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
@@ -138,7 +135,7 @@ public class UsbService extends Service {
|
||||
private UsbSerialInterface.UsbCTSCallback ctsCallback = new UsbSerialInterface.UsbCTSCallback() {
|
||||
@Override
|
||||
public void onCTSChanged(boolean state) {
|
||||
if(mHandler != null)
|
||||
if (mHandler != null)
|
||||
mHandler.obtainMessage(CTS_CHANGE).sendToTarget();
|
||||
}
|
||||
};
|
||||
@@ -149,7 +146,7 @@ public class UsbService extends Service {
|
||||
private UsbSerialInterface.UsbDSRCallback dsrCallback = new UsbSerialInterface.UsbDSRCallback() {
|
||||
@Override
|
||||
public void onDSRChanged(boolean state) {
|
||||
if(mHandler != null)
|
||||
if (mHandler != null)
|
||||
mHandler.obtainMessage(DSR_CHANGE).sendToTarget();
|
||||
}
|
||||
};
|
||||
@@ -233,8 +230,8 @@ public class UsbService extends Service {
|
||||
* This function will be called from MainActivity to change baud rate
|
||||
*/
|
||||
|
||||
public void changeBaudRate(int baudRate){
|
||||
if(serialPort != null)
|
||||
public void changeBaudRate(int baudRate) {
|
||||
if (serialPort != null)
|
||||
serialPort.setBaudRate(baudRate);
|
||||
}
|
||||
|
||||
@@ -272,13 +269,13 @@ public class UsbService extends Service {
|
||||
device = null;
|
||||
}
|
||||
}
|
||||
if (device==null) {
|
||||
if (device == null) {
|
||||
// There is 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." );
|
||||
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);
|
||||
@@ -297,7 +294,7 @@ public class UsbService extends Service {
|
||||
* 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() ) );
|
||||
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);
|
||||
}
|
||||
@@ -335,7 +332,7 @@ public class UsbService extends Service {
|
||||
Intent intent = new Intent(ACTION_USB_READY);
|
||||
context.sendBroadcast(intent);
|
||||
} else {
|
||||
if (serialPort instanceof CDCSerialDevice) {
|
||||
if (serialPort instanceof CDCSerialDevice) {
|
||||
Intent intent = new Intent(ACTION_CDC_DRIVER_NOT_WORKING);
|
||||
context.sendBroadcast(intent);
|
||||
} else {
|
||||
@@ -360,7 +357,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);
|
||||
@@ -373,7 +370,6 @@ public class UsbService extends Service {
|
||||
if (data.contains(",")) {
|
||||
|
||||
|
||||
|
||||
String[] namesList = data.split(",");
|
||||
|
||||
Double d5 = new Double(namesList[3]);
|
||||
@@ -407,60 +403,36 @@ public class UsbService extends Service {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if( !(obj.getX_427() == null) && !("".equals(obj.getX_427())))
|
||||
{
|
||||
Toast.makeText(UsbService.this, "Done", Toast.LENGTH_SHORT).show();
|
||||
if (tr == 0) {
|
||||
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();
|
||||
} else if (!(obj.getX_555() == null) && !("".equals(obj.getX_555()))) {
|
||||
Toast.makeText(UsbService.this, "Done", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
} else {
|
||||
tr = 0;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Try Again ",
|
||||
"Try Again ",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
tr = 1;
|
||||
|
||||
}
|
||||
});
|
||||
@@ -469,13 +441,12 @@ public class UsbService extends Service {
|
||||
|
||||
}
|
||||
|
||||
if (fobj.getRun_flag()==1)
|
||||
{
|
||||
if (fobj.getRun_flag() == 1) {
|
||||
if (data.contains(String.valueOf(obj.getX_427()))) {
|
||||
String ds2 = data.substring(data.lastIndexOf(":") + 1).trim();
|
||||
f_427 = ds2;
|
||||
|
||||
ds2=ds2.replace("OK [0]","");
|
||||
ds2 = ds2.replace("OK [0]", "");
|
||||
|
||||
|
||||
obj.setF_427(ds2);
|
||||
@@ -486,7 +457,7 @@ public class UsbService extends Service {
|
||||
|
||||
String ds2 = data.substring(data.lastIndexOf(":") + 1).trim();
|
||||
f_555 = ds2;
|
||||
ds2=ds2.replace("OK [0]","");
|
||||
ds2 = ds2.replace("OK [0]", "");
|
||||
obj.setF_555(ds2);
|
||||
Log.e("Value of Final ob 555", obj.getF_555());
|
||||
|
||||
@@ -494,7 +465,6 @@ public class UsbService extends Service {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
if (fobj.getBaseline_flag() == 1) {
|
||||
|
||||
@@ -503,7 +473,7 @@ public class UsbService extends Service {
|
||||
String ds1 = data.substring(data.lastIndexOf(":") + 1).trim();
|
||||
i_427 = ds1;
|
||||
|
||||
ds1=ds1.replace("OK [0]","");
|
||||
ds1 = ds1.replace("OK [0]", "");
|
||||
|
||||
obj.setI_427(ds1);
|
||||
Log.e("Value of I ob 427", obj.getI_427());
|
||||
@@ -515,7 +485,7 @@ public class UsbService extends Service {
|
||||
String ds2 = data.substring(data.lastIndexOf(":") + 1).trim();
|
||||
i_555 = ds2;
|
||||
|
||||
ds2=ds2.replace("OK [0]","");
|
||||
ds2 = ds2.replace("OK [0]", "");
|
||||
|
||||
obj.setI_555(ds2);
|
||||
|
||||
@@ -528,6 +498,38 @@ public class UsbService extends Service {
|
||||
}
|
||||
|
||||
|
||||
if (fobj.getOrg_flag() == 1) {
|
||||
|
||||
if (data.contains(String.valueOf(obj.getX_427()))) {
|
||||
|
||||
String ds1 = data.substring(data.lastIndexOf(":") + 1).trim();
|
||||
o_427 = ds1;
|
||||
|
||||
ds1 = ds1.replace("OK [0]", "");
|
||||
|
||||
obj.setO_427(ds1);
|
||||
Log.e("Value of Org ob 427", obj.getO_427());
|
||||
|
||||
|
||||
}
|
||||
if (data.contains(String.valueOf(obj.getX_555()))) {
|
||||
|
||||
String ds2 = data.substring(data.lastIndexOf(":") + 1).trim();
|
||||
o_555 = ds2;
|
||||
|
||||
ds2 = ds2.replace("OK [0]", "");
|
||||
|
||||
obj.setO_555(ds2);
|
||||
|
||||
Log.e("Value of org ob 555", obj.getO_555());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
864
app/src/main/java/shanmukha/in/sickle_cell/UI/SerialData.java
Normal file
864
app/src/main/java/shanmukha/in/sickle_cell/UI/SerialData.java
Normal file
@@ -0,0 +1,864 @@
|
||||
package shanmukha.in.sickle_cell.UI;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.ServiceConnection;
|
||||
import android.hardware.usb.UsbDevice;
|
||||
import android.os.Bundle;
|
||||
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.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import shanmukha.in.sickle_cell.Model.PojoFlag;
|
||||
import shanmukha.in.sickle_cell.Model.PojoStatus;
|
||||
import shanmukha.in.sickle_cell.R;
|
||||
import shanmukha.in.sickle_cell.Service.UsbService;
|
||||
|
||||
import static shanmukha.in.sickle_cell.Service.UsbService.obj;
|
||||
|
||||
|
||||
public class SerialData extends AppCompatActivity {
|
||||
public static PojoFlag fobj = new PojoFlag();
|
||||
int flag = 0;
|
||||
int dev = 0;
|
||||
int bas = 0;
|
||||
int ru = 0;
|
||||
public static PojoFlag start_obj = new PojoFlag();
|
||||
public static PojoStatus sta = new PojoStatus();
|
||||
|
||||
|
||||
// ProgressBar progressBar;
|
||||
/*
|
||||
* 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
|
||||
flag = 0;
|
||||
|
||||
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();
|
||||
flag = 1;
|
||||
|
||||
break;
|
||||
case UsbService.ACTION_NO_USB: // NO USB CONNECTED
|
||||
Toast.makeText(context, "No USB connected", Toast.LENGTH_SHORT).show();
|
||||
flag = 1;
|
||||
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 MyHandler mHandler;
|
||||
double ratio, ab_427, ab_555;
|
||||
private static final String ACTION_USB_PERMISSION = "shanmukha.in.sickle_cell.USB_PERMISSION";
|
||||
private TextView textViewTitle;
|
||||
String result;
|
||||
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_serial);
|
||||
|
||||
mHandler = new MyHandler(this);
|
||||
textViewTitle = findViewById(R.id.textViewTitle1);
|
||||
|
||||
Button sendButton = (Button) findViewById(R.id.buttonSend);
|
||||
Button baseli = (Button) findViewById(R.id.baseline_c);
|
||||
Button runi = (Button) findViewById(R.id.run_c);
|
||||
Button next = (Button) findViewById(R.id.next_c);
|
||||
Button org = (Button) findViewById(R.id.or_c);
|
||||
/* progressBar = (ProgressBar)findViewById(R.id.spin_kit);
|
||||
Sprite doubleBounce = new ChasingDots();
|
||||
progressBar.setIndeterminateDrawable(doubleBounce);
|
||||
progressBar.bringToFront();*/
|
||||
org.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (sta.getOrg_para_flag() == 1) {
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(SerialData.this);
|
||||
builder.setCancelable(false);
|
||||
builder.setMessage("Do you want to Set Orginal Parameters again ?");
|
||||
|
||||
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
Log.e("x in 427 pixel ", obj.getO_427());
|
||||
Log.e("x in 555 pixel ", obj.getO_555());
|
||||
fobj.setOrg_flag(1);
|
||||
fobj.setBaseline_flag(0);
|
||||
fobj.setRun_flag(0);
|
||||
fobj.setConnect_flag(0);
|
||||
bas = 1;
|
||||
ru = 0;
|
||||
|
||||
if (flag == 0 && obj.getO_427() != null && !"".equals(obj.getO_427()) && obj.getO_555() != null && !"".equals(obj.getO_555())) {
|
||||
|
||||
|
||||
try {
|
||||
String string22 = "led2 50\r";
|
||||
|
||||
usbService.write(string22.getBytes());
|
||||
Thread.sleep(2000);
|
||||
|
||||
String string1 = "autoset\r";
|
||||
usbService.write(string1.getBytes());
|
||||
Thread.sleep(2000);
|
||||
|
||||
Thread.sleep(Long.parseLong("1000"));
|
||||
String string4 = "run\r";
|
||||
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
usbService.write(string4.getBytes());
|
||||
Thread.sleep(2000);
|
||||
|
||||
int number427 = Integer.valueOf(obj.getX_427());
|
||||
Thread.sleep(1000);
|
||||
|
||||
int number555 = Integer.valueOf(obj.getX_555());
|
||||
|
||||
|
||||
Thread.sleep(2000);
|
||||
String string44 = "print " + number427 + "\r";
|
||||
usbService.write(string44.getBytes());
|
||||
|
||||
|
||||
Thread.sleep(6000);
|
||||
String string45 = "print " + number555 + "\r";
|
||||
usbService.write(string45.getBytes());
|
||||
|
||||
|
||||
Thread.sleep(6000);
|
||||
|
||||
|
||||
if (obj.getO_427() == null && "".equals(obj.getO_427())) {
|
||||
Toast.makeText(SerialData.this, "Perform Orignal Paramter Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else if (obj.getO_555() == null && "".equals(obj.getO_555())) {
|
||||
Toast.makeText(SerialData.this, "Perform Orignal Paramter Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else if (((obj.getO_555().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*") || (obj.getO_427().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*"))) {
|
||||
Toast.makeText(SerialData.this, "Perform Orignal Paramter Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "Done", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Log.e("x O 427 pixel ", obj.getO_427());
|
||||
Log.e("x O 555 pixel ", obj.getO_555());
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
|
||||
|
||||
} else {
|
||||
fobj.setOrg_flag(1);
|
||||
fobj.setBaseline_flag(0);
|
||||
fobj.setRun_flag(0);
|
||||
fobj.setConnect_flag(0);
|
||||
bas = 1;
|
||||
ru = 0;
|
||||
if (dev == 1) {
|
||||
if (flag == 0) {
|
||||
|
||||
|
||||
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 number427 = Integer.valueOf(obj.getX_427());
|
||||
Thread.sleep(1000);
|
||||
|
||||
int number555 = Integer.valueOf(obj.getX_555());
|
||||
|
||||
|
||||
Thread.sleep(2000);
|
||||
String string44 = "print " + number427 + "\r";
|
||||
usbService.write(string44.getBytes());
|
||||
|
||||
|
||||
Thread.sleep(6000);
|
||||
String string45 = "print " + number555 + "\r";
|
||||
usbService.write(string45.getBytes());
|
||||
|
||||
|
||||
Thread.sleep(6000);
|
||||
|
||||
|
||||
if (((obj.getO_555().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*") || (obj.getO_427().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*"))) {
|
||||
Toast.makeText(SerialData.this, "Perform Orignal Paramter Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
if (obj.getO_427() == null && "".equals(obj.getO_427())) {
|
||||
Toast.makeText(SerialData.this, "Perform Orignal Paramter Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else if (obj.getO_555() == null && "".equals(obj.getO_555())) {
|
||||
Toast.makeText(SerialData.this, "Perform Orignal Paramter Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "Done", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "Get Device Parameters First ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sta.setOrg_para_flag(1);
|
||||
}
|
||||
});
|
||||
|
||||
next.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try {
|
||||
if (flag != 1) {
|
||||
|
||||
|
||||
Log.e("x 427 pixel ", obj.getX_427());
|
||||
Log.e("x 555 pixel ", obj.getX_555());
|
||||
|
||||
|
||||
Log.e("i 427 pixel ", obj.getI_427());
|
||||
|
||||
Log.e("i 555 pixel ", obj.getI_555());
|
||||
|
||||
|
||||
Log.e("f 427 pixel ", obj.getF_427());
|
||||
|
||||
|
||||
Log.e("f 555 pixel ", obj.getF_555());
|
||||
Log.e("O 555 pixel ", obj.getO_555());
|
||||
|
||||
Log.e("O 427 pixel ", obj.getO_427());
|
||||
|
||||
|
||||
ab_427 = Math.log10(Double.parseDouble(obj.getO_427()) / (Double.parseDouble(obj.getI_427()) - Double.parseDouble(obj.getF_427())));
|
||||
Log.e("without log value 427", String.valueOf(Double.parseDouble(obj.getO_427()) / (Double.parseDouble(obj.getI_427()) - Double.parseDouble(obj.getF_427()))));
|
||||
Log.e("ab 427", String.valueOf(ab_427));
|
||||
|
||||
|
||||
ab_555 = Math.log10(Double.parseDouble(obj.getO_555()) / (Double.parseDouble(obj.getI_555()) - Double.parseDouble(obj.getF_555())));
|
||||
Log.e("without log value 555", String.valueOf(Double.parseDouble(obj.getO_555()) / (Double.parseDouble(obj.getI_555()) - Double.parseDouble(obj.getF_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) {
|
||||
|
||||
result = "SCD";
|
||||
textViewTitle.setText(result);
|
||||
|
||||
Log.e("result ", String.valueOf(result));
|
||||
|
||||
} else {
|
||||
|
||||
textViewTitle.setText("No Result Try Again");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
dev = 0;
|
||||
ru = 0;
|
||||
bas = 0;
|
||||
/* obj.setI_427(null);
|
||||
obj.setI_555(null);*/
|
||||
obj.setF_427(null);
|
||||
obj.setF_555(null);
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(SerialData.this, "Please Complete all steps ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
runi.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// progressBar.setVisibility(View.GONE);
|
||||
|
||||
fobj.setRun_flag(1);
|
||||
fobj.setBaseline_flag(0);
|
||||
fobj.setConnect_flag(0);
|
||||
fobj.setOrg_flag(0);
|
||||
|
||||
ru = 1;
|
||||
|
||||
if (usbService != null) {
|
||||
|
||||
try {
|
||||
|
||||
int number427 = Integer.valueOf(obj.getX_427());
|
||||
|
||||
int number555 = Integer.valueOf(obj.getX_555());
|
||||
|
||||
|
||||
String string4 = "run\r";
|
||||
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
usbService.write(string4.getBytes());
|
||||
Thread.sleep(5000);
|
||||
|
||||
String string44 = "print " + number427 + "\r";
|
||||
usbService.write(string44.getBytes());
|
||||
Thread.sleep(4000);
|
||||
|
||||
String string45 = "print " + number555 + "\r";
|
||||
usbService.write(string45.getBytes());
|
||||
Thread.sleep(4000);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(SerialData.this, "Perform Run Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (obj.getF_427() == null && "".equals(obj.getF_427())) {
|
||||
Toast.makeText(SerialData.this, "Perform Run Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else if (obj.getF_555() == null && "".equals(obj.getF_555())) {
|
||||
Toast.makeText(SerialData.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(SerialData.this, "Perform Run Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "Done", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
baseli.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
if (sta.getBase_para_flag() == 1 && obj.getI_427() != null && !"".equals(obj.getI_427()) && obj.getI_555() != null && !"".equals(obj.getI_555())) {
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(SerialData.this);
|
||||
builder.setCancelable(false);
|
||||
builder.setMessage("Do you want to Set Baseline Parameters again ?");
|
||||
|
||||
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Log.e("x in 427 pixel ", obj.getI_427());
|
||||
Log.e("x in 555 pixel ", obj.getI_555());
|
||||
fobj.setBaseline_flag(1);
|
||||
fobj.setRun_flag(0);
|
||||
fobj.setConnect_flag(0);
|
||||
fobj.setOrg_flag(0);
|
||||
bas = 1;
|
||||
ru = 0;
|
||||
|
||||
if (flag == 0) {
|
||||
|
||||
|
||||
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 number427 = Integer.valueOf(obj.getX_427());
|
||||
Thread.sleep(1000);
|
||||
|
||||
int number555 = Integer.valueOf(obj.getX_555());
|
||||
|
||||
|
||||
Thread.sleep(2000);
|
||||
String string44 = "print " + number427 + "\r";
|
||||
usbService.write(string44.getBytes());
|
||||
|
||||
|
||||
Thread.sleep(4000);
|
||||
String string45 = "print " + number555 + "\r";
|
||||
usbService.write(string45.getBytes());
|
||||
|
||||
|
||||
Thread.sleep(4000);
|
||||
|
||||
|
||||
if (obj.getI_427() == null && "".equals(obj.getI_427())) {
|
||||
Toast.makeText(SerialData.this, "Perform Baseline Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else if (obj.getI_555() == null && "".equals(obj.getI_555())) {
|
||||
Toast.makeText(SerialData.this, "Perform Baseline Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else if (((obj.getI_555().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*") || (obj.getI_427().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*"))) {
|
||||
Toast.makeText(SerialData.this, "Perform Baseline Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "Done", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Log.e("x in 427 pixel ", obj.getI_427());
|
||||
Log.e("x in 555 pixel ", obj.getI_555());
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
|
||||
|
||||
} else {
|
||||
fobj.setBaseline_flag(1);
|
||||
fobj.setRun_flag(0);
|
||||
fobj.setConnect_flag(0);
|
||||
fobj.setOrg_flag(0);
|
||||
bas = 1;
|
||||
ru = 0;
|
||||
|
||||
if (flag == 0) {
|
||||
|
||||
|
||||
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 number427 = Integer.valueOf(obj.getX_427());
|
||||
Thread.sleep(1000);
|
||||
|
||||
int number555 = Integer.valueOf(obj.getX_555());
|
||||
|
||||
|
||||
Thread.sleep(2000);
|
||||
String string44 = "print " + number427 + "\r";
|
||||
usbService.write(string44.getBytes());
|
||||
|
||||
|
||||
Thread.sleep(4000);
|
||||
String string45 = "print " + number555 + "\r";
|
||||
usbService.write(string45.getBytes());
|
||||
|
||||
|
||||
Thread.sleep(4000);
|
||||
|
||||
|
||||
if (obj.getI_427() == null && "".equals(obj.getI_427())) {
|
||||
Toast.makeText(SerialData.this, "Perform Baseline Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else if (obj.getI_555() == null && "".equals(obj.getI_555())) {
|
||||
Toast.makeText(SerialData.this, "Perform Baseline Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else if (((obj.getI_555().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*") || (obj.getI_427().replaceAll("\\s", "")).matches(".*[a-zA-Z]+.*"))) {
|
||||
Toast.makeText(SerialData.this, "Perform Baseline Step Again ", Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "Done", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
sta.setBase_para_flag(1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
sendButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (sta.getDevice_para_flag() == 1 && obj.getX_427() != null && !"".equals(obj.getX_427()) && obj.getX_555() != null && !"".equals(obj.getX_555())) {
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(SerialData.this);
|
||||
builder.setCancelable(false);
|
||||
builder.setMessage("Do you want to Set Device Parameters again ?");
|
||||
|
||||
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
Log.e("x 427 pixel ", obj.getX_427());
|
||||
Log.e("x 555 pixel ", obj.getX_555());
|
||||
|
||||
start_obj.setConnect_flag(1);
|
||||
|
||||
|
||||
fobj.setConnect_flag(1);
|
||||
fobj.setOrg_flag(0);
|
||||
|
||||
fobj.setBaseline_flag(0);
|
||||
fobj.setRun_flag(0);
|
||||
|
||||
dev = 1;
|
||||
textViewTitle.setText("");
|
||||
if (flag == 0) {
|
||||
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String string22 = "read\r";
|
||||
|
||||
usbService.write(string22.getBytes());
|
||||
|
||||
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
sta.setDevice_para_flag(1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
Log.e("x 427 pixel ", obj.getX_427());
|
||||
Log.e("x 555 pixel ", obj.getX_555());
|
||||
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
|
||||
|
||||
} else {
|
||||
start_obj.setConnect_flag(1);
|
||||
|
||||
|
||||
fobj.setConnect_flag(1);
|
||||
|
||||
fobj.setBaseline_flag(0);
|
||||
fobj.setRun_flag(0);
|
||||
fobj.setOrg_flag(0);
|
||||
|
||||
dev = 1;
|
||||
textViewTitle.setText("");
|
||||
if (flag == 0) {
|
||||
|
||||
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String string22 = "read\r";
|
||||
|
||||
usbService.write(string22.getBytes());
|
||||
|
||||
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
|
||||
} else {
|
||||
Toast.makeText(SerialData.this, "USB Not Connect", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
sta.setDevice_para_flag(1);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
@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<SerialData> mActivity;
|
||||
|
||||
public MyHandler(SerialData activity) {
|
||||
mActivity = new WeakReference<>(activity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case UsbService.MESSAGE_FROM_SERIAL_PORT:
|
||||
String data = (String) msg.obj;
|
||||
break;
|
||||
|
||||
case UsbService.SYNC_READ:
|
||||
String buffer = (String) msg.obj;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onClickconectar(View view) {
|
||||
UsbService sf = new UsbService();
|
||||
HashMap<String, UsbDevice> usbDevices = sf.usbManager.getDeviceList();
|
||||
if (!usbDevices.isEmpty()) {
|
||||
boolean keep = true;
|
||||
for (Map.Entry<String, UsbDevice> entry : usbDevices.entrySet()) {
|
||||
flag = 0;
|
||||
|
||||
sf.device = entry.getValue();
|
||||
int deviceVID = sf.device.getVendorId();
|
||||
if (deviceVID == 0x0403 || deviceVID == 0x0403)// Arduino Vendor ID
|
||||
//if(deviceVID == 0x2341)// Arduino Vendor ID
|
||||
{
|
||||
PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
|
||||
sf.usbManager.requestPermission(sf.device, pi);
|
||||
keep = false;
|
||||
} else {
|
||||
sf.connection = null;
|
||||
sf.device = null;
|
||||
}
|
||||
|
||||
if (!keep)
|
||||
break;
|
||||
flag = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setCancelable(false);
|
||||
builder.setMessage("Do you want to Exit ?");
|
||||
|
||||
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
finishAffinity();
|
||||
finish();
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
|
||||
}
|
||||
BIN
app/src/main/res/drawable/background.jpg
Normal file
BIN
app/src/main/res/drawable/background.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 285 KiB |
@@ -39,7 +39,7 @@ android:background="@drawable/background"
|
||||
android:id="@+id/baseline_c"
|
||||
android:layout_centerInParent="true"
|
||||
|
||||
android:layout_below="@id/buttonSend"
|
||||
android:layout_below="@id/or_c"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_margin="15dp"
|
||||
|
||||
@@ -102,6 +102,20 @@ android:background="@drawable/background"
|
||||
android:layout_alignParentStart="true"/>
|
||||
|
||||
|
||||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="First Parameter"
|
||||
android:id="@+id/or_c"
|
||||
android:onClick="onClickconectar"
|
||||
android:layout_below="@id/buttonSend"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_margin="15dp"
|
||||
|
||||
android:layout_centerInParent="true"
|
||||
|
||||
android:layout_alignParentStart="true"/>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user