44 lines
988 B
Python
44 lines
988 B
Python
#import RPi.GPIO as GPIO
|
|
import time
|
|
import subprocess
|
|
|
|
Relay = [5, 6, 13, 16, 19, 20, 21, 26]
|
|
All_Relays = "5,6,13,16,19,20,21,26"
|
|
ON = 1
|
|
OFF = 0
|
|
# GPIO.HIGH -> relay off
|
|
# GPIO.LOW -> relay on
|
|
|
|
#GPIO.setmode(GPIO.BCM)
|
|
#GPIO.setwarnings(False)
|
|
|
|
|
|
def init():
|
|
# alle Relais auf output und ausschalten
|
|
res = subprocess.run(["pinctrl", All_Relays, "op", "dh"])
|
|
|
|
|
|
def on(id):
|
|
# GPIO.output(Relay[id], GPIO.LOW)
|
|
res = subprocess.run(["pinctrl", f"{Relay[id]}", "op", "dl"])
|
|
|
|
def off(id):
|
|
# GPIO.output(Relay[id], GPIO.HIGH)
|
|
res = subprocess.run(["pinctrl", f"{Relay[id]}", "op", "dh"])
|
|
|
|
def setOnOff(id, state):
|
|
if state==ON:
|
|
on(id)
|
|
elif state==OFF:
|
|
off(id)
|
|
|
|
def onoffstatus(id):
|
|
res = subprocess.run(["pinctrl", "lev", f"{Relay[id]}"], capture_output=True, text=True)
|
|
if res.returncode == 0:
|
|
out = int(res.stdout)
|
|
if out == 1:
|
|
return OFF
|
|
if out == 0:
|
|
return ON
|
|
raise ValueError
|