'''
  ____   ___  _   _ _   _ ____  
 / ___| / _ \| | | | \ | |  _ \ 
 \___ \| | | | | | |  \| | | | |
  ___) | |_| | |_| | |\  | |_| |
 |____/ \___/ \___/|_| \_|____/ 
                                
python3 /var/www/nebuleair_pro_4g/sound_meter/NSRT_MK4_change_config.py

1.Intervalle d'enregistrement 
L'intervalle d'enregistrement définit le temps entre deux points successifs enregistrés. 
Cela définit également la période d'intégration pour le LEQ, et la période d'observation pour L-min et L-max et Lpeak.  
L'intervalle d'enregistrement peut être réglé de 125 ms (1/8ème) à 2 H par incréments de 125 ms. 

some parameters can be changed:
write_tau(tau: float)       -> time constant
write_fs(frequency: int)    -> sampling freq

'''

import nsrt_mk3_dev
#from nsrt_mk3_dev import Weighting
#from nsrt_mk3_dev.nsrt_mk3_dev import NsrtMk3Dev, Weighting
from enum import Enum

class Weighting(Enum):
    DB_A = 1
    DB_C = 2
    DB_Z = 3

nsrt = nsrt_mk3_dev.NsrtMk3Dev('/dev/ttyACM0')

#####################
#change time constant
nsrt.write_tau(1)
#####################

#####################
#change Weighting curve
# - Weighting.DB_A  (A-weighting - most common for environmental noise)
# - Weighting.DB_C  (C-weighting - for peak measurements)
# - Weighting.DB_Z  (Z-weighting - linear/flat response)
nsrt.write_weighting(Weighting.DB_A)
#####################

freq_level = nsrt.read_fs()             #current sampling frequency
time_constant = nsrt.read_tau()         #reads the current time constant
leq_level = nsrt.read_leq()             #current running LEQ and starts the integration of a new LEQ.
weighting = nsrt.read_weighting()       #weighting curve that is currently selected
weighted_level = nsrt.read_level()      #current running level in dB.

print(f'current sampling freq : {freq_level} Hz')
print(f'current time constant : {time_constant} s')
print(f'current LEQ level:         {leq_level:0.2f} dB')
print(f'{weighting} value:      {weighted_level:0.2f} dBA')