Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented distinction between listeners to call via CLK GPIO pin ID #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions micropython_rotary_encoder/rotary_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ def on(self, event: int, callback: callable):
if event not in self._listeners:
self._listeners[event] = []

self._listeners[event].append(callback)
self._listeners[event].append((callback, self.pin_clk))

def off(self, event: int, callback: callable):
if event in self._listeners:
self._listeners[event].remove(callback)
self._listeners[event].remove((callback, self.pin_clk))

def off_all(self, event: int, callback: callable = None):
if event in self._listeners:
if callback is None:
self._listeners[event] = []
else:
while callback in self._listeners[event]:
self._listeners[event].remove(callback)
self._listeners[event].remove((callback, self.pin_clk))

def _sw_irq_handler(self, pin):
timestamp = utime.ticks_ms()
Expand Down Expand Up @@ -275,19 +275,21 @@ def __call_listeners(self):

if __l_e in __list:
for __l in __list[__l_e]:
try:
if __l_e == __m_c_e:
__l(__sw_c)
else:
__l()
except Exception as e:
print(f"RotaryEncoder callback error. Event: {__l_e}, Listener: {__l}, Error: {e}")
if __l[1] == self.pin_clk:
try:
if __l_e == __m_c_e:
__l[0](__sw_c)
else:
__l[0]()
except Exception as e:
print(f"RotaryEncoder callback error. Event: {__l_e}, Listener: {__l}, Error: {e}")
if __e_e in __list:
for __l in __list[__e_e]:
try:
if __l_e == __m_c_e:
__l(__l_e, __sw_c)
else:
__l(__l_e, 0)
except Exception as e:
print(f"RotaryEncoder callback error. Event: {__e_e}, Listener: {__l}, Error: {e}")
if __l[1] == self.pin_clk:
try:
if __l_e == __m_c_e:
__l[0](__l_e, __sw_c)
else:
__l[0](__l_e, 0)
except Exception as e:
print(f"RotaryEncoder callback error. Event: {__e_e}, Listener: {__l}, Error: {e}")