// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/LowPassFilter.java
// public class LowPassFilter extends AveragingFilter
// {
//     private static final String tag = LowPassFilter.class.getSimpleName();
// 
//     // Gravity and linear accelerations components for the
//     // Wikipedia low-pass fusedOrientation
//     private float[] output;
// 
//     public LowPassFilter() {
//         this(DEFAULT_TIME_CONSTANT);
//     }
// 
//     public LowPassFilter(float timeConstant) {
//         this.timeConstant = timeConstant;
//         reset();
//     }
// 
//     /**
//      * Add a sample.
//      *
//      * @param values
//      *            The acceleration data. A 1x3 matrix containing the data from the X, Y and Z axis of the sensor
//      *            noting that order is arbitrary.
//      * @return Returns the output of the fusedOrientation.
//      */
//     public float[] filter(float[] values)
//     {
//         // Initialize the start time.
//         if (startTime == 0)
//         {
//             startTime = System.nanoTime();
//         }
// 
//         timestamp = System.nanoTime();
// 
//         // Find the sample period (between updates) and convert from
//         // nanoseconds to seconds. Note that the sensor delivery rates can
//         // individually vary by a relatively large time frame, so we use an
//         // averaging technique with the number of sensor updates to
//         // determine the delivery rate.
//         float dt = 1 / (count++ / ((timestamp - startTime) / 1000000000.0f));
// 
//         float alpha = timeConstant / (timeConstant + dt);
// 
//         output[0] = alpha * output[0] + (1 - alpha) * values[0];
//         output[1] = alpha * output[1] + (1 - alpha) * values[1];
//         output[2] = alpha * output[2] + (1 - alpha) * values[2];
// 
//         return output;
//     }
// 
//     @Override
//     public float[] getOutput() {
//         return output;
//     }
// 
//     public void setTimeConstant(float timeConstant)
//     {
//         this.timeConstant = timeConstant;
//     }
// 
//     public void reset()
//     {
//         super.reset();
//         this.output = new float[]
//                 { 0, 0, 0 };
// 
//     }
// }
// 
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/linearacceleration/LinearAcceleration.java
// public abstract class LinearAcceleration {
// 
//     private static final String tag = LinearAcceleration.class.getSimpleName();
// 
//     private final float[] output = new float[]{0, 0, 0};
// 
//     protected final BaseFilter filter;
// 
//     public LinearAcceleration(BaseFilter filter) {
//         this.filter = filter;
//     }
// 
//     public float[] filter(float[] values) {
// 
//         float[] gravity = getGravity();
// 
//         // Determine the linear acceleration
//         output[0] = values[0] - gravity[0];
//         output[1] = values[1] - gravity[1];
//         output[2] = values[2] - gravity[2];
// 
//         return output;
//     }
// 
//     public abstract float[] getGravity();
// }
// 
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/linearacceleration/LinearAccelerationAveraging.java
// public class LinearAccelerationAveraging extends LinearAcceleration {
// 
//     public LinearAccelerationAveraging(AveragingFilter averagingFilter) {
//         super(averagingFilter);
//     }
// 
//     @Override
//     public float[] getGravity() {
//         return filter.getOutput();
//     }
// }
// 
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/observer/SensorSubject.java
// public class SensorSubject {
//     private final List<SensorObserver> observers = new ArrayList<>();
// 
//     public interface SensorObserver {
//         void onSensorChanged(float[] values);
//     }
// 
//     public void register(SensorObserver observer) {
//         if(!observers.contains(observer)) {
//             observers.add(observer);
//         }
//     }
// 
//     public void unregister(SensorObserver observer) {
//         observers.remove(observer);
//     }
// 
//     public void onNext(float[] values) {
//         for(int i = 0; i < observers.size(); i++) {
//             observers.get(i).onSensorChanged(values);
//         }
//     }
// }
// 
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/FSensor.java
// public interface FSensor {
//     void register(SensorSubject.SensorObserver sensorObserver);
//     void unregister(SensorSubject.SensorObserver sensorObserver);
// 
//     void start();
//     void stop();
//     void reset();
// }


