Git Product home page Git Product logo

Comments (3)

 avatar commented on June 24, 2024

Please next time use this for commenting code as in python indentation is essential:

Your code

This is how I am interpreting your code (Tell me if I am interpreting wrong):

longpress_time = 1
longpress_time2 = 5

def vol_down(self, channel):
    if GPIO.input(channel) == 1:
        if self.down_time_vol_down + longpress_time > time.time():
            self.frontend.input({'key': 'volume_down', 'long': False})
        elif self.down_time_vol_down + longpress_time2 > time.time():
            self.frontend.input({'key': 'volume_down', 'long': True})
    else:
        self.down_time_vol_down = time.time()

I am not able to reproduce the error as I am using a powered USB hub. Without the hub the pi reboots when I insert a USB.

So to be sure if I understood this correctly. The problem is that when you plug a USB, GPIO value changes so fast that GPIO.input(channel) is never 0 and down_time is not updated. So as the down time is a old value longpress is triggered.

To fix that your idea is that it should be a max time (5 seconds in your example) for a button press and that we should ignore that press as it will probably be a false positive.

Another fix I think of could be to check if the time has been updated:

def vol_down(self, channel):
    if GPIO.input(channel) == 1:
        if self.down_time_vol_down >= 0:
            if self.down_time_vol_down + longpress_time > time.time():
                self.frontend.input({'key': 'volume_down', 'long': False})
            else:
                self.frontend.input({'key': 'volume_down', 'long': True})
        self.down_time_vol_down = -1
    else:
        self.down_time_vol_down = time.time()

Please try this code and reply if it fixes or not.

Thanks for your help in making mopidy-ttspio better!

from mopidy-ttsgpio.

shuricksumy avatar shuricksumy commented on June 24, 2024

Hi,
you interpreted correctly my code. I checked your code. It worked good. But when we start mopidy the variables are declared with value = 0. And we get fake pressed buttons only one time. So we should use next:

    self.down_time_previous = -1
    self.down_time_next = -1
    self.down_time_main = -1
    self.down_time_vol_up = -1
    self.down_time_vol_down = -1

Thanks for your help too.

from mopidy-ttsgpio.

 avatar commented on June 24, 2024

Thanks for the feedback!

The fix will be included in next release

from mopidy-ttsgpio.

Related Issues (9)

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.