Skip to content

Commit

Permalink
Added disable_reporting() on exit
Browse files Browse the repository at this point in the history
This has been suggested by @kdickie59 in
#14
I cannot test it as it's fine on my RPI3 with the Uno
but hopfully helps!
  • Loading branch information
berndporr committed Feb 23, 2024
1 parent 2e12ee6 commit d0a41a3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion examples/print_analog_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def myPrintCallback(self, data):
self.timestamp += (1 / self.samplingRate)

def stop(self):
self.board.samplingOff()
self.board.exit()

print("Let's print data from Arduino's analogue pins for 10secs.")
Expand Down
10 changes: 9 additions & 1 deletion pyfirmata2/pyfirmata2.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,12 @@ def setSamplingInterval(self, intervalInMs):

def exit(self):
"""Call this to exit cleanly."""
# First detach all servo's, otherwise it somehow doesn't want to close...
for a in self.analog:
a.disable_reporting()
for d in self.digital:
d.disable_reporting()
self.samplingOff()
# First detach all servo's, otherwise it somehow doesn't want to close...
if hasattr(self, 'digital'):
for pin in self.digital:
if pin.mode == SERVO:
Expand Down Expand Up @@ -472,6 +476,8 @@ def enable_reporting(self):

def disable_reporting(self):
"""Disable the reporting of the port."""
if not self.reporting:
return
self.reporting = False
msg = bytearray([REPORT_DIGITAL + self.port_number, 0])
self.board.sp.write(msg)
Expand Down Expand Up @@ -564,6 +570,8 @@ def enable_reporting(self):
def disable_reporting(self):
"""Disable the reporting of an input pin."""
if self.type == ANALOG:
if not self.reporting:
return
self.reporting = False
msg = bytearray([REPORT_ANALOG + self.pin_number, 0])
self.board.sp.write(msg)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='pyFirmata2',
version='2.4.5',
version='2.4.6',
description="Use your Arduino as a data acquisition card under Python",
long_description=long_description,
author='Bernd Porr',
Expand Down

0 comments on commit d0a41a3

Please sign in to comment.