Skip to content

Instantly share code, notes, and snippets.

@nbuchwitz
Created December 30, 2022 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nbuchwitz/ba65229977a3b314c1c4c2bd39b38015 to your computer and use it in GitHub Desktop.
Save nbuchwitz/ba65229977a3b314c1c4c2bd39b38015 to your computer and use it in GitHub Desktop.
#!/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