From 99b37cbb2980f41040987b56460f7e0b37fe8b5f Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Wed, 23 Dec 2020 00:30:25 +0100 Subject: [PATCH] rfm69: print all messages to stderr (#7) This allows code using this module to print its output to stdout without interference. Possible future improvement: add an option to specify if any non-fatal message should be printed. --- raspyrfm/rfm69.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/raspyrfm/rfm69.py b/raspyrfm/rfm69.py index 30da88a..f2f8b14 100644 --- a/raspyrfm/rfm69.py +++ b/raspyrfm/rfm69.py @@ -1,3 +1,5 @@ +from __future__ import print_function +import sys import RPi.GPIO as GPIO import spidev import threading @@ -181,7 +183,7 @@ class Rfm69(threading.Thread): def __init__(self, cs = 0, gpio_int = 25): if not self.test(cs, gpio_int): - print("ERROR! RFM69 not found") + print("ERROR! RFM69 not found", file=sys.stderr) return self.__event = threading.Event() @@ -195,7 +197,7 @@ class Rfm69(threading.Thread): self.__packet_format = PacketFormat_Fixed self.__aes_on = False - print("RFM69 found on CS " + str(cs)) + print("RFM69 found on CS " + str(cs), file=sys.stderr) GPIO.setmode(GPIO.BCM) GPIO.setup(gpio_int, GPIO.IN) GPIO.add_event_detect(gpio_int, GPIO.RISING, callback=self.__rfm_irq) @@ -266,7 +268,7 @@ class Rfm69(threading.Thread): self.mode_standby() threading.Thread.__init__(self) - print("Init complete.") + print("Init complete.", file = sys.stderr) def run(self): while True: @@ -429,7 +431,7 @@ class Rfm69(threading.Thread): self.__packet_format = value else: - print("Unrecognized option >>" + key + "<<") + print("Unrecognized option >>" + key + "<<", file=sys.stderr) self.mode_standby() self.__mutex.release()