Commit de979804 authored by Olivier Kaufmann's avatar Olivier Kaufmann
Browse files

Updates mux_2024 specs handling

Showing with 18 additions and 27 deletions
+18 -27
...@@ -111,7 +111,6 @@ class MuxAbstract(ABC): ...@@ -111,7 +111,6 @@ class MuxAbstract(ABC):
if self.board_id is None: if self.board_id is None:
self.exec_logger.error(f'MUX {self.board_name} should have an id !') self.exec_logger.error(f'MUX {self.board_name} should have an id !')
self.exec_logger.debug(f'MUX {self.board_id} ({self.board_name}) initialization') self.exec_logger.debug(f'MUX {self.board_id} ({self.board_name}) initialization')
self.ctl = kwargs.pop('ctl', None)
self.io = kwargs.pop('io', None) self.io = kwargs.pop('io', None)
cabling = kwargs.pop('cabling', None) cabling = kwargs.pop('cabling', None)
self.cabling = {} self.cabling = {}
......
...@@ -5,25 +5,14 @@ from ohmpi.hardware_components import MuxAbstract ...@@ -5,25 +5,14 @@ from ohmpi.hardware_components import MuxAbstract
import adafruit_tca9548a # noqa import adafruit_tca9548a # noqa
from adafruit_mcp230xx.mcp23017 import MCP23017 # noqa from adafruit_mcp230xx.mcp23017 import MCP23017 # noqa
from digitalio import Direction # noqa from digitalio import Direction # noqa
from busio import I2C
# import time # import time
# board specs # hardware characteristics and limitations
voltage_max = 50 SPECS = {'voltage_max': 50., 'current_max': 3., 'activation_delay': 0.01, 'release_delay': 0.005}
current_max = 3.
activation_delay = 0.01
release_delay = 0.005
MUX_CONFIG = HARDWARE_CONFIG['mux'].pop('default', {})
MUX_CONFIG.update({'voltage_max': max(0.,min(MUX_CONFIG.pop('voltage_max', voltage_max), voltage_max)),
'current_max': max(0.,min(MUX_CONFIG.pop('current_max', voltage_max), voltage_max))})
MUX_CONFIG.update({'activation_delay': max(MUX_CONFIG.pop('activation_delay', activation_delay), activation_delay),
'release_delay': max(MUX_CONFIG.pop('release_delay', release_delay), release_delay)})
# defaults to 4 roles cabling electrodes from 1 to 8 # defaults to 4 roles cabling electrodes from 1 to 8
default_mux_cabling = {(elec, role) : ('mux_1', elec) for role in ['A', 'B', 'M', 'N'] for elec in range(1,9)} default_mux_cabling = {(elec, role) : ('mux_1', elec) for role in ['A', 'B', 'M', 'N'] for elec in range(1,9)}
# defaults to ic connection
ctl_connection = MUX_CONFIG.pop('connection', 'i2c')
inner_cabling = {'4_roles' : {(1, 'X'): {'MCP': 0, 'MCP_GPIO': 0}, (1, 'Y'): {'MCP': 0, 'MCP_GPIO': 8}, inner_cabling = {'4_roles' : {(1, 'X'): {'MCP': 0, 'MCP_GPIO': 0}, (1, 'Y'): {'MCP': 0, 'MCP_GPIO': 8},
(2, 'X'): {'MCP': 0, 'MCP_GPIO': 1}, (2, 'Y'): {'MCP': 0, 'MCP_GPIO': 9}, (2, 'X'): {'MCP': 0, 'MCP_GPIO': 1}, (2, 'Y'): {'MCP': 0, 'MCP_GPIO': 9},
...@@ -63,17 +52,19 @@ inner_cabling = {'4_roles' : {(1, 'X'): {'MCP': 0, 'MCP_GPIO': 0}, (1, 'Y'): {'M ...@@ -63,17 +52,19 @@ inner_cabling = {'4_roles' : {(1, 'X'): {'MCP': 0, 'MCP_GPIO': 0}, (1, 'Y'): {'M
class Mux(MuxAbstract): class Mux(MuxAbstract):
def __init__(self, **kwargs): def __init__(self, **kwargs):
if 'id' in kwargs.keys():
MUX_CONFIG.update(HARDWARE_CONFIG['mux']['boards'][kwargs['id']])
kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')}) kwargs.update({'board_name': os.path.basename(__file__).rstrip('.py')})
if 'cabling' not in kwargs.keys() or kwargs['cabling']=={}: kwargs.update({'cabling': kwargs.pop('cabling', default_mux_cabling)})
kwargs.update({'cabling': default_mux_cabling}) kwargs.update({'activation_delay': max(kwargs.pop('activation_delay', SPECS['activation_delay']),
if 'activation_delay' not in kwargs: SPECS['activation_delay'])})
kwargs.update({'activation_delay': MUX_CONFIG['activation_delay']}) kwargs.update({'release_delay': max(kwargs.pop('release_delay', SPECS['release_delay']),
if 'release_delay' not in kwargs: SPECS['activation_delay'])})
kwargs.update({'release_delay': MUX_CONFIG['release_delay']}) kwargs.update({'voltage_max': max(0., min(kwargs.pop('voltage_max', SPECS['voltage_max']),
SPECS['voltage_max']))})
kwargs.update({'current_max': max(0., min(kwargs.pop('current_max', SPECS['current_max']),
SPECS['current_max']))})
super().__init__(**kwargs) super().__init__(**kwargs)
self.exec_logger.debug(f'configuration: {MUX_CONFIG}') assert isinstance(self.io, I2C)
self.exec_logger.debug(f'configuration: {kwargs}')
tca_address = kwargs.pop('tca_address', None) tca_address = kwargs.pop('tca_address', None)
tca_channel = kwargs.pop('tca_channel', 0) tca_channel = kwargs.pop('tca_channel', 0)
self._roles = kwargs.pop('roles', None) self._roles = kwargs.pop('roles', None)
...@@ -86,7 +77,7 @@ class Mux(MuxAbstract): ...@@ -86,7 +77,7 @@ class Mux(MuxAbstract):
else: else:
self.exec_logger.error(f'Invalid role assignment for {self.board_name}: {self._roles} !') self.exec_logger.error(f'Invalid role assignment for {self.board_name}: {self._roles} !')
self._mode = '' self._mode = ''
self.io = self.ctl.connections[kwargs.pop('connection', ctl_connection)] # self.io = self.ctl.connections[kwargs.pop('connection', ctl_connection)] -> to hardware_system
if tca_address is None: if tca_address is None:
self._tca = self.io self._tca = self.io
else: else:
......
...@@ -24,6 +24,7 @@ voltage_adc_voltage_min = 10. # mV ...@@ -24,6 +24,7 @@ voltage_adc_voltage_min = 10. # mV
voltage_adc_voltage_max = 4500. # mV voltage_adc_voltage_max = 4500. # mV
sampling_rate = 20. # Hz sampling_rate = 20. # Hz
data_rate = 860. # S/s? data_rate = 860. # S/s?
RX_CONFIG['voltage_min'] = np.min([voltage_adc_voltage_min, RX_CONFIG.pop('voltage_min', np.inf)]) # mV RX_CONFIG['voltage_min'] = np.min([voltage_adc_voltage_min, RX_CONFIG.pop('voltage_min', np.inf)]) # mV
RX_CONFIG['voltage_max'] = np.min([voltage_adc_voltage_max, RX_CONFIG.pop('voltage_max', np.inf)]) # mV RX_CONFIG['voltage_max'] = np.min([voltage_adc_voltage_max, RX_CONFIG.pop('voltage_max', np.inf)]) # mV
RX_CONFIG['sampling_rate'] = RX_CONFIG.pop('sampling_rate', sampling_rate) RX_CONFIG['sampling_rate'] = RX_CONFIG.pop('sampling_rate', sampling_rate)
......
...@@ -108,9 +108,9 @@ class OhmPiHardware: ...@@ -108,9 +108,9 @@ class OhmPiHardware:
if isinstance(ctl, dict): if isinstance(ctl, dict):
mux_ctl_module = importlib.import_module(f'ohmpi.hardware_components.{mux_config["ctl"]["model"]}') mux_ctl_module = importlib.import_module(f'ohmpi.hardware_components.{mux_config["ctl"]["model"]}')
ctl = mux_ctl_module.Ctl(**self.ctl) ctl = mux_ctl_module.Ctl(**self.ctl)
mux_config.update({'ctl': ctl})
assert issubclass(type(mux_config['ctl']), CtlAbstract) assert issubclass(type(mux_config['ctl']), CtlAbstract)
io = mux_module.pop('io', self.ctl.connections[mux_config.pop('connection', 'i2c')])
mux_config.update({'io': io})
mux_config['id'] = mux_id mux_config['id'] = mux_id
self.mux_boards[mux_id] = mux_module.Mux(**mux_config) self.mux_boards[mux_id] = mux_module.Mux(**mux_config)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment