From 09af767dffbc5dd5e7c7db96d945385e6d03ccac Mon Sep 17 00:00:00 2001
From: su530201 <olivier.kaufmann@umons.ac.be>
Date: Mon, 28 Aug 2023 10:47:19 +0200
Subject: [PATCH] Adds a test for 2 role mux_2024 board

---
 dev/test_mux_2024.py            |  6 ++--
 dev/test_mux_2024_2_roles_AB.py | 50 +++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 3 deletions(-)
 create mode 100644 dev/test_mux_2024_2_roles_AB.py

diff --git a/dev/test_mux_2024.py b/dev/test_mux_2024.py
index 7dbd6341..0d57749c 100644
--- a/dev/test_mux_2024.py
+++ b/dev/test_mux_2024.py
@@ -6,9 +6,9 @@ from ohmpi.hardware_components.mux_2024_rev_0_0 import Mux, MUX_CONFIG
 from ohmpi.hardware_components import raspberry_pi_i2c as ctl_module
 # from ohmpi.config import HARDWARE_CONFIG
 
-stand_alone_mux = False
-part_of_hardware_system = False
-within_ohmpi = True
+stand_alone_mux = False  # Testing hardware component alone
+part_of_hardware_system = False  # Testing hardware component as a part of the hardware system
+within_ohmpi = True # Testing hardware component as a part of the hardware system through the ohmpi object
 # Stand alone mux
 if stand_alone_mux:
     MUX_CONFIG['ctl'] = ctl_module.Ctl()
diff --git a/dev/test_mux_2024_2_roles_AB.py b/dev/test_mux_2024_2_roles_AB.py
new file mode 100644
index 00000000..c8daee6a
--- /dev/null
+++ b/dev/test_mux_2024_2_roles_AB.py
@@ -0,0 +1,50 @@
+import time
+from ohmpi.utils import change_config
+import logging
+change_config('../configs/config_mb_2023_mux_2024_2_roles_AB.py', verbose=False)
+from ohmpi.hardware_components.mux_2024_rev_0_0 import Mux, MUX_CONFIG
+from ohmpi.hardware_components import raspberry_pi_i2c as ctl_module
+# from ohmpi.config import HARDWARE_CONFIG
+
+stand_alone_mux = True  # Testing hardware component alone
+part_of_hardware_system = False  # Testing hardware component as a part of the hardware system
+within_ohmpi = False  # Testing hardware component as a part of the hardware system through the ohmpi object
+update_mux_config = False
+# Stand alone mux
+if stand_alone_mux:
+    # MUX_CONFIG['ctl'] = ctl_module.Ctl()
+    # MUX_CONFIG['id'] = 'mux_1'
+    # MUX_CONFIG['cabling'] = {(i+8, j) : ('mux_1', i) for j in ['A', 'B', 'M', 'N'] for i in range(1,9)}
+    mux = Mux(**MUX_CONFIG)
+    mux.switch_one(elec=2, role='A', state='on')
+    time.sleep(2)
+    mux.switch_one(elec=2, role='A', state='off')
+    mux.switch({'A': [2], 'B': [3]}, state='on')
+    time.sleep(8)
+    # mux.switch({'A': [1], 'B': [4], 'M': [2], 'N': [3]}, state='off')
+    mux.reset()
+    mux.test({'A': [i for i in range(1, 17)], 'B': [i for i in range(1, 17)]}, activation_time=.1)
+
+# mux as part of a OhmPiHardware system
+if part_of_hardware_system:
+    from ohmpi.hardware_system import OhmPiHardware
+    print('Starting test of mux as part of a OhmPiHardware system.')
+
+    k = OhmPiHardware()
+    k.exec_logger.setLevel(logging.DEBUG)
+
+    # Test mux switching
+    k.reset_mux()
+    k.switch_mux(electrodes=[1, 4, 2, 3], roles=['A', 'B', 'M', 'N'], state='on')
+    time.sleep(1.)
+    k.switch_mux(electrodes=[1, 4, 2, 3], roles=['A', 'B', 'M', 'N'], state='off')
+
+if within_ohmpi:
+    from ohmpi.ohmpi import OhmPi
+    print('Starting test of mux within OhmPi.')
+    k = OhmPi()
+    k.switch_mux_on([1, 4, 2, 3])
+    time.sleep(1.)
+    k.reset_mux()
+
+change_config('../configs/config_default.py', verbose=False)
-- 
GitLab