unify logging
This commit is contained in:
parent
499b20c079
commit
5c32645105
|
@ -1 +1 @@
|
|||
Subproject commit a2146940f7840612ae16df2df58c669c39158642
|
||||
Subproject commit c392edccf7608d8699e6d1c4d7cd9182ff583a41
|
17
buttond.py
17
buttond.py
|
@ -15,6 +15,7 @@ __email__ = "kevin@company235.com"
|
|||
__status__ = "Prototype"
|
||||
|
||||
import configparser
|
||||
import logging
|
||||
from signal import pause
|
||||
from baconscript import comment
|
||||
from gpiozero import Button, GPIODeviceError
|
||||
|
@ -24,6 +25,8 @@ from gpiozero import Button, GPIODeviceError
|
|||
# from gpiozero import Device
|
||||
# Device.pin_factory = MockFactory()
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# callback intermidiary to sanitize user input
|
||||
def _activate(macro):
|
||||
|
@ -33,7 +36,7 @@ def _activate(macro):
|
|||
if macro == "":
|
||||
return
|
||||
# pass macro to baconscript
|
||||
print("doing macro ", macro)
|
||||
log.info("doing macro %s", macro)
|
||||
comment(macro)
|
||||
|
||||
|
||||
|
@ -53,16 +56,16 @@ for b in config.get('button', 'names').split(','):
|
|||
closed = c.get('close', None)
|
||||
opened = c.get('open', None)
|
||||
# set up button on pin
|
||||
print('init', b, 'on GPIO', pin)
|
||||
log.debug('init %s on GPIO %s', b, pin)
|
||||
_buttons[b] = Button(pin)
|
||||
# connect button callbacks to anonymous functions
|
||||
print('connecting', b, '"closed" to macro', closed)
|
||||
log.info('connecting %s "closed" to macro %s', b, closed)
|
||||
_buttons[b].when_pressed = lambda macro=closed: _activate(macro)
|
||||
print('connecting', b, '"opened" to macro', opened)
|
||||
log.info('connecting %s "opened" to macro %s', b, opened)
|
||||
_buttons[b].when_released = lambda macro=opened: _activate(macro)
|
||||
|
||||
except (KeyError, GPIODeviceError) as e:
|
||||
print('Error configuring button', b, e)
|
||||
log.error('Error configuring button %s: %s', b, e)
|
||||
continue
|
||||
|
||||
|
||||
|
@ -71,7 +74,7 @@ try:
|
|||
del pin, closed, opened
|
||||
del c, config
|
||||
except NameError as e:
|
||||
print('failed to release memory', e)
|
||||
log.error('failed to release memory: %s', e)
|
||||
|
||||
|
||||
# when run directly, sleep until button signal or KeyboardInterrupt
|
||||
|
@ -82,4 +85,4 @@ if __name__ == '__main__':
|
|||
print()
|
||||
else:
|
||||
# indicate prefered method of sleeping when laoded as a module
|
||||
print('call signal.pause() instead of time.sleep()')
|
||||
log.debug('call signal.pause() instead of time.sleep()')
|
||||
|
|
Loading…
Reference in New Issue