From 18b404abd7ab4885ddd10fe823eef9369b32428c Mon Sep 17 00:00:00 2001 From: Bernd Porr Date: Thu, 26 Nov 2020 19:10:08 +0000 Subject: [PATCH] Made the evil pass_time function private. --- examples/blink.py | 11 ++++++----- examples/digital-in.py | 4 ++-- examples/realtime_scope.py | 2 +- pyfirmata2/pyfirmata2.py | 6 +++--- setup.py | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/examples/blink.py b/examples/blink.py index b256e6d0..9dc9489b 100755 --- a/examples/blink.py +++ b/examples/blink.py @@ -32,12 +32,13 @@ # The "Hello World" demo how to change a digital port synchronously. # # Warning: this is just an example of how to accesss the digital ports. -# For precise timing please use timers and not the pass_time command -# which locks up processing and is not precise. +# For precise timing please use timers or callback handlers +# and not the sleep() command which locks up processing +# and is not precise. # import pyfirmata2 - +import time PIN = 13 # Pin 13 is used DELAY = 1 # 1 second delay @@ -53,6 +54,6 @@ # Loop for blinking the led while True: board.digital[PIN].write(1) # Set the LED pin to 1 (HIGH) - board.pass_time(DELAY) + time.sleep(1) board.digital[PIN].write(0) # Set the LED pin to 0 (LOW) - board.pass_time(DELAY) + time.sleep(1) diff --git a/examples/digital-in.py b/examples/digital-in.py index fe4bbf7c..ea3cc1fd 100755 --- a/examples/digital-in.py +++ b/examples/digital-in.py @@ -32,7 +32,7 @@ # delay opertation. import pyfirmata2 - +import time # Adjust that the port match your system, see samples below: # On Linux: /dev/tty.usbserial-A6008rIF, /dev/ttyACM0, @@ -57,6 +57,6 @@ print("Button not pressed") else: print("Button has never been pressed") - board.pass_time(0.5) + time.sleep(0.1) board.exit() diff --git a/examples/realtime_scope.py b/examples/realtime_scope.py index 6a8b0d22..f6876a2f 100755 --- a/examples/realtime_scope.py +++ b/examples/realtime_scope.py @@ -26,7 +26,7 @@ def __init__(self): # create an empty line self.line, = self.ax.plot(self.plotbuffer) # axis - self.ax.set_ylim(0, 1) + self.ax.set_ylim(0, 1.5) # That's our ringbuffer which accumluates the samples # It's emptied every time when the plot window below # does a repaint diff --git a/pyfirmata2/pyfirmata2.py b/pyfirmata2/pyfirmata2.py index d2b3dab1..25306048 100755 --- a/pyfirmata2/pyfirmata2.py +++ b/pyfirmata2/pyfirmata2.py @@ -119,7 +119,7 @@ def __init__(self, port, layout=None, baudrate=57600, name=None, timeout=None): # Alas, Firmata blinks its version before printing it to serial # For 2.3, even 5 seconds might not be enough. # TODO Find a more reliable way to wait until the board is ready - self.pass_time(BOARD_SETUP_WAIT_TIME) + self.__pass_time(BOARD_SETUP_WAIT_TIME) self.name = name self._layout = layout if not self.name: @@ -213,7 +213,7 @@ def auto_setup(self): """ self.add_cmd_handler(CAPABILITY_RESPONSE, self._handle_report_capability_response) self.send_sysex(CAPABILITY_QUERY, []) - self.pass_time(0.1) # Serial SYNC + self.__pass_time(0.1) # Serial SYNC while self.bytes_available(): self.iterate() @@ -282,7 +282,7 @@ def get_pin(self, pin_def): pin.enable_reporting() return pin - def pass_time(self, t): + def __pass_time(self, t): """Non-blocking time-out for ``t`` seconds.""" cont = time.time() + t while time.time() < cont: diff --git a/setup.py b/setup.py index 163ee78f..ce70bdbe 100755 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setup( name='pyFirmata2', - version='2.0.1', + version='2.1.0', description="Use your Arduino as a data acquisition card under Python", long_description=long_description, author='Bernd Porr',