#--------------------------------------------------------
#Copyright 2017 Kymatics, LLC
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#--------------------------------------------------------

import math, ConfigParser, os

Config = ConfigParser.ConfigParser()

#Config.read(os.path.join('..','settings.ini'))
Config.read('settings.ini')


# GUI Settings
save_data = Config.getint('GUI', 'save_data')               # Not yet implemented
total_time = Config.getint('GUI', 'total_time')             # Seconds to display
pps = Config.getint('GUI', 'pps')                           # Display points /sec    

# DAQ settings
samplerate = Config.getint('DAQ', 'samplerate')             # Freqeuncy (2 kHz - 5 kHz Max)
DAQrange = Config.getboolean('DAQ', 'range')                # Full Scale Range - (0 => +-5V) (1 => +-10V)

oversamp = Config.getint('DAQ', 'oversamp')                 # Oversampling - (0 - NO OS) (1 - 2X OS) 
                                                            # (2 - 4X OS - 15kHz max BW) (3 - 8X OS - 10kHz max BW)
                                                            # (4 - 16X OS - 5kHz max BW) (5 - 32X OS - 2kHz max BW) 
                                                            # (6 - 64X OS - 1kHz max BW)
                        
channels = Config.getint('DAQ', 'channels')                 # Number of channels per DAQ       

data_update = Config.getfloat('DAQ', 'data_update')         # Seconds - Period at which to update plot arrays  

downsample = Config.getint('DAQ', 'downsample')             # Downsample (Moving Average downsample (2^n) - 0-5)
                                                            # (0 -  NO DS) (1 -  2X DS) 
                                                            # (2 -  4X DS) (3 -  8X DS)
                                                            # (4 - 16X DS) (5 - 32X DS) 

sensorcloud_enable = False
#SensorCloud Login Info
if Config.has_section('SensorCloud'):
    sensorcloud_enable = True
    sensorcloud_device_id = Config.get('SensorCloud','device_id')
    sensorcloud_key = Config.get('SensorCloud','key')
    



# Do not modify!
samplerate_data = samplerate/(2**downsample)

data_smallstep = data_update/2

downsample_disp = int(math.ceil(samplerate_data/pps))

DAQauthkey = '42 is always the answer!'



sensorcloud_period = min(15.,15000./samplerate_data)



