Skip to content

Commit e170d81

Browse files
TobiasSchaffnerchombourger
authored andcommitted
power/gpio: Allow to configure low level triggered relays
Introduce an optional `enable` config key for the power gpio. This config defaults to `high` for high level triggered relays but can be set to `low` for low level triggered relays. Signed-off-by: Tobias Schaffner <[email protected]>
1 parent a399bf6 commit e170d81

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

docs/config.rst

+4
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,14 @@ supported:
262262
Format: <gpiochipx>@<pin>
263263
If multiple GPIO lines and pins are used separate the entries using ','.
264264

265+
* ``enable``: string [optional]
266+
If the relay enable trigger is ``high`` or ``low``. Defaults to ``high``.
267+
265268
Example::
266269

267270
# For single GPIO line
268271
gpio = gpiochip0@201
272+
enable = high
269273
# For multiple GPIO lines
270274
gpio = gpiochip0@201,gpiochip1@11,gpiochip0@203
271275

mtda.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ time-until = login:
132132
variant=aviosys_8800
133133

134134
# variant=gpio
135-
# pins=48
135+
# gpio=gpiochip0@203
136+
# enable=high
136137

137138
# variant=pduclient
138139
# daemon=134.86.60.40

mtda/power/gpio.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,29 @@
1919

2020
class GpioPowerController(PowerController):
2121

22+
HIGH = 1
23+
LOW = 0
24+
2225
def __init__(self, mtda):
2326
self.dev = None
2427
self.mtda = mtda
2528
self.lines = []
2629
self.gpiopair = []
30+
self.trigger = self.HIGH
2731

2832
def configure(self, conf):
2933
self.mtda.debug(3, "power.gpio.configure()")
3034

3135
result = None
3236

37+
if 'enable' in conf:
38+
if conf['enable'] == 'high':
39+
self.trigger = self.HIGH
40+
elif conf['enable'] == 'low':
41+
self.trigger = self.LOW
42+
else:
43+
raise ValueError("'enable' shall be either 'high' or 'low'!")
44+
3345
if 'gpio' in conf:
3446
for gpio in conf['gpio'].split(','):
3547
self.gpiopair.append(itemgetter(0, 1)(gpio.split('@')))
@@ -83,7 +95,7 @@ def on(self):
8395
result = False
8496

8597
for line in self.lines:
86-
line.set_value(1)
98+
line.set_value(self.trigger)
8799
result = self.status() == self.POWER_ON
88100

89101
self.mtda.debug(3, f"power.gpio.on(): {result}")
@@ -95,7 +107,7 @@ def off(self):
95107
result = False
96108

97109
for line in self.lines:
98-
line.set_value(0)
110+
line.set_value(self.trigger ^ 1)
99111
result = self.status() == self.POWER_OFF
100112

101113
self.mtda.debug(3, f"power.gpio.off(): {result}")
@@ -109,7 +121,7 @@ def status(self):
109121

110122
for line in self.lines:
111123
value = line.get_value()
112-
if value == 1:
124+
if value == self.trigger:
113125
value = self.POWER_ON
114126
else:
115127
value = self.POWER_OFF

0 commit comments

Comments
 (0)