move the event loop to a main() function
This commit is contained in:
parent
35d20682fc
commit
f1505037b1
15
buttond.py
15
buttond.py
|
@ -28,6 +28,16 @@ from gpiozero import Button, GPIODeviceError
|
|||
logging.basicConfig(level=logging.INFO)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def main():
|
||||
"""Entry point for direct execution."""
|
||||
## run the event loop
|
||||
try:
|
||||
pause()
|
||||
except KeyboardInterrupt:
|
||||
print()
|
||||
|
||||
|
||||
def activate(macro):
|
||||
"""Sanitize user configured macros."""
|
||||
if macro is None:
|
||||
|
@ -79,10 +89,7 @@ except NameError as e:
|
|||
|
||||
# when run directly, sleep until button signal or KeyboardInterrupt
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
pause()
|
||||
except KeyboardInterrupt:
|
||||
print()
|
||||
main()
|
||||
else:
|
||||
# indicate prefered method of sleeping when laoded as a module
|
||||
log.debug('call signal.pause() instead of time.sleep()')
|
||||
|
|
Loading…
Reference in New Issue