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)
|
logging.basicConfig(level=logging.INFO)
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Entry point for direct execution."""
|
||||||
|
## run the event loop
|
||||||
|
try:
|
||||||
|
pause()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
def activate(macro):
|
def activate(macro):
|
||||||
"""Sanitize user configured macros."""
|
"""Sanitize user configured macros."""
|
||||||
if macro is None:
|
if macro is None:
|
||||||
|
@ -79,10 +89,7 @@ except NameError as e:
|
||||||
|
|
||||||
# when run directly, sleep until button signal or KeyboardInterrupt
|
# when run directly, sleep until button signal or KeyboardInterrupt
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
main()
|
||||||
pause()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print()
|
|
||||||
else:
|
else:
|
||||||
# indicate prefered method of sleeping when laoded as a module
|
# indicate prefered method of sleeping when laoded as a module
|
||||||
log.debug('call signal.pause() instead of time.sleep()')
|
log.debug('call signal.pause() instead of time.sleep()')
|
||||||
|
|
Loading…
Reference in New Issue