|
Post by lbendlin on Jan 28, 2019 8:18:53 GMT -8
Say I want to retrieve the current status of Load Switch 0 . I don't want to change it, or impact any other load switches. What would be the appropriate code for that?
|
|
|
Post by SDL on Jan 29, 2019 10:02:56 GMT -8
You would read the I/O control register on the GPIO chip. Or keep your status within the program.
BP
|
|
|
Post by lbendlin on Jan 29, 2019 10:48:16 GMT -8
I have SJ1, SJ2 and SJ4 soldered over because I need the loads to be switched on when the I2C is missing (I am powering the QPM from the SunControl VDDM). Would that be properly reflected in the I/O control register returned data one i2c is back up? Or would i2c not know anything about these hardware bridges?
|
|
|
Post by SDL on Jan 31, 2019 11:24:31 GMT -8
OK. I officially now don't understand what you are doing. Let me go look at the spec.
BP
|
|
|
Post by lbendlin on Jan 31, 2019 12:15:47 GMT -8
I did some tests and the code has no idea if the SJ bridges are soldered. It can only tell me the status of a switch (GPIO) AFTER setting said switch (before that the readGPIO(0) always comes back as 0, regardless of actual status). That's lame, I would think.
I mean, yes, I know that three out of four bridges are soldered, and I can set the switches as per current conditions. But that would mean that I need to keep the switch status data offsite, negating the benefits of being able to read the GPIO.
The issue is not limited to the bridges though. Whenever I instantiate the QPM in Python, it has again forgotten what the status of each port is. The only remedy would be to keep the python script running perpetually but I don't want to waste cycles on that when I only need to read the status every five minutes.
|
|
|
Post by lbendlin on Feb 2, 2019 11:53:57 GMT -8
Ok, have done some more research. It seems that the QPM _does_ remember the status of its switches, except for the first time after power-on*. But I can live with that since I know what the status is at power-on.
I have rewritten the init routine to better suit my needs (and also elimination quite a few lines of code)
def __init__(self, twi=1, addr=QuadPower_ADDRESS):
self._bus = smbus.SMBus(twi)
self._QuadPower_i2caddr = addr
# variables
# 0..3 switches, 4..7 input
self._QuadPower_direction = 0xF0
self._QuadPower_pullup = 0
self._QuadPower_pulldown = 0xF0
self._QuadPower_interruptmask = 0
#set direction-input for GPIO, output for switches
self.wireWriteRegister(self.QuadPower_REGDIR_ADDR, self._QuadPower_direction);
#set pulldown for GPIO
self.wireWriteRegister(self.QuadPower_REGPULLDOWN_ADDR, self._QuadPower_pulldown);
#
#self.writeGPIO(0) One thing that threw me off massively is this part
QuadPower_INPUT = (0x01) # 0 means input
QuadPower_OUTPUT = (0x00) # 1 means output Can you please correct that in GitHub? 0 actually means Output and 1 means Input
So now all I need is to call
>>> import SDL_Pi_QPM
>>> QuadPower = SDL_Pi_QPM.SDL_Pi_QPM()
>>> QuadPower.readGPIO()
11 to get the current status of the switches.
* Upon power up and first instantiation ALL switches will be turned on (not just the ones with the bridges soldered) but as I said that's fine for my setup. It can be modified in the init script.
|
|