Changeset 9769326 in orbit
- Timestamp:
- 12/11/13 15:18:00 (8 years ago)
- Branches:
- master, Servo
- Children:
- 05e2bb8
- Parents:
- d5fbc16
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
android/src/info/puzzlebox/orbit/FragmentTabFlightEmotiv.java
r490c673 r9769326 2 2 package info.puzzlebox.orbit; 3 3 4 import java.text.DecimalFormat;5 6 4 import info.puzzlebox.orbit.OrbitTabActivity; 7 8 import java.util.Arrays;9 5 10 6 import android.content.res.Configuration; … … 30 26 import android.support.v4.app.Fragment; 31 27 32 //import com.androidplot.xy.BoundaryMode;33 //import com.androidplot.xy.LineAndPointFormatter;34 //import com.androidplot.xy.SimpleXYSeries;35 //import com.androidplot.xy.XYPlot;36 import com.neurosky.thinkgear.TGDevice;37 38 28 39 29 public class FragmentTabFlightEmotiv extends Fragment implements SeekBar.OnSeekBarChangeListener { … … 58 48 * Configuration 59 49 */ 60 // int eegAttention = 0;61 // int eegMeditation = 0;62 50 int eegCognitiv = 0; 63 51 int eegPower = 0; … … 66 54 boolean eegConnecting = false; 67 55 boolean demoFlightMode = false; 68 Number[] rawEEG = new Number[512];56 // Number[] rawEEG = new Number[512]; 69 57 int arrayIndex = 0; 70 58 … … 74 62 */ 75 63 Configuration config; 76 // ProgressBar progressBarAttention;77 // SeekBar seekBarAttention;78 // ProgressBar progressBarMeditation;79 // SeekBar seekBarMeditation;80 64 ProgressBar progressBarCognitiv; 81 65 SeekBar seekBarCognitiv; 82 66 ProgressBar progressBarSignal; 83 67 ProgressBar progressBarPower; 84 // SeekBar seekBarThrottle;85 // SeekBar seekBarYaw;86 // SeekBar seekBarPitch;87 68 Button connectButton; 88 69 Button testFlightButton; … … 91 72 ImageView imageViewStatus; 92 73 93 // int[] thresholdValuesAttention = new int[101];94 // int[] thresholdValuesMeditation = new int[101];95 74 int[] thresholdValuesCognitiv = new int[101]; 96 75 int minimumPower = 0; // minimum power for the helicopter throttle … … 98 77 99 78 int viewSpaceGenerateAudioWidth = 120; 100 101 // private final int EEG_RAW_HISTORY_SIZE = 512; // number of points to plot in EEG history102 // private XYPlot eegRawHistoryPlot = null;103 // private SimpleXYSeries eegRawHistorySeries = null;104 79 105 80 … … 163 138 164 139 config = getResources().getConfiguration(); 165 166 // progressBarAttention = (ProgressBar) v.findViewById(R.id.progressBarAttention);167 // final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 };168 // ShapeDrawable progressBarAttentionDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null));169 // String progressBarAttentionColor = "#FF0000";170 // progressBarAttentionDrawable.getPaint().setColor(Color.parseColor(progressBarAttentionColor));171 // ClipDrawable progressAttention = new ClipDrawable(progressBarAttentionDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);172 // progressBarAttention.setProgressDrawable(progressAttention);173 // progressBarAttention.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));174 175 // progressBarMeditation = (ProgressBar) v.findViewById(R.id.progressBarMeditation);176 // ShapeDrawable progressBarMeditationDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null,null));177 // String progressBarMeditationColor = "#0000FF";178 // progressBarMeditationDrawable.getPaint().setColor(Color.parseColor(progressBarMeditationColor));179 // ClipDrawable progressMeditation = new ClipDrawable(progressBarMeditationDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL);180 // progressBarMeditation.setProgressDrawable(progressMeditation);181 // progressBarMeditation.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal));182 140 183 141 progressBarCognitiv = (ProgressBar) v.findViewById(R.id.progressBarCognitiv); … … 209 167 210 168 // setup the Raw EEG History plot 211 // eegRawHistoryPlot = (XYPlot) v.findViewById(R.id.eegRawHistoryPlot); 212 // eegRawHistorySeries = new SimpleXYSeries("Raw EEG"); 213 214 // Use index value as xVal, instead of explicit, user provided xVals. 215 // eegRawHistorySeries.useImplicitXVals(); 216 217 // Setup the boundary mode, boundary values only applicable in FIXED mode. 218 219 // if (eegRawHistoryPlot != null) { 220 // 221 // eegRawHistoryPlot.setDomainBoundaries(0, EEG_RAW_HISTORY_SIZE, BoundaryMode.FIXED); 222 // // eegRawHistoryPlot.setDomainBoundaries(0, EEG_RAW_HISTORY_SIZE, BoundaryMode.AUTO); 223 // // eegRawHistoryPlot.setRangeBoundaries(-32767, 32767, BoundaryMode.FIXED); 224 // // eegRawHistoryPlot.setRangeBoundaries(-32767, 32767, BoundaryMode.AUTO); 225 // eegRawHistoryPlot.setRangeBoundaries(-256, 256, BoundaryMode.GROW); 226 // 227 // eegRawHistoryPlot.addSeries(eegRawHistorySeries, new LineAndPointFormatter(Color.rgb(200, 100, 100), Color.BLACK, null, null)); 228 // 229 // // Thin out domain and range tick values so they don't overlap 230 // eegRawHistoryPlot.setDomainStepValue(5); 231 // eegRawHistoryPlot.setTicksPerRangeLabel(3); 232 // 233 // // eegRawHistoryPlot.setRangeLabel("Amplitude"); 234 // 235 // // Sets the dimensions of the widget to exactly contain the text contents 236 // eegRawHistoryPlot.getDomainLabelWidget().pack(); 237 // eegRawHistoryPlot.getRangeLabelWidget().pack(); 238 // 239 // // Only display whole numbers in labels 240 // eegRawHistoryPlot.getGraphWidget().setDomainValueFormat(new DecimalFormat("0")); 241 // eegRawHistoryPlot.getGraphWidget().setRangeValueFormat(new DecimalFormat("0")); 242 // 243 // // Hide domain and range labels 244 // eegRawHistoryPlot.getGraphWidget().setDomainLabelWidth(0); 245 // eegRawHistoryPlot.getGraphWidget().setRangeLabelWidth(0); 246 // 247 // // Hide legend 248 // eegRawHistoryPlot.getLegendWidget().setVisible(false); 249 // 250 // // setGridPadding(float left, float top, float right, float bottom) 251 // eegRawHistoryPlot.getGraphWidget().setGridPadding(0, 0, 0, 0); 252 // 253 // 254 // // eegRawHistoryPlot.getGraphWidget().setDrawMarkersEnabled(false); 255 // 256 // // final PlotStatistics histStats = new PlotStatistics(1000, false); 257 // // eegRawHistoryPlot.addListener(histStats); 258 // 259 // } 260 261 262 263 // seekBarAttention = (SeekBar) v.findViewById(R.id.seekBarAttention); 264 // seekBarAttention.setOnSeekBarChangeListener(this); 265 // seekBarMeditation = (SeekBar) v.findViewById(R.id.seekBarMeditation); 266 // seekBarMeditation.setOnSeekBarChangeListener(this); 169 170 267 171 seekBarCognitiv = (SeekBar) v.findViewById(R.id.seekBarCognitiv); 268 172 seekBarCognitiv.setOnSeekBarChangeListener(this); … … 270 174 271 175 imageViewStatus = (ImageView) v.findViewById(R.id.imageViewStatus); 272 273 274 // layoutControl = (LinearLayout) v.findViewById(R.id.layoutControl);275 // layoutAudioService = (LinearLayout) v.findViewById(R.id.layoutAudioService);276 // layoutAdvancedOptions = (LinearLayout) v.findViewById(R.id.layoutAdvancedOptions);277 // layoutInvertControlSignal = (LinearLayout) v.findViewById(R.id.layoutInvertControlSignal);278 176 279 177 … … 483 381 public void parseEEG(Message msg) { 484 382 485 switch (msg.what) {486 487 case TGDevice.MSG_STATE_CHANGE:488 489 switch (msg.arg1) {490 case TGDevice.STATE_IDLE:491 break;492 case TGDevice.STATE_CONNECTING:493 eegConnecting = true;494 eegConnected = false;495 updateStatusImage();496 break;497 case TGDevice.STATE_CONNECTED:498 setButtonText(R.id.buttonConnect, "Disconnect");499 eegConnecting = false;500 eegConnected = true;501 updateStatusImage();502 break;503 case TGDevice.STATE_NOT_FOUND:504 eegConnecting = false;505 eegConnected = false;506 updateStatusImage();507 break;508 case TGDevice.STATE_NOT_PAIRED:509 eegConnecting = false;510 eegConnected = false;511 updateStatusImage();512 break;513 case TGDevice.STATE_DISCONNECTED:514 eegConnecting = false;515 eegConnected = false;516 updateStatusImage();517 break;518 }519 520 break;521 522 case TGDevice.MSG_POOR_SIGNAL:523 eegSignal = calculateSignal(msg.arg1);524 // appendDebugConsole("\nPoorSignal: " + msg.arg1 + "\n");525 progressBarSignal.setProgress(eegSignal);526 updateStatusImage();527 break;528 case TGDevice.MSG_RAW_DATA:529 530 // rawEEG[arrayIndex] = msg.arg1;531 // arrayIndex = arrayIndex + 1;532 533 // if (arrayIndex == EEG_RAW_HISTORY_SIZE - 1)534 // updateEEGRawHistory();535 536 break;537 case TGDevice.MSG_HEART_RATE:538 // appendDebugConsole("Heart rate: " + msg.arg1 + "\n");539 break;540 case TGDevice.MSG_ATTENTION:541 // eegAttention = msg.arg1;542 // // appendDebugConsole("Attention: " + eegAttention + "\n");543 // progressBarAttention.setProgress(eegAttention);544 // updatePower();545 546 break;547 case TGDevice.MSG_MEDITATION:548 // eegMeditation = msg.arg1;549 // if (DEBUG)550 // Log.v(TAG, "Meditation: " + eegMeditation);551 // // appendDebugConsole("Meditation: " + eegMeditation + "\n");552 // progressBarMeditation.setProgress(eegMeditation);553 // updatePower();554 555 break;556 case TGDevice.MSG_BLINK:557 //tv.append("Blink: " + msg.arg1 + "\n");558 break;559 case TGDevice.MSG_RAW_COUNT:560 //tv.append("Raw Count: " + msg.arg1 + "\n");561 break;562 case TGDevice.MSG_LOW_BATTERY:563 // Toast.makeText(getApplicationContext(), "Low battery!", Toast.LENGTH_SHORT).show();564 break;565 case TGDevice.MSG_RAW_MULTI:566 //TGRawMulti rawM = (TGRawMulti)msg.obj;567 //tv.append("Raw1: " + rawM.ch1 + "\nRaw2: " + rawM.ch2);568 default:569 break;570 }383 // switch (msg.what) { 384 // 385 // case TGDevice.MSG_STATE_CHANGE: 386 // 387 // switch (msg.arg1) { 388 // case TGDevice.STATE_IDLE: 389 // break; 390 // case TGDevice.STATE_CONNECTING: 391 // eegConnecting = true; 392 // eegConnected = false; 393 // updateStatusImage(); 394 // break; 395 // case TGDevice.STATE_CONNECTED: 396 // setButtonText(R.id.buttonConnect, "Disconnect"); 397 // eegConnecting = false; 398 // eegConnected = true; 399 // updateStatusImage(); 400 // break; 401 // case TGDevice.STATE_NOT_FOUND: 402 // eegConnecting = false; 403 // eegConnected = false; 404 // updateStatusImage(); 405 // break; 406 // case TGDevice.STATE_NOT_PAIRED: 407 // eegConnecting = false; 408 // eegConnected = false; 409 // updateStatusImage(); 410 // break; 411 // case TGDevice.STATE_DISCONNECTED: 412 // eegConnecting = false; 413 // eegConnected = false; 414 // updateStatusImage(); 415 // break; 416 // } 417 // 418 // break; 419 // 420 // case TGDevice.MSG_POOR_SIGNAL: 421 // eegSignal = calculateSignal(msg.arg1); 422 // // appendDebugConsole("\nPoorSignal: " + msg.arg1 + "\n"); 423 // progressBarSignal.setProgress(eegSignal); 424 // updateStatusImage(); 425 // break; 426 // case TGDevice.MSG_RAW_DATA: 427 // 428 // // rawEEG[arrayIndex] = msg.arg1; 429 // // arrayIndex = arrayIndex + 1; 430 // 431 // // if (arrayIndex == EEG_RAW_HISTORY_SIZE - 1) 432 // // updateEEGRawHistory(); 433 // 434 // break; 435 // case TGDevice.MSG_HEART_RATE: 436 // // appendDebugConsole("Heart rate: " + msg.arg1 + "\n"); 437 // break; 438 // case TGDevice.MSG_ATTENTION: 439 // // eegAttention = msg.arg1; 440 // // // appendDebugConsole("Attention: " + eegAttention + "\n"); 441 // // progressBarAttention.setProgress(eegAttention); 442 // // updatePower(); 443 // 444 // break; 445 // case TGDevice.MSG_MEDITATION: 446 // // eegMeditation = msg.arg1; 447 // // if (DEBUG) 448 // // Log.v(TAG, "Meditation: " + eegMeditation); 449 // // // appendDebugConsole("Meditation: " + eegMeditation + "\n"); 450 // // progressBarMeditation.setProgress(eegMeditation); 451 // // updatePower(); 452 // 453 // break; 454 // case TGDevice.MSG_BLINK: 455 // //tv.append("Blink: " + msg.arg1 + "\n"); 456 // break; 457 // case TGDevice.MSG_RAW_COUNT: 458 // //tv.append("Raw Count: " + msg.arg1 + "\n"); 459 // break; 460 // case TGDevice.MSG_LOW_BATTERY: 461 // // Toast.makeText(getApplicationContext(), "Low battery!", Toast.LENGTH_SHORT).show(); 462 // break; 463 // case TGDevice.MSG_RAW_MULTI: 464 // //TGRawMulti rawM = (TGRawMulti)msg.obj; 465 // //tv.append("Raw1: " + rawM.ch1 + "\nRaw2: " + rawM.ch2); 466 // default: 467 // break; 468 // } 571 469 572 470 } // handleMessage … … 584 482 eegConnected = false; 585 483 586 // eegAttention = 0;587 // eegMeditation = 0;588 484 eegCognitiv = 0; 589 485 eegSignal = 0; … … 592 488 updateStatusImage(); 593 489 594 // progressBarAttention.setProgress(eegAttention);595 // progressBarMeditation.setProgress(eegMeditation);596 490 progressBarCognitiv.setProgress(eegCognitiv); 597 491 progressBarSignal.setProgress(eegSignal); … … 645 539 646 540 int power; 647 // int attentionSeekValue;648 // int meditationSeekValue;649 541 int cognitivSeekValue; 650 542 float percentOfMaxPower; 651 543 652 544 // Reset all values to zero 653 // for (int i = 0; i < thresholdValuesAttention.length; i++) {654 // thresholdValuesAttention[i] = 0;655 // thresholdValuesMeditation[i] = 0;656 // }657 545 658 546 for (int i = 0; i < thresholdValuesCognitiv.length; i++) { … … 660 548 thresholdValuesCognitiv[i] = 0; 661 549 } 662 663 664 // attentionSeekValue = seekBarAttention.getProgress();665 // if (attentionSeekValue > 0) {666 // for (int i = attentionSeekValue; i < thresholdValuesAttention.length; i++) {667 550 668 551 cognitivSeekValue = seekBarCognitiv.getProgress(); … … 692 575 */ 693 576 694 // percentOfMaxPower = (float)( ((100 - attentionSeekValue) - (100 - i)) / (float)(100 - attentionSeekValue) );695 // power = thresholdValuesAttention[i] + (int)( minimumPower + ((maximumPower - minimumPower) * percentOfMaxPower) );696 // thresholdValuesAttention[i] = power;697 //698 // }699 // }700 577 701 578 percentOfMaxPower = (float)( ((100 - cognitivSeekValue) - (100 - i)) / (float)(100 - cognitivSeekValue) ); … … 707 584 708 585 709 // meditationSeekValue = seekBarMeditation.getProgress();710 // if (meditationSeekValue > 0) {711 // for (int i = meditationSeekValue; i < thresholdValuesMeditation.length; i++) {712 // percentOfMaxPower = (float)( ((100 - meditationSeekValue) - (100 - i)) / (float)(100 - meditationSeekValue) );713 // power = thresholdValuesMeditation[i] + (int)( minimumPower + ((maximumPower - minimumPower) * percentOfMaxPower) );714 // thresholdValuesMeditation[i] = power;715 // }716 // }717 718 586 } // updatePowerThresholds 719 587 … … 729 597 */ 730 598 731 // int attention = progressBarAttention.getProgress();732 // int meditation = progressBarMeditation.getProgress();733 // int attentionSeekValue = seekBarAttention.getProgress();734 // int meditationSeekValue = seekBarMeditation.getProgress();735 599 int cognitiv = progressBarCognitiv.getProgress(); 736 600 int cognitivSeekValue = seekBarCognitiv.getProgress(); … … 738 602 int speed = 0; 739 603 740 // if (attention > attentionSeekValue)741 // speed = thresholdValuesAttention[attention];742 // if (meditation > meditationSeekValue)743 // speed = speed + thresholdValuesMeditation[meditation];744 604 if (cognitiv > cognitivSeekValue) 745 605 speed = thresholdValuesCognitiv[cognitiv]; … … 781 641 // Set Attention and Meditation to zero if we've lost signal 782 642 if (eegSignal < 100) { 783 // eegAttention = 0;784 // eegMeditation = 0;785 643 eegCognitiv = 0; 786 // progressBarAttention.setProgress(eegAttention);787 // progressBarMeditation.setProgress(eegMeditation);788 644 progressBarCognitiv.setProgress(eegCognitiv); 789 645 } … … 804 660 Log.v(TAG, "hideEEGRawHistory()"); 805 661 806 // if (eegRawHistoryPlot != null)807 // eegRawHistoryPlot.setVisibility(View.GONE);808 809 810 // removeView*(View)811 // eegRawHistoryPlot.remove812 // (XYPlot) v.findViewById(R.id.eegRawHistoryPlot)813 814 662 815 663 } // hideEEGRawHistory … … 820 668 public void updateEEGRawHistory(Number[] rawEEG) { 821 669 822 // if (eegRawHistoryPlot != null) {823 // eegRawHistoryPlot.removeSeries(eegRawHistorySeries);824 //825 // eegRawHistorySeries = new SimpleXYSeries(Arrays.asList(rawEEG), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, "Raw EEG");826 //827 // // LineAndPointFormatter format = new LineAndPointFormatter(Color.rgb(200, 100, 100), Color.BLACK, null, null);828 // // LineAndPointFormatter format = new LineAndPointFormatter(Color.rgb(200, 100, 100), Color.TRANSPARENT, null, null);829 // LineAndPointFormatter format = new LineAndPointFormatter(Color.rgb(0, 0, 0), Color.TRANSPARENT, null, null);830 //831 // // format.getFillPaint().setAlpha(220);832 //833 // eegRawHistoryPlot.addSeries(eegRawHistorySeries, format);834 //835 //836 // // redraw the Plots:837 // eegRawHistoryPlot.redraw();838 //839 // // rawEEG = new Number[512];840 // // arrayIndex = 0;841 // }842 843 670 } // updateEEGRawHistory 844 671
Note: See TracChangeset
for help on using the changeset viewer.