Skip to content

Commit 8befffa

Browse files
author
win aung
committed
Cleaned up codes, and improved text styling on gauge page.
1 parent e526770 commit 8befffa

File tree

4 files changed

+33
-16
lines changed

4 files changed

+33
-16
lines changed

androidapp/app/src/main/java/com/cantech/cannect/Dashboard.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public void run() {
184184
Log.d("table", BTPIDs.get(finalI));
185185
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(sendingMessageIntent);
186186
try {
187-
Thread.sleep(1500);
187+
Thread.sleep(1000);
188188
} catch (InterruptedException e) {
189189
// TODO Auto-generated catch block
190190
e.printStackTrace();
@@ -387,23 +387,29 @@ public void onReceive(Context context, Intent intent) {
387387
case "6DOF":
388388
toExport = 1;
389389
String[] data = parsed[1].split(",");
390-
newData = new Data("Acceleration-x",data[0]);
390+
try {
391+
newData = new Data("Acceleration-x", data[0]);
392+
}catch(Exception e) {break; }
391393
for (int i=0;i<dataArrayList.size();i++){
392394
String pid = dataArrayList.get(i).getPid();
393395
if (pid.equals("Acceleration-x")){
394396
dataArrayList.set(i, newData);
395397
break;
396398
}
397399
}
398-
newData = new Data("Acceleration-y",data[1]);
400+
try {
401+
newData = new Data("Acceleration-y", data[1]);
402+
}catch(Exception e) {break; }
399403
for (int i=0;i<dataArrayList.size();i++){
400404
String pid = dataArrayList.get(i).getPid();
401405
if (pid.equals("Acceleration-y")){
402406
dataArrayList.set(i, newData);
403407
break;
404408
}
405409
}
406-
newData = new Data("Acceleration-z",data[2]);
410+
try {
411+
newData = new Data("Acceleration-z", data[2]);
412+
}catch(Exception e) {break; }
407413
for (int i=0;i<dataArrayList.size();i++){
408414
String pid = dataArrayList.get(i).getPid();
409415
if (pid.equals("Acceleration-z")){
@@ -412,23 +418,29 @@ public void onReceive(Context context, Intent intent) {
412418
}
413419
}
414420
//gyro
415-
newData = new Data("Gyroscope-x",data[3]);
421+
try{
422+
newData = new Data("Gyroscope-x",data[3]);
423+
}catch(Exception e) { break;}
416424
for (int i=0;i<dataArrayList.size();i++){
417425
String pid = dataArrayList.get(i).getPid();
418426
if (pid.equals("Gyroscope-x")){
419427
dataArrayList.set(i, newData);
420428
break;
421429
}
422430
}
423-
newData = new Data("Gyroscope-y",data[4]);
431+
try{
432+
newData = new Data("Gyroscope-y",data[4]);
433+
}catch(Exception e) {break; }
424434
for (int i=0;i<dataArrayList.size();i++){
425435
String pid = dataArrayList.get(i).getPid();
426436
if (pid.equals("Gyroscope-y")){
427437
dataArrayList.set(i, newData);
428438
break;
429439
}
430440
}
431-
newData = new Data("Gyroscope-z",data[5]);
441+
try{
442+
newData = new Data("Gyroscope-z",data[5]);
443+
}catch(Exception e) { break;}
432444
for (int i=0;i<dataArrayList.size();i++){
433445
String pid = dataArrayList.get(i).getPid();
434446
if (pid.equals("Gyroscope-z")){
@@ -437,7 +449,9 @@ public void onReceive(Context context, Intent intent) {
437449
}
438450
}
439451
//temp
440-
newData = new Data("Temperature",data[6]);
452+
try {
453+
newData = new Data("Temperature", data[6]);
454+
}catch(Exception e) {break; }
441455
for (int i=0;i<dataArrayList.size();i++){
442456
String pid = dataArrayList.get(i).getPid();
443457
if (pid.equals("Temperature")){

androidapp/app/src/main/java/com/cantech/cannect/Dashboard_chart.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void run(){
178178
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(sendingMessageIntent);
179179
Log.d("chart", BTPIDs);
180180
try {
181-
Thread.sleep(1500);
181+
Thread.sleep(1000);
182182
} catch (InterruptedException e) {
183183
// TODO Auto-generated catch block
184184
e.printStackTrace();
@@ -236,8 +236,7 @@ public void onReceive(Context context, Intent intent) {
236236

237237
float value;
238238
try {
239-
if (!parsed[1].equals("UNDEFINED")) {
240-
value = Float.parseFloat(parsed[1]);
239+
if (!parsed[1].equals("UNDEFINED")) { value = Float.parseFloat(parsed[1]);
241240

242241
} else {
243242
System.out.println("UNDEFINED string received ...");
@@ -357,16 +356,19 @@ protected void reDesignChart(LineDataSet toChange, String str){
357356
case "DEMAND ENGINE TORQUE":
358357
leftAxis.setAxisMinimum(-125f);
359358
leftAxis.setAxisMaximum(130f);
359+
lineDataSet.setColor(getResources().getColor(R.color.Orchid));
360360
BTPIDs = "61 ";
361361
break;
362362
case "FUEL PRESSURE":
363363
leftAxis.setAxisMaximum(765f);
364364
leftAxis.setAxisMinimum(0f);
365+
lineDataSet.setColor(getResources().getColor(R.color.AntiqueWhite));
365366
BTPIDs = "0A ";
366367
break;
367368
case "ACTUAL ENGINE TORQUE":
368369
leftAxis.setAxisMinimum(-125f);
369370
leftAxis.setAxisMaximum(130f);
371+
lineDataSet.setColor(getResources().getColor(R.color.debug_green));
370372
BTPIDs = "62 ";
371373
break;
372374
default:

androidapp/app/src/main/java/com/cantech/cannect/Dashboard_gauge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void run() {
147147
sendingMessageIntent.putExtra("theMessage", "01 " + initialPIDs[finalI] + ">");
148148
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(sendingMessageIntent);
149149
try {
150-
Thread.sleep(1500);
150+
Thread.sleep(1000);
151151
} catch (InterruptedException e) {
152152
// TODO Auto-generated catch block
153153
e.printStackTrace();

androidapp/app/src/main/java/com/cantech/cannect/MainActivity.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected void onCreate(Bundle savedInstanceState) {
7373
// 22 ISO 9141 - 2
7474
// 11 J1850 PWM
7575
// 12 J1850 VPW
76-
protocolList.addAll(Arrays.asList("33" , "34", "35", "36", "11", "22")); // "12", "21", "23", "24", "25"
76+
protocolList.addAll(Arrays.asList("33" , "34", "35", "36", "21", "23", "24", "25", "22")); // "12", "11",
7777
protocolstatus = findViewById(R.id.protocol_text);
7878
protocolstatus.setText(protocol);
7979
ActionBar actionBar = getSupportActionBar();
@@ -115,15 +115,16 @@ public void run(){
115115
LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(sendingMessageIntent);
116116
Log.d("main", sendingMessageIntent.getExtras().toString());
117117
i++;
118-
if(i == protocolList.size()){
119-
break;
120-
}
121118
try {
122119
Thread.sleep(100);
123120
} catch (InterruptedException e) {
124121
// TODO Auto-generated catch block
125122
e.printStackTrace();
126123
}
124+
if(i == protocolList.size()){
125+
break;
126+
}
127+
127128
}
128129
Log.d("main", "thread is existed");
129130
}

0 commit comments

Comments
 (0)