From eaf07f050728a5269a51514556b639cd94df9146 Mon Sep 17 00:00:00 2001
From: su530201 <olivier.kaufmann@umons.ac.be>
Date: Thu, 19 Oct 2023 18:15:40 +0200
Subject: [PATCH] Updates current_max

---
 ohmpi/hardware_components/pwr_dps5005.py | 2 +-
 ohmpi/hardware_system.py                 | 4 +++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/ohmpi/hardware_components/pwr_dps5005.py b/ohmpi/hardware_components/pwr_dps5005.py
index f538df9a..13e98a35 100644
--- a/ohmpi/hardware_components/pwr_dps5005.py
+++ b/ohmpi/hardware_components/pwr_dps5005.py
@@ -72,7 +72,7 @@ class Pwr(PwrAbstract):
         return self._battery_voltage
 
     def current_max(self, value):
-        self.connection.write_register(0x0001, value * 10, 0)
+        self.connection.write_register(0x0001, value, 0)
 
     @property
     def pwr_state(self):
diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py
index 6eb7a367..dd397e4a 100644
--- a/ohmpi/hardware_system.py
+++ b/ohmpi/hardware_system.py
@@ -43,7 +43,7 @@ for k, v in rx_module.SPECS['rx'].items():
     except Exception as e:
         print(f'Cannot set value {v} in RX_CONFIG[{k}]:\n{e}')
 
-current_max = np.min([TX_CONFIG['current_max'],  # TODO: replace 50 by a TX config
+current_max = np.min([TX_CONFIG['current_max'],  HARDWARE_CONFIG['pwr']['current_max'], # TODO: replace 50 by a TX config
                       np.min(np.hstack((np.inf, [MUX_CONFIG[i].pop('current_max', np.inf) for i in MUX_CONFIG.keys()])))])
 voltage_max = np.min([TX_CONFIG['voltage_max'],
                       np.min(np.hstack((np.inf, [MUX_CONFIG[i].pop('voltage_max', np.inf) for i in MUX_CONFIG.keys()])))])
@@ -99,6 +99,7 @@ class OhmPiHardware:
         HARDWARE_CONFIG['pwr'].pop('model')
         HARDWARE_CONFIG['pwr'].update(**HARDWARE_CONFIG['pwr'])  # NOTE: Explain why this is needed or delete me
         HARDWARE_CONFIG['pwr'].update({'ctl': HARDWARE_CONFIG['pwr'].pop('ctl', self.ctl)})
+        HARDWARE_CONFIG['pwr'].update({'current_max': current_max})
         if isinstance(HARDWARE_CONFIG['pwr']['ctl'], dict):
             ctl_mod = HARDWARE_CONFIG['pwr']['ctl'].pop('model', self.ctl)
             if isinstance(ctl_mod, str):
@@ -135,6 +136,7 @@ class OhmPiHardware:
         if isinstance(self.tx, dict):
             self.tx = tx_module.Tx(**self.tx)
         self.tx.pwr = self.pwr
+        self.tx.pwr._current_max = current_max
 
         # Initialize Muxes
         self._cabling = kwargs.pop('cabling', {})
-- 
GitLab