-
-
Save nbuchwitz/ba65229977a3b314c1c4c2bd39b38015 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import revpimodio2 | |
# wrapper function for event handler which takes the desired output name as a parameter | |
def wrapper(output): | |
def event_fn(name, value): | |
# write value to output with given name | |
rpi.io[output].value = int(value) | |
return event_fn | |
# create revpimodio instance | |
rpi = revpimodio2.RevPiModIO(autorefresh=True) | |
# cleanup on ctrl + c | |
rpi.handlesignalend() | |
# the input -> output mapping | |
mapping = { "I_1": "Output_1", "I_2": "Output_2" } | |
for input_name, output_name in mapping.items(): | |
assert input_name in rpi.io | |
assert output_name in rpi.io | |
# register IO event for input_name with handler returned from wrapper | |
rpi.io[input_name].reg_event(wrapper(output_name), prefire=True) | |
# start main loop | |
rpi.mainloop(blocking=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment