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

Alway registering from last tap in the array #26

Open
farcouet opened this issue Feb 6, 2021 · 0 comments
Open

Alway registering from last tap in the array #26

farcouet opened this issue Feb 6, 2021 · 0 comments

Comments

@farcouet
Copy link

farcouet commented Feb 6, 2021

Hello,

I have re-installed everything and still each time last tap is registering the pour. So it will always come from tap 5 as I have 5 taps.

I have modified the code as I am not good with python and objects. So it's a bit ugly but it works for 5 taps. So there's something with the GPIO.add_event_detect that refers always to the last object initialized. I tried both in the docker container and running it from the PI outside the docker container.

There is still little things with the toolkit with hardcoded number of tap to 4 but that's an easy fix.

I replaced this:

for tap in self.taps: # setup all the taps. add event triggers to the opening of the taps.

GPIO.add_event_detect(tap.get_pin(), GPIO.RISING, callback=lambda *a: self.register_tap(tap), bouncetime=20)

By this for 5 taps. But it's not really clean and I do not know how to fix previous function.
tap=self.taps[0]
GPIO.add_event_detect(tap.get_pin(), GPIO.RISING, callback=lambda a: self.register_tap(self.taps[0]), bouncetime=20)
tap=self.taps[1]
GPIO.add_event_detect(tap.get_pin(), GPIO.RISING, callback=lambda a: self.register_tap(self.taps[1]), bouncetime=20)
tap=self.taps[2]
GPIO.add_event_detect(tap.get_pin(), GPIO.RISING, callback=lambda a: self.register_tap(self.taps[2]), bouncetime=20)
tap=self.taps[3]
GPIO.add_event_detect(tap.get_pin(), GPIO.RISING, callback=lambda a: self.register_tap(self.taps[3]), bouncetime=20)
tap=self.taps[4]
GPIO.add_event_detect(tap.get_pin(), GPIO.RISING, callback=lambda a: self.register_tap(self.taps[4]), bouncetime=20)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant