|
14 | 14 | import android.support.v7.widget.LinearLayoutManager; |
15 | 15 | import android.support.v7.widget.RecyclerView; |
16 | 16 | import android.support.v7.widget.Toolbar; |
| 17 | +import android.util.Log; |
17 | 18 | import android.view.Menu; |
18 | 19 | import android.view.MenuItem; |
19 | 20 | import android.view.View; |
|
40 | 41 | import io.pslab.models.GyroData; |
41 | 42 | import io.pslab.models.LuxData; |
42 | 43 | import io.pslab.models.SensorDataBlock; |
| 44 | +import io.pslab.models.ServoData; |
| 45 | +import io.pslab.models.ThermometerData; |
43 | 46 | import io.pslab.others.CSVLogger; |
44 | 47 | import io.pslab.others.LocalDataLog; |
45 | 48 | import io.realm.Realm; |
@@ -101,6 +104,11 @@ protected void onCreate(Bundle savedInstanceState) { |
101 | 104 | case "Compass": |
102 | 105 | categoryData = LocalDataLog.with().getTypeOfSensorBlocks(getString(R.string.compass)); |
103 | 106 | break; |
| 107 | + case "Thermometer": |
| 108 | + categoryData = LocalDataLog.with().getTypeOfSensorBlocks(getString(R.string.thermometer)); |
| 109 | + break; |
| 110 | + case "Robotic Arm": |
| 111 | + categoryData = LocalDataLog.with().getTypeOfSensorBlocks(getString(R.string.robotic_arm)); |
104 | 112 | default: |
105 | 113 | categoryData = LocalDataLog.with().getAllSensorBlocks(); |
106 | 114 | getSupportActionBar().setTitle(getString(R.string.logged_data)); |
@@ -412,6 +420,75 @@ private void getFileData(File file) { |
412 | 420 | } catch (IOException e) { |
413 | 421 | e.printStackTrace(); |
414 | 422 | } |
| 423 | + } else if (selectedDevice != null && selectedDevice.equals(getResources().getString(R.string.thermometer))) { |
| 424 | + try { |
| 425 | + FileInputStream is = new FileInputStream(file); |
| 426 | + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
| 427 | + String line = reader.readLine(); |
| 428 | + int i = 0; |
| 429 | + long block = 0, time = 0; |
| 430 | + while (line != null) { |
| 431 | + if (i != 0) { |
| 432 | + String[] data = line.split(","); |
| 433 | + try { |
| 434 | + time += 1000; |
| 435 | + ThermometerData thermometerData = new ThermometerData(time, block, Float.valueOf(data[2]), Double.valueOf(data[5]), Double.valueOf(data[6])); |
| 436 | + realm.beginTransaction(); |
| 437 | + realm.copyToRealm(thermometerData); |
| 438 | + realm.commitTransaction(); |
| 439 | + } catch (Exception e) { |
| 440 | + Toast.makeText(this, getResources().getString(R.string.incorrect_import_format), Toast.LENGTH_SHORT).show(); |
| 441 | + } |
| 442 | + } else { |
| 443 | + block = System.currentTimeMillis(); |
| 444 | + time = block; |
| 445 | + realm.beginTransaction(); |
| 446 | + realm.copyToRealm(new SensorDataBlock(block, getResources().getString(R.string.thermometer))); |
| 447 | + realm.commitTransaction(); |
| 448 | + } |
| 449 | + i++; |
| 450 | + line = reader.readLine(); |
| 451 | + } |
| 452 | + fillData(); |
| 453 | + DataLoggerActivity.this.toolbar.getMenu().findItem(R.id.delete_all).setVisible(true); |
| 454 | + } catch (IOException e) { |
| 455 | + e.printStackTrace(); |
| 456 | + } |
| 457 | + } else if (selectedDevice != null && selectedDevice.equals(getResources().getString(R.string.robotic_arm))) { |
| 458 | + try { |
| 459 | + FileInputStream is = new FileInputStream(file); |
| 460 | + BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
| 461 | + String line = reader.readLine(); |
| 462 | + int i = 0; |
| 463 | + long block = 0, time = 0; |
| 464 | + while (line != null) { |
| 465 | + if (i != 0) { |
| 466 | + String[] data = line.split(","); |
| 467 | + try { |
| 468 | + time += 1000; |
| 469 | + ServoData servoData = new ServoData(time, block, data[2], data[3], data[4], data[5], Float.valueOf(data[6]), Float.valueOf(data[7])); |
| 470 | + realm.beginTransaction(); |
| 471 | + realm.copyToRealm(servoData); |
| 472 | + realm.commitTransaction(); |
| 473 | + } catch (Exception e) { |
| 474 | + Log.d("exception", i + " " + e.getMessage()); |
| 475 | + Toast.makeText(this, getResources().getString(R.string.incorrect_import_format), Toast.LENGTH_SHORT).show(); |
| 476 | + } |
| 477 | + } else { |
| 478 | + block = System.currentTimeMillis(); |
| 479 | + time = block; |
| 480 | + realm.beginTransaction(); |
| 481 | + realm.copyToRealm(new SensorDataBlock(block, getResources().getString(R.string.robotic_arm))); |
| 482 | + realm.commitTransaction(); |
| 483 | + } |
| 484 | + i++; |
| 485 | + line = reader.readLine(); |
| 486 | + } |
| 487 | + fillData(); |
| 488 | + DataLoggerActivity.this.toolbar.getMenu().findItem(R.id.delete_all).setVisible(true); |
| 489 | + } catch (IOException e) { |
| 490 | + e.printStackTrace(); |
| 491 | + } |
415 | 492 | } |
416 | 493 | } |
417 | 494 | } |
0 commit comments