From 924d4a04275250910ca8d977ebd1fdf303d7242e Mon Sep 17 00:00:00 2001
From: su530201 <olivier.kaufmann@umons.ac.be>
Date: Thu, 1 Jun 2023 12:27:06 +0200
Subject: [PATCH] Removes option in ohmpi_card_3_15 to create a ctl if ctl
 config is passed as a dict

---
 ohmpi/hardware_components/ohmpi_card_3_15.py  | 5 +----
 ohmpi/hardware_components/raspberry_pi_i2c.py | 1 +
 ohmpi/hardware_system.py                      | 8 +++++---
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/ohmpi/hardware_components/ohmpi_card_3_15.py b/ohmpi/hardware_components/ohmpi_card_3_15.py
index 58a5f022..828d9166 100644
--- a/ohmpi/hardware_components/ohmpi_card_3_15.py
+++ b/ohmpi/hardware_components/ohmpi_card_3_15.py
@@ -48,6 +48,7 @@ TX_CONFIG['default_voltage'] = np.min([TX_CONFIG.pop('default_voltage', np.inf),
 TX_CONFIG['mcp_board_address'] = TX_CONFIG.pop('mcp_board_address', tx_mcp_board_address)
 TX_CONFIG['low_battery'] = TX_CONFIG.pop('low_battery', low_battery)
 
+
 def _gain_auto(channel):
     """Automatically sets the gain on a channel
 
@@ -83,8 +84,6 @@ class Tx(TxAbstract):
         self.current_adjustable = False
         if self.ctl is None:
             self.ctl = ctl_module.Ctl()
-        elif isinstance(self.ctl, dict):
-            self.ctl = ctl_module.Ctl(dict)
 
         # I2C connexion to MCP23008, for current injection
         self.mcp_board = MCP23008(self.ctl.bus, address=TX_CONFIG['mcp_board_address'])
@@ -207,8 +206,6 @@ class Rx(RxAbstract):
         super().__init__(**kwargs)
         if self.ctl is None:
             self.ctl = ctl_module.Ctl()
-        elif isinstance(self.ctl, dict):
-            self.ctl = ctl_module.Ctl(dict)
 
         # ADS1115 for voltage measurement (MN)
         self._ads_voltage_address = 0x49
diff --git a/ohmpi/hardware_components/raspberry_pi_i2c.py b/ohmpi/hardware_components/raspberry_pi_i2c.py
index 8f8a802c..aa6d9a37 100644
--- a/ohmpi/hardware_components/raspberry_pi_i2c.py
+++ b/ohmpi/hardware_components/raspberry_pi_i2c.py
@@ -5,6 +5,7 @@ import os
 from ohmpi.utils import get_platform
 from gpiozero import CPUTemperature  # noqa
 
+
 class Ctl(CtlAbstract):
     def __init__(self, **kwargs):
         kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')})
diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py
index 294674f3..ee52b4ca 100644
--- a/ohmpi/hardware_system.py
+++ b/ohmpi/hardware_system.py
@@ -50,9 +50,11 @@ class OhmPiHardware:
         if self.soh_logger is None:
             self.soh_logger = create_stdout_logger('soh_hw')
         self.tx_sync = Event()
-        self.ctl = kwargs.pop('ctl', ctl_module.Ctl(exec_logger=self.exec_logger,
-                                                    data_logger=self.data_logger,
-                                                    soh_logger=self.soh_logger))
+        HARDWARE_CONFIG['ctl'].pop('model')
+        HARDWARE_CONFIG['ctl'].update({'exec_logger': self.exec_logger, 'data_logger': self.data_logger,
+                                       'soh_logger': self.soh_logger})
+        self.ctl = kwargs.pop('ctl', ctl_module.Ctl(**HARDWARE_CONFIG['ctl']))
+
         self.rx = kwargs.pop('rx', rx_module.Rx(exec_logger=self.exec_logger,
                                                 data_logger=self.data_logger,
                                                 soh_logger=self.soh_logger,
-- 
GitLab