Android Open Source - audiopulse-androidclient Monitor Thread






From Project

Back to project page audiopulse-androidclient.

License

The source code is released under:

GNU General Public License

If you think the Android project audiopulse-androidclient listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.audiopulse.activities;
//w ww  .  j a  v a2s.co  m
import org.audiopulse.hardware.APulseIface;

import android.os.Bundle;
import android.os.Message;

public class MonitorThread extends Thread
{
  static final String TAG = "MonitorThread";
  private final APulseIface apulse;
  MonitorHandler mainThreadHandler = null;
  int count = 0;
  private final short[] f1;
  private final short[] f2;
  public MonitorThread(MonitorHandler h, APulseIface ap, short[] f1, short[] f2)
  {
    mainThreadHandler = h;
    apulse=ap;
    this.f1=f1;
    this.f2=f2;
  }

  @Override
  public void run()
  {
    sendMessage("Number of tests: " + f1.length );
    for(int i=0;i<f1.length;i++){
      //Reset driver in between tests
      resetDriver();

      //Set frequency to test
      mainThreadHandler.setCurrentFrequency(f1[i],f2[i]);
      
      //Start test and monitor until complete
      sendAction(MonitorHandler.Messages.TEST_FREQUENCY); //Test is run through the Handler
      monitorOneTest();
      sendAction(MonitorHandler.Messages.RECORDING_COMPLETE);
    }
    sendMessage("\n\n***Finished all - " + f1.length + " - tests!");
  }

  public void resetDriver(){
    //Reset driver to make sure it is in an original state
    apulse.reset();
    while(true){
      int stat=apulse.getStatus().test_state;
      if( stat== APulseIface.APulseStatus.TEST_RESET){
        break;
      }
      sendMessage("\nTest beinb reset...");
      monitorSleep();
    }
  }


  private void monitorOneTest(){
    //TODO: Make wait time dependent on recording parameter time!
    int stat;
    while(true){
      stat=apulse.getStatus().test_state;
      if( stat== APulseIface.APulseStatus.TEST_DONE){
        break;
      }
      monitorSleep();
    }
  }


  private synchronized void monitorSleep(){
    try {
      Thread.sleep(200);
    }catch (InterruptedException e) {
      e.printStackTrace();
    }  
  }

  private synchronized void sendMessage(String str){
    Message msg = this.mainThreadHandler.obtainMessage(MonitorHandler.Messages.LOG);
    Bundle b = new Bundle();
    b.putString(MonitorHandler.LOGUI,str);
    msg.setData(b);
    this.mainThreadHandler.sendMessage(msg);
  }

  private synchronized void sendAction(int action){
    Message msg = this.mainThreadHandler.obtainMessage(action);
    this.mainThreadHandler.sendMessage(msg);
  }

}




Java Source Code List

org.audiopulse.activities.AudioPulseActivity.java
org.audiopulse.activities.MonitorHandler.java
org.audiopulse.activities.MonitorThread.java
org.audiopulse.activities.PlotSpectralActivity.java
org.audiopulse.activities.TestEarActivity.java
org.audiopulse.activities.UsbTestActivity.java
org.audiopulse.analysis.DPOAEAnalyzer.java
org.audiopulse.analysis.DPOAEResults.java
org.audiopulse.analysis.SignalProcessing.java
org.audiopulse.analysis.SpectralWindows.java
org.audiopulse.graphics.DemoView.java
org.audiopulse.graphics.PlotSpectralView.java
org.audiopulse.hardware.APulseIface.java
org.audiopulse.hardware.USBIface.java
org.audiopulse.io.AudioPulseFilePackager.java
org.audiopulse.io.AudioPulseFileWriter.java
org.audiopulse.io.UsbAudioEmulator.java
org.audiopulse.io.UsbAudioInterface.java