Git Product home page Git Product logo

Comments (7)

TeeVau avatar TeeVau commented on August 30, 2024

Hey,
I also noticed the same behavior. It looks like the debounce configuration is not working.

from octoprint-gpioshutdown.

ke9g avatar ke9g commented on August 30, 2024

I REALLY like the idea of this plug in. Hopefully you will have some time to address these last few need!

from octoprint-gpioshutdown.

TeeVau avatar TeeVau commented on August 30, 2024

I've found out the the "bouncetime" parameter in method add_event_detect is not working as we expexting.
It just ment that a bouncing switch does not fire the callback routine multiple times, nut just one time.
It's not used as a "hold" time. But it seems to be that there is one attemp to realise a "hold" time. But for me it looks like that this can't work.
Maybe @fmalekpour can explain how it should be used?

from octoprint-gpioshutdown.

ke9g avatar ke9g commented on August 30, 2024

Here is an update on my debounce comment. I don't understand Python, so I can't help you directly with your code. But I do understand debounce logic so I will explain here what I think your code should be doing. I hope this helps!

I will assume the GPIO pin is "HIGH" at all normal times (pulled high with resistor) and then "LOW" when the shutdown switch is pressed.

here is a suggested logic sequence:

  1. Check to see if the printer is printing. If it is, then skip all the code below. If it is idle, then proceed to step #2
  2. Check the GPIO pin. If it is 'high', skip the rest of the code below. If the pin is low, proceed to step #3
  3. Sleep for the debounce period and then check the GPIO pin again. If the pin is 'high' then skip the rest of the code below. If the pin is still 'low', continue to step #4. This is the debounce action, and it makes sure the switch is being held down and there isn't noise on the pin. I suggest a debounce period of about 500 milliseconds. Or for even better redundancy, check the switch 10 times in a row with a 50 ms sleep time, making sure the switch is always low every time.
  4. execute the shutdown commands

Good luck!

from octoprint-gpioshutdown.

TeeVau avatar TeeVau commented on August 30, 2024

Hi there,

What is debouncing and how it can be implemented is basically clear to me. I don't know why the current implementation is so "strange". I would like some feedback from the developer so that I can understand the background.
Does this have a certain meaning that I or we don't recognize, or did the implementation "slip in" and just work for the application?

The current function is the following:
With a rising AND falling edge, the callback function is called IMMEDIATELY. The first edge triggers the callback function immediately. Debouncing only avoids calling the function again. However, the function is called directly with a rising edge and not only after the debounce time.
When the callback function is called, the shutdown is carried out, regardless of the state of the GPIO.

What we both want is a hold time, in addition to debouncing:
Shut down only when the GPIO is held for 2000ms.
I want that e.g. use as a safety function so that the Pi does not shut down if I accidentally press the button briefly.

This is the functional sequence when I press the button and keep it pressed, always with 3000ms debounce time):
------> PRESS
2021-01-06 21: 05: 19,027 - octoprint.plugins.GPIOShutdown - INFO - START callback
2021-01-06 21: 05: 22,033 - octoprint.plugins.GPIOShutdown - INFO - SLEEP finished
2021-01-06 21: 05: 22,035 - octoprint.plugins.GPIOShutdown - INFO - Sensor triggered!
2021-01-06 21: 05: 22,037 - octoprint.plugins.GPIOShutdown - INFO - sudo shutdown -h now
2021-01-06 21: 05: 22,039 - octoprint.plugins.GPIOShutdown - INFO - sudo shutdown -h now
2021-01-06 21: 05: 22,040 - octoprint.plugins.GPIOShutdown - INFO - START callback
2021-01-06 21: 05: 25,053 - octoprint.plugins.GPIOShutdown - INFO - SLEEP finished
2021-01-06 21: 05: 25,055 - octoprint.plugins.GPIOShutdown - INFO - RETURN callback

When I release the button:
------> RELEASE
2021-01-06 21: 05: 47,266 - octoprint.plugins.GPIOShutdown - INFO - START callback
2021-01-06 21: 05: 50,271 - octoprint.plugins.GPIOShutdown - INFO - SLEEP finished
2021-01-06 21: 05: 50,272 - octoprint.plugins.GPIOShutdown - INFO - RETURN callback
2021-01-06 21: 05: 50,274 - octoprint.plugins.GPIOShutdown - INFO - START callback
2021-01-06 21: 05: 53,279 - octoprint.plugins.GPIOShutdown - INFO - SLEEP finished
2021-01-06 21: 05: 53,281 - octoprint.plugins.GPIOShutdown - INFO - RETURN callback

This is the functional sequence if I only press the button briefly:
2021-01-06 21: 08: 24,983 - octoprint.plugins.GPIOShutdown - INFO - START callback
2021-01-06 21: 08: 27,997 - octoprint.plugins.GPIOShutdown - INFO - SLEEP finished
2021-01-06 21: 08: 27,999 - octoprint.plugins.GPIOShutdown - INFO - Sensor triggered!
2021-01-06 21: 08: 28,002 - octoprint.plugins.GPIOShutdown - INFO - sudo shutdown -h now
2021-01-06 21: 08: 28,004 - octoprint.plugins.GPIOShutdown - INFO - sudo shutdown -h now
2021-01-06 21: 08: 28,006 - octoprint.plugins.GPIOShutdown - INFO - START callback
2021-01-06 21: 08: 31,012 - octoprint.plugins.GPIOShutdown - INFO - SLEEP finished
2021-01-06 21: 08: 31,013 - octoprint.plugins.GPIOShutdown - INFO - RETURN callback

What I want to implement is:
------> Short push (lower than the debounce time)
octoprint.plugins.GPIOShutdown - INFO - START callback
octoprint.plugins.GPIOShutdown - INFO - SLEEP finished
octoprint.plugins.GPIOShutdown - INFO - No shutdown due to no active input after debounce time

------> Long push (Higher than the debounce time)
octoprint.plugins.GPIOShutdown - INFO - START callback
octoprint.plugins.GPIOShutdown - INFO - SLEEP finished
octoprint.plugins.GPIOShutdown - INFO - Shutdown due to active input after debounce time
octoprint.plugins.GPIOShutdown - INFO - sudo shutdown -h now

I'll take that as a task and try to implement it in a fork. Maybe the pull request will be accepted.

from octoprint-gpioshutdown.

TeeVau avatar TeeVau commented on August 30, 2024

Hey,
I've added a poor solution. But I guess it will work for the most out there ;-)

Give it a try!

from octoprint-gpioshutdown.

TeeVau avatar TeeVau commented on August 30, 2024

Found a typo and fixed it with #24

from octoprint-gpioshutdown.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.