bindings: python: examples: make gpiomon.py output resemble the original
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Mon, 12 Aug 2019 12:12:13 +0000 (14:12 +0200)
committerBartosz Golaszewski <bgolaszewski@baylibre.com>
Mon, 12 Aug 2019 12:12:13 +0000 (14:12 +0200)
Modify the gpiomon.py example to describe the detected events in
a format similar to the one used by the original gpiomon tool.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
bindings/python/examples/gpiomon.py

index 9cb71daa9720a69c8daa056326347907a55f8c12..2615f4a36449d7098e7933580b6213b0aba0d2eb 100755 (executable)
@@ -14,13 +14,15 @@ import sys
 
 def print_event(event):
     if event.type == gpiod.LineEvent.RISING_EDGE:
-        print(' RISING EDGE', end='')
+        evstr = ' RISING EDGE'
     elif event.type == gpiod.LineEvent.FALLING_EDGE:
-        print('FALLING EDGE', end='')
+        evstr = 'FALLING EDGE'
     else:
         raise TypeError('Invalid event type')
 
-    print(' {}.{} line: {}'.format(event.sec, event.nsec, event.source.offset()))
+    print('event: {} offset: {} timestamp: [{}.{}]'.format(evstr,
+                                                           event.source.offset(),
+                                                           event.sec, event.nsec))
 
 if len(sys.argv) < 3:
     raise TypeError('usage: gpiomon.py <gpiochip> <offset1> <offset2> ...')