# Path: sensbiotk/io/iofox_deprec.py
# LSM303DLHC_ACC_SCALE = {'2g': 0x00, '4g': 0x10, '8g': 0x20, '16g': 0x30}
# LSM303DLHC_MAG_SCALE = {'1_3gauss': 0x20, '1_9gauss': 0x40, '2_5gauss': 0x60,
#                         '4_0gauss': 0x80, '4_7gauss': 0xA0, '5_6gauss': 0xC0,
#                         '8_1gauss': 0xE0}
# L3G4200D_SCALE = {'250dps': 0x00, '500dps': 0x10, '2000dps': 0x30}
# SCALE = {'ref_g': 9.81, 'time': 1e-3,
#          'acc': 2.0e-2, 'mag_xy': (1.0 / 670.0), 'mag_z': (1.0 / 600.0),
#          'press': 1.0 / 4096.0 / 1000.0, 'temp': 1.0 / 480.0,
#          'offset_temp': 22.5}
# SEP = "\t"
# def _get_acc_scale():
# def _get_magxy_scale():
# def _get_gyr_scale():
# def _get_time(rawval):
# def _get_acc(rawval):
# def _get_mag(rawval):
# def _get_gyr(rawval):
# def _get_press(rawval):
# def _get_temp(rawval):
# def _set_time_scale(val):
# def _set_acc_scale(val):
# def _set_mag_scale(val):
# def _set_gyr_scale(val):
# def _write_imu_header(fid, binfilename):
# def _write_imu_data(fid, data):
# def _write_presst_header(fid, binfilename):
# def _write_presst_data(fid, data):
# def convert_fox_rawfile(binfilename, imufilename, presstfilename):
# def info_fox_rawfile(binfilename):
# def load_foximu_csvfile(filename):
# def load_foxpresst_csvfile(filename):
# def save_foximu_csvfile(accfilename, time, acc, mag, gyr, separator=SEP):
# 
# Path: sensbiotk/io/viz.py
# def plot_imu(num, title, time, acc, mag, gyr):
# def plot_show():
# def test1():
# def test2():
# def test3():


import numpy as np
import matplotlib.pyplot as plt
from sensbiotk.io import iofox_deprec as fox
from sensbiotk.io import viz
    """ Test load_foximu_csvfile function

    Parameters
    ----------
    filename : filename IMU door to be analyzed
    """
    plt.figure(4)

    # Filter the mag norm
    mag_normfiltre = moving_average(mag_norm, dimfen)
    # State door computation
    [etat_porte, _ ]= \
        state_detection(time_imu, mag_normfiltre, valopen, valclose, valeps)
    # Plot the mag norm filtered and the door state
    plt.plot(time_imu[dimfen-1:-dimfen+1], mag_normfiltre)
    plt.plot(time_imu[dimfen-1:-dimfen+1], etat_porte)

    return


def test0():
    """ Test 0
    """
    filein = DIR + "HIGPS00.RAW"
    fileout = DIR + "imu00.csv"
    fileoutp = DIR + "presst00.csv"

    fox.convert_fox_rawfile(filein, fileout, fileoutp)
    [time, acc_imu, mag_imu, gyr_imu] = fox.load_foximu_csvfile(fileout)
    time_imu = time[:, 1]

# Path: sensbiotk/io/iofox_deprec.py
# LSM303DLHC_ACC_SCALE = {'2g': 0x00, '4g': 0x10, '8g': 0x20, '16g': 0x30}
# LSM303DLHC_MAG_SCALE = {'1_3gauss': 0x20, '1_9gauss': 0x40, '2_5gauss': 0x60,
#                         '4_0gauss': 0x80, '4_7gauss': 0xA0, '5_6gauss': 0xC0,
#                         '8_1gauss': 0xE0}
# L3G4200D_SCALE = {'250dps': 0x00, '500dps': 0x10, '2000dps': 0x30}
# SCALE = {'ref_g': 9.81, 'time': 1e-3,
#          'acc': 2.0e-2, 'mag_xy': (1.0 / 670.0), 'mag_z': (1.0 / 600.0),
#          'press': 1.0 / 4096.0 / 1000.0, 'temp': 1.0 / 480.0,
#          'offset_temp': 22.5}
# SEP = "\t"
# def _get_acc_scale():
# def _get_magxy_scale():
# def _get_gyr_scale():
# def _get_time(rawval):
# def _get_acc(rawval):
# def _get_mag(rawval):
# def _get_gyr(rawval):
# def _get_press(rawval):
# def _get_temp(rawval):
# def _set_time_scale(val):
# def _set_acc_scale(val):
# def _set_mag_scale(val):
# def _set_gyr_scale(val):
# def _write_imu_header(fid, binfilename):
# def _write_imu_data(fid, data):
# def _write_presst_header(fid, binfilename):
# def _write_presst_data(fid, data):
# def convert_fox_rawfile(binfilename, imufilename, presstfilename):
# def info_fox_rawfile(binfilename):
# def load_foximu_csvfile(filename):
# def load_foxpresst_csvfile(filename):
# def save_foximu_csvfile(accfilename, time, acc, mag, gyr, separator=SEP):
# 
# Path: sensbiotk/io/viz.py
# def plot_imu(num, title, time, acc, mag, gyr):
# def plot_show():
# def test1():
# def test2():
# def test3():


# Path: examples/doors/doors.py
import numpy as np
import matplotlib.pyplot as plt
from sensbiotk.io import iofox_deprec as fox
from sensbiotk.io import viz

    """ Test load_foximu_csvfile function

    Parameters
    ----------
    filename : filename IMU door to be analyzed
    """
    plt.figure(4)

    # Filter the mag norm
    mag_normfiltre = moving_average(mag_norm, dimfen)
    # State door computation
    [etat_porte, _ ]= \
        state_detection(time_imu, mag_normfiltre, valopen, valclose, valeps)
    # Plot the mag norm filtered and the door state
    plt.plot(time_imu[dimfen-1:-dimfen+1], mag_normfiltre)
    plt.plot(time_imu[dimfen-1:-dimfen+1], etat_porte)

    return


def test0():
    """ Test 0
    """
    filein = DIR + "HIGPS00.RAW"
    fileout = DIR + "imu00.csv"
    fileoutp = DIR + "presst00.csv"

    fox.convert_fox_rawfile(filein, fileout, fileoutp)
    [time, acc_imu, mag_imu, gyr_imu] = fox.load_foximu_csvfile(fileout)
    time_imu = time[:, 1]

    viz.plot_imu(1, "FOX IMU sensors", time_imu, acc_imu, mag_imu, gyr_imu)