import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import com.kircherelectronics.fsensor.filter.averaging.LowPassFilter;
import com.kircherelectronics.fsensor.linearacceleration.LinearAcceleration;
import com.kircherelectronics.fsensor.linearacceleration.LinearAccelerationAveraging;
import com.kircherelectronics.fsensor.observer.SensorSubject;
import com.kircherelectronics.fsensor.sensor.FSensor;
    @Override
    public void start() {
        startTime = 0;
        count = 0;

        registerSensors(sensorDelay);
    }

    /**
     * Stop the sensor.
     */
    @Override
    public void stop() {
        unregisterSensors();
    }

    @Override
    public void register(SensorSubject.SensorObserver sensorObserver) {
        sensorSubject.register(sensorObserver);
    }

    @Override
    public void unregister(SensorSubject.SensorObserver sensorObserver) {
        sensorSubject.unregister(sensorObserver);
    }

    /**
     * Set the sensor frequency.
     * @param sensorDelay Must be SensorManager.SENSOR_DELAY_FASTEST, SensorManager.SENSOR_DELAY_GAME, SensorManager.SENSOR_DELAY_NORMAL or SensorManager.SENSOR_DELAY_UI
     */
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/filter/averaging/LowPassFilter.java
// public class LowPassFilter extends AveragingFilter
// {
//     private static final String tag = LowPassFilter.class.getSimpleName();
// 
//     // Gravity and linear accelerations components for the
//     // Wikipedia low-pass fusedOrientation
//     private float[] output;
// 
//     public LowPassFilter() {
//         this(DEFAULT_TIME_CONSTANT);
//     }
// 
//     public LowPassFilter(float timeConstant) {
//         this.timeConstant = timeConstant;
//         reset();
//     }
// 
//     /**
//      * Add a sample.
//      *
//      * @param values
//      *            The acceleration data. A 1x3 matrix containing the data from the X, Y and Z axis of the sensor
//      *            noting that order is arbitrary.
//      * @return Returns the output of the fusedOrientation.
//      */
//     public float[] filter(float[] values)
//     {
//         // Initialize the start time.
//         if (startTime == 0)
//         {
//             startTime = System.nanoTime();
//         }
// 
//         timestamp = System.nanoTime();
// 
//         // Find the sample period (between updates) and convert from
//         // nanoseconds to seconds. Note that the sensor delivery rates can
//         // individually vary by a relatively large time frame, so we use an
//         // averaging technique with the number of sensor updates to
//         // determine the delivery rate.
//         float dt = 1 / (count++ / ((timestamp - startTime) / 1000000000.0f));
// 
//         float alpha = timeConstant / (timeConstant + dt);
// 
//         output[0] = alpha * output[0] + (1 - alpha) * values[0];
//         output[1] = alpha * output[1] + (1 - alpha) * values[1];
//         output[2] = alpha * output[2] + (1 - alpha) * values[2];
// 
//         return output;
//     }
// 
//     @Override
//     public float[] getOutput() {
//         return output;
//     }
// 
//     public void setTimeConstant(float timeConstant)
//     {
//         this.timeConstant = timeConstant;
//     }
// 
//     public void reset()
//     {
//         super.reset();
//         this.output = new float[]
//                 { 0, 0, 0 };
// 
//     }
// }
// 
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/linearacceleration/LinearAcceleration.java
// public abstract class LinearAcceleration {
// 
//     private static final String tag = LinearAcceleration.class.getSimpleName();
// 
//     private final float[] output = new float[]{0, 0, 0};
// 
//     protected final BaseFilter filter;
// 
//     public LinearAcceleration(BaseFilter filter) {
//         this.filter = filter;
//     }
// 
//     public float[] filter(float[] values) {
// 
//         float[] gravity = getGravity();
// 
//         // Determine the linear acceleration
//         output[0] = values[0] - gravity[0];
//         output[1] = values[1] - gravity[1];
//         output[2] = values[2] - gravity[2];
// 
//         return output;
//     }
// 
//     public abstract float[] getGravity();
// }
// 
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/linearacceleration/LinearAccelerationAveraging.java
// public class LinearAccelerationAveraging extends LinearAcceleration {
// 
//     public LinearAccelerationAveraging(AveragingFilter averagingFilter) {
//         super(averagingFilter);
//     }
// 
//     @Override
//     public float[] getGravity() {
//         return filter.getOutput();
//     }
// }
// 
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/observer/SensorSubject.java
// public class SensorSubject {
//     private final List<SensorObserver> observers = new ArrayList<>();
// 
//     public interface SensorObserver {
//         void onSensorChanged(float[] values);
//     }
// 
//     public void register(SensorObserver observer) {
//         if(!observers.contains(observer)) {
//             observers.add(observer);
//         }
//     }
// 
//     public void unregister(SensorObserver observer) {
//         observers.remove(observer);
//     }
// 
//     public void onNext(float[] values) {
//         for(int i = 0; i < observers.size(); i++) {
//             observers.get(i).onSensorChanged(values);
//         }
//     }
// }
// 
// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/FSensor.java
// public interface FSensor {
//     void register(SensorSubject.SensorObserver sensorObserver);
//     void unregister(SensorSubject.SensorObserver sensorObserver);
// 
//     void start();
//     void stop();
//     void reset();
// }


// Path: fsensor/src/main/java/com/kircherelectronics/fsensor/sensor/acceleration/LowPassLinearAccelerationSensor.java
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import com.kircherelectronics.fsensor.filter.averaging.LowPassFilter;
import com.kircherelectronics.fsensor.linearacceleration.LinearAcceleration;
import com.kircherelectronics.fsensor.linearacceleration.LinearAccelerationAveraging;
import com.kircherelectronics.fsensor.observer.SensorSubject;
import com.kircherelectronics.fsensor.sensor.FSensor;

    @Override
    public void start() {
        startTime = 0;
        count = 0;

        registerSensors(sensorDelay);
    }

    /**
     * Stop the sensor.
     */
    @Override
    public void stop() {
        unregisterSensors();
    }

    @Override
    public void register(SensorSubject.SensorObserver sensorObserver) {
        sensorSubject.register(sensorObserver);
    }

    @Override
    public void unregister(SensorSubject.SensorObserver sensorObserver) {
        sensorSubject.unregister(sensorObserver);
    }

    /**
     * Set the sensor frequency.
     * @param sensorDelay Must be SensorManager.SENSOR_DELAY_FASTEST, SensorManager.SENSOR_DELAY_GAME, SensorManager.SENSOR_DELAY_NORMAL or SensorManager.SENSOR_DELAY_UI
     */
    public void setSensorDelay(int sensorDelay) {