From 9168a14dd139f4b2578b7862e7a332ba62e6e8d3 Mon Sep 17 00:00:00 2001 From: kruger <kruger@astron.nl> Date: Wed, 26 May 2021 21:19:51 +0200 Subject: [PATCH] UNB2 LED working, inverted --- config/UNB2TR.yaml | 9 +++++---- i2cserv/gpio.py | 6 ++++-- i2cserv/i2c_array2.py | 17 +++++++++++++---- i2cserv/i2c_switch2.py | 24 +++++++++++++++++++++--- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/config/UNB2TR.yaml b/config/UNB2TR.yaml index af2b56a..8ec5992 100644 --- a/config/UNB2TR.yaml +++ b/config/UNB2TR.yaml @@ -76,7 +76,7 @@ device_registers: description: IO-Expander for front panel address: 0x41 device: PCA9536 - driver: d_front_panel + driver: switch_FP registers: - name: CONF #default 0xff = all input description: Direction of GPIO @@ -154,7 +154,7 @@ variables: mask: UNB2_mask driver: switch_FP devreg: FP_IO.GPIO - bitoffset: 4 +# bitoffset: 4 width: 3 rw: rw dtype: uint8 @@ -367,10 +367,11 @@ methods: - name: UNB2_on mask: UNB2_mask + driver: switch_FP instructions: -# - FP_IO.CONF: 0xff #TODO: setup correctly + - FP_IO.CONF: 0xf8 #bit 0-2 output for LED - UNB2_PWR_on: 0 #already inverted - - UNB2_Front_Panel_LED_colour: 1 + - UNB2_Front_Panel_LED_colour: 3 #green - UNB2_PCB_ID: Update - UNB2_PCB_version: Update diff --git a/i2cserv/gpio.py b/i2cserv/gpio.py index 122c09a..eaa4731 100644 --- a/i2cserv/gpio.py +++ b/i2cserv/gpio.py @@ -26,8 +26,10 @@ class gpio(hwdev): logging.warning("Wrong mask length"); mask=[True]*self.Npins; if len(data)!=self.Npins: - logging.warning("Wrong data length"); - return [] + if len(data)==1: data=[data[0]]*self.Npins; + else: + logging.warning("Wrong data length"); + return [] for i,pin in enumerate(self.pins): if mask[i]: GPIO.output(pin,data[i]%2); diff --git a/i2cserv/i2c_array2.py b/i2cserv/i2c_array2.py index 0b62a46..02f656a 100644 --- a/i2cserv/i2c_array2.py +++ b/i2cserv/i2c_array2.py @@ -37,9 +37,18 @@ class i2c_array2(i2c_array): self.conf['parentcls'].SetSW3(self.sw3[RCUi]); def SetSwitchMask(self,mask): - logging.warn("Not implemented!!") -# m=0; -# for RCUi in range(self.N): -# if mask[RCUi]: m|=1<<self.RCU_Switch1[RCUi]; + sw1=[];sw2=[];sw3=[]; + m=0; + for RCUi in range(self.N): + if mask[RCUi]: + if self.sw1[RCUi] not in sw1: sw1.append(self.sw1[RCUi]) + if self.sw2[RCUi] not in sw2: sw2.append(self.sw2[RCUi]) + if len(self.sw3)>0: + if self.sw3[RCUi] not in sw3: sw3.append(self.sw3[RCUi]) + logging.info(str(("SetSwitchMask",sw1,sw2,sw3))) + self.conf['parentcls'].SetSWx(sw1,sw2,sw3) +# self.conf['parentcls'].SetSW1(self.sw1[RCUi]); + +# m|=1<<self.RCU_Switch1[RCUi]; # self.conf['parentcls'].SetChannel(m); diff --git a/i2cserv/i2c_switch2.py b/i2cserv/i2c_switch2.py index 4600c0a..b0b1620 100644 --- a/i2cserv/i2c_switch2.py +++ b/i2cserv/i2c_switch2.py @@ -12,7 +12,7 @@ class i2c_switch2(i2c): self.channel2=-1 self.channel3=-1 logging.info("i2c switch2 at address %i,%i,%i" % (self.SWaddr1,self.SWaddr2,self.SWaddr3)) - logging.warn("APSCT switch disabled for testing") +# logging.warn("APSCT switch disabled for testing") def SetSW1(self,channelbit): channel=1<<(channelbit) @@ -21,8 +21,8 @@ class i2c_switch2(i2c): self.channel1=channel self.channel2=-1 self.channel3=-1 - return True; #testing without APSCT switch -# return self.i2csetget(self.SWaddr1,[channel]) +# return True; #testing without APSCT switch + return self.i2csetget(self.SWaddr1,[channel]) def SetSW2(self,channelbit): channel=1<<(channelbit) @@ -39,3 +39,21 @@ class i2c_switch2(i2c): self.channel3=channel return self.i2csetget(self.SWaddr3,[channel]) + def SetSWx(self,sw1,sw2,sw3): + channel=0; + for x in sw1: channel+=(1<<x); + self.channel1=channel; + self.i2csetget(self.SWaddr1,[channel]) + if channel==0: return; + channel=0; + for x in sw2: channel+=(1<<x); + self.channel2=channel; + self.i2csetget(self.SWaddr2,[channel]) + if channel==0: return; + channel=0; + for x in sw3: channel+=(1<<x); + if channel==0: return; + self.channel3=channel; + self.i2csetget(self.SWaddr3,[channel]) + + -- GitLab