/**
  * returns the mean of samples values of aixs indicated by the index number .
  *
  * @param index Indicates the axis (x=0,y=1,z=2).
  * @return The mean value.
  */
 private float getMeanG(int index) {
   float t = 0;
   for (int i = 1; i <= samples; i++) {
     accel.fetchAllAccel(value, AccelUnits.G);
     t += value[index];
     try {
       Thread.sleep(10);
     } catch (InterruptedException ex) {
     }
   }
   return t / samples;
 }
 /**
  * returns the mean of N raw values of aixs indicated by the index number .
  *
  * @param index Indicates the axis (x=0,y=1,z=2).
  * @return The mean value.
  */
 private float getRawMean(int index) {
   int t = 0;
   for (int i = 1; i <= samples; i++) {
     accel.fetchRawAccel(raw);
     t += raw[index];
     try {
       Thread.sleep(10);
     } catch (InterruptedException ex) {
     }
   }
   return t / samples;
 }
 /**
  * Displays the raw value of axis indicated by index. A low pass filter is applied on the raw
  * values to make reading easier.
  *
  * @param index Indicates the axis (x=0,y=1,z=2).
  */
 private void showLowPass(int index) {
   float alpha = 0.95f;
   float lowpassed = 0;
   while (!Button.ENTER.isDown()) {
     accel.fetchRawAccel(raw);
     lowpassed = alpha * raw[index] + (1.0f - alpha) * lowpassed;
     LCD.drawString(Double.toString(lowpassed), 0, 3);
     try {
       Thread.sleep(150);
     } catch (InterruptedException ex) {
     }
   }
   while (Button.ENTER.isDown()) ;
 }
 /**
  * Constructor of the <code>AccelCalibration</code> class.
  *
  * @param accel Accel should have the pointer to the accelerometer class that uses the calibration
  *     settings. When invoked from within the accelerometer class (as is normal behaviour) the
  *     invokation looks like this <code>AccelCalibration settings=new AccelCalibration(this);
  *     </code>
  */
 AccelCalibration(Accelerometer accel) {
   this.accel = accel;
   name = accel.getSensorType();
 }