Only set up pin that we are really going to use

This commit is contained in:
Oliver Gugger
2019-08-13 16:41:51 +02:00
parent 9ad3c53f64
commit cfa085391c

View File

@@ -79,17 +79,16 @@ def cli_args_parser():
return parser.parse_args() return parser.parse_args()
def __setup_GPIO(): def __setup_GPIO(channel=r_ch1):
""" """
Setup all GPIOs, set output mode, and set gpio mode to bcm Setup all GPIOs, set output mode, and set gpio mode to bcm
""" """
GPIO.setwarnings(False) GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) GPIO.setmode(GPIO.BCM)
for gpio in [r_ch1, r_ch2, r_ch3]: print("setting up gpio_{}".format(channel))
print("setting up gpio_{}".format(gpio)) GPIO.setup(channel, GPIO.OUT)
GPIO.setup(gpio, GPIO.OUT) __set_gpio(channel, S_OFF)
__set_gpio(gpio, S_OFF)
def __set_gpio(channel=r_ch1, value=S_OFF): def __set_gpio(channel=r_ch1, value=S_OFF):
""" """
@@ -107,6 +106,9 @@ def gpio_test():
Test all channels Test all channels
""" """
for i, gpio in enumerate([r_ch1, r_ch2, r_ch3], start=1): for i, gpio in enumerate([r_ch1, r_ch2, r_ch3], start=1):
# Setup gpio pin
__setup_GPIO(gpio)
__set_gpio(gpio, S_ON) __set_gpio(gpio, S_ON)
print("Channel_{}: gpio_{} on".format(i, gpio)) print("Channel_{}: gpio_{} on".format(i, gpio))
time.sleep(0.1) time.sleep(0.1)
@@ -118,6 +120,9 @@ def draw_beer(channel=r_ch1, wait=t_large_beer):
""" """
Draw a delicious beer, keep the tap on for n_wait seconds Draw a delicious beer, keep the tap on for n_wait seconds
""" """
# Setup gpio pin
__setup_GPIO(channel)
__set_gpio(channel, S_ON) __set_gpio(channel, S_ON)
time.sleep(wait) time.sleep(wait)
__set_gpio(channel, S_OFF) __set_gpio(channel, S_OFF)
@@ -131,9 +136,6 @@ if __name__ == "__main__":
print(args.products) print(args.products)
# Setup all gpio pins
__setup_GPIO()
# call functions according to the given arguments # call functions according to the given arguments
if args.test: if args.test:
print("Test mode enabled") print("Test mode enabled")