Comments (3)
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.
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.
Thanks for the feedback!
The fix will be included in next release
from mopidy-ttsgpio.
Related Issues (9)
- possibility to change playlist? HOT 1
- volume control with potentiometer HOT 1
- AttributeError: <ActorProxy for Core (urn:uuid:b975feb9-a04b-4d1d-9eae-36edd319765c), attr_path=('playlists',)>
- We have no any posibility to regulate the volume of speech. HOT 1
- Stop using internal Mopidy APIs
- Support for lcd HOT 1
- ImportError: No module named pygst HOT 4
- Google is blocking requests
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mopidy-ttsgpio.