From a3bc3bc3e3ff0d62e702f939b6bc7e3af27a5f03 Mon Sep 17 00:00:00 2001 From: su530201 <olivier.kaufmann@umons.ac.be> Date: Sat, 15 Apr 2023 18:12:41 +0200 Subject: [PATCH] Improves the change config function in utils --- config.py | 1 + utils.py | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config.py b/config.py index 8ce65319..b11d7d75 100644 --- a/config.py +++ b/config.py @@ -27,6 +27,7 @@ HARDWARE_CONFIG = { }, 'rx' : {'model': 'ohmpi_card_3_15', 'coef_p2': 2.50, # slope for current conversion for ADS.P2, measurement in V/V + 'sampling_rate': 10., # ms 'nb_samples': 20, # Max value 10 # was named integer before... }, 'mux': {'model' : 'dummy_mux', # 'ohmpi_i2c_mux64_v1.01', diff --git a/utils.py b/utils.py index 7f367f03..5e192644 100644 --- a/utils.py +++ b/utils.py @@ -21,14 +21,14 @@ def get_platform(): return platform, on_pi def change_config(config_file, verbose=True): - cwd = os.getcwd() + pwd = os.path.dirname(os.path.abspath(__file__)) try: - shutil.copyfile(f'{cwd}/OhmPi/config.py', f'{cwd}/OhmPi/config_tmp.py') - shutil.copyfile(f'{cwd}/OhmPi/{config_file}', f'{cwd}/OhmPi/config.py') + shutil.copyfile(f'{pwd}/config.py', f'{pwd}/config_tmp.py') + shutil.copyfile(f'{pwd}/{config_file}', f'{pwd}/config.py') if verbose: - print(f'Changed to {cwd}/OhmPi/{config_file}:\n') - with open(f'{cwd}/OhmPi/config.py', mode='r') as f: + print(f'Changed to {pwd}/{config_file}:\n') + with open(f'{pwd}/config.py', mode='r') as f: print(f.read()) except Exception as error: - print(f'Could not change config file to {cwd}/OhmPi/{config_file}:\n{error}') \ No newline at end of file + print(f'Could not change config file to {pwd}/{config_file}:\n{error}') \ No newline at end of file -- GitLab