Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
Suppress digital input callback if value did not change
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYsLab committed Apr 15, 2020
1 parent f2283ab commit 9b582b1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
8 changes: 4 additions & 4 deletions html/pymata4/private_constants.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ <h1 class="title">Module <code>pymata4.private_constants</code></h1>
PWM_MESSAGE = 0xE0 # Firmata confusingly conflates analog input with PWM output
REPORT_VERSION = 0xF9 # report protocol version

# start of FirmataPlus defined SYSEX commands
# start of FirmataExpress defined SYSEX commands
KEEP_ALIVE = 0x50 # keep alive message
ARE_YOU_THERE = 0x51 # poll for boards existence
I_AM_HERE = 0x52 # response to poll
Expand Down Expand Up @@ -111,7 +111,7 @@ <h1 class="title">Module <code>pymata4.private_constants</code></h1>
SYSEX_REALTIME = 0x7F # MIDI Reserved for realtime messages

# reserved for PyMata
PYMATA_EXPRESS_THREADED_VERSION = &#34;1.00&#34;
PYMATA_EXPRESS_THREADED_VERSION = &#34;1.01&#34;

# each byte represents a digital port
# and its value contains the current port settings
Expand Down Expand Up @@ -206,7 +206,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
PWM_MESSAGE = 0xE0 # Firmata confusingly conflates analog input with PWM output
REPORT_VERSION = 0xF9 # report protocol version

# start of FirmataPlus defined SYSEX commands
# start of FirmataExpress defined SYSEX commands
KEEP_ALIVE = 0x50 # keep alive message
ARE_YOU_THERE = 0x51 # poll for boards existence
I_AM_HERE = 0x52 # response to poll
Expand Down Expand Up @@ -238,7 +238,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
SYSEX_REALTIME = 0x7F # MIDI Reserved for realtime messages

# reserved for PyMata
PYMATA_EXPRESS_THREADED_VERSION = &#34;1.00&#34;
PYMATA_EXPRESS_THREADED_VERSION = &#34;1.01&#34;

# each byte represents a digital port
# and its value contains the current port settings
Expand Down
2 changes: 1 addition & 1 deletion pymata4/private_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PrivateConstants:
SYSEX_REALTIME = 0x7F # MIDI Reserved for realtime messages

# reserved for PyMata
PYMATA_EXPRESS_THREADED_VERSION = "1.01"
PYMATA_EXPRESS_THREADED_VERSION = "1.02"

# each byte represents a digital port
# and its value contains the current port settings
Expand Down
11 changes: 7 additions & 4 deletions pymata4/pymata4.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,7 @@ def keep_alive(self, period=1, margin=.3):
will physically reset itself.
Frequency of keep alive transmission is calculated as follows:
keep_alive_sent = period - (period * margin)
keep_alive_sent = period - margin
:param period: Time period between keepalives. Range is 0-10 seconds.
0 disables the keepalive mechanism.
Expand Down Expand Up @@ -1347,6 +1346,9 @@ def _digital_message(self, data):
# get pin value
value = port_data & 0x01

# retrieve previous value
last_value = self.digital_pins[pin].current_value

# set the current value in the pin structure
self.digital_pins[pin].current_value = value
time_stamp = time.time()
Expand All @@ -1358,8 +1360,9 @@ def _digital_message(self, data):
else:
message = [PrivateConstants.INPUT, pin, value, time_stamp]

if self.digital_pins[pin].cb:
self.digital_pins[pin].cb(message)
if last_value != value:
if self.digital_pins[pin].cb:
self.digital_pins[pin].cb(message)

port_data >>= 1

Expand Down
2 changes: 1 addition & 1 deletion pypi_desc.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Pymata4 is a Firmata client that, like its asyncio sibling,
* **Piezo Tone Generation.**
* **Baud rate of 115200**

<h2><u>Major features</u></h2>
### Major features

* **Fully documented <a href="https://htmlpreview.github.com/?https://github.com/MrYsLab/pymata4/blob/master/html/pymata4/index.html" target="_blank">intuitive API</a>**

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
packages=['pymata4'],
install_requires=['pyserial'],

version='1.01',
version='1.02',
description="A Python Protocol Abstraction Library For Arduino Firmata",
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 9b582b1

Please sign in to comment.