maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Design (https://talk.maemo.org/forumdisplay.php?f=46)
-   -   Python - Using Bluetooth/Wired Headset Answer Button (https://talk.maemo.org/showthread.php?t=84827)

biketool 2012-06-11 14:49

Python - Using Bluetooth/Wired Headset Answer Button
 
There is a new app named Saera being developed to provide a voice controlled experience similar to Siri for the Iphone.
For this app to be fully useful to people who need hands free voice interaction with their device the answer button needs to work outside of answering/ending phone calls with both the wired headset and more importantly the Bluetooth headsets much as it does on phones with voice dialing. Most of the work appears to have been done for wired headsets with these packages:
*Headset Button Enabler - enables wired headset to be used outside calls
*Headset Control - uses wired headset to control Media Player

These apps are designed for pausing and starting the media player but need to be accessable to Python which Saera is written in, and more importantly also need to include the more common bluetooth headsets which does not appaer to be the case.

Saera is one of the killer apps car drivers, cyclists, and motorcycle drivers have waited for on Maemo/Meego.

the Saera thread is here http://talk.maemo.org/showthread.php?t=84753

biketool 2012-06-11 15:15

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Checked http://wiki.maemo.org/Phone_control
doesnt seem to currently be any way to get information related to headsets beyond pairing and other standard bluez stuff.

misiak 2012-06-11 15:42

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
According to headset-button-enabler description, when it is installed and a headset button is pressed, "ButtonPressed" signal is emitted by HAL... it should be possible to catch that signal in Python somehow... I cannot help with Python, as my Python skills are weak, but have a look at headset-control package sources, especially at two files: headset-controld.c and headset-control-obj.c. If you understand C language, you will notice this isn't rocket science, and it requires only Python glib, dbus and hal bindings (maybe even one of these is not needed, I skimmed through the code now very quickly while I'm on the train), which, afaik, are all available for Python on Maemo. So, in my oppinion, package headset-control could be used as a reference implementation, if someone has more time, (s)he can write a wiki page basing on this code.

wook_sf 2012-06-11 17:47

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
not quite sure, but maybe os.popen can help?

biketool 2012-06-12 08:36

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by misiak (Post 1220544)
According to headset-button-enabler description, when it is installed and a headset button is pressed, "ButtonPressed" signal is emitted by HAL... it should be possible to catch that signal in Python somehow... .

Thanks I think the scripts control will do it for the wired headset. I dont have my N900 right now as a replacement is in the mail but I am also trying to figure out how the HAL or d-bus handles an answer button from a BT headset when there is not an incoming call. I think if there was a way to mod headset-button-enabler to look for the bluetooth answer instead of from the wired headset it would do the job, my sub-script kiddie skills are really failing me now though.

biketool 2012-06-12 08:39

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by wook_sf (Post 1220606)
not quite sure, but maybe os.popen can help?

Thanks, I am looking at that now, a great lead. The problem is I am waiting for my replacement N900 to arrive and cant experiment. Can you see a answer button press on you BT headset with os.popen without mucking with dbus?

wook_sf 2012-06-13 11:18

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by biketool (Post 1220814)
Thanks, I am looking at that now, a great lead. The problem is I am waiting for my replacement N900 to arrive and cant experiment. Can you see a answer button press on you BT headset with os.popen without mucking with dbus?

unfortunately i don't have BT headset :S nor n900 :D but it should work since i tested some functions like this on n9 and it works.
last night i found struct of input events and library written in python, well...there's not much of ported py libs for harmattan but i am sure python-dev and this scripts can be ported to python easily.
however, you can take needed classes from event.py and input.py and put them into your script.

gionni88 2012-06-13 13:33

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
When wired or bluetooth button is pressed a system dbus signal is emitted. On n900 if I don't remember wrong the wired button is disabled but you may enable it just with an amixer command. You don't need anything else, just to enable the wired button and listen to dbus events.

misiak 2012-06-13 14:01

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by gionni88 (Post 1221343)
When wired or bluetooth button is pressed a system dbus signal is emitted. On n900 if I don't remember wrong the wired button is disabled but you may enable it just with an amixer command. You don't need anything else, just to enable the wired button and listen to dbus events.

So it doesn't matter whether the headset is wired or wireless (bluetooth), the dbus signal will be the same? If yes, I can come up with minimalistic C and Python example for you taxizo, as I have wired headset (but I don't have any wireless, so I'm only able to test with wired one).

edit: This would get more responses if it was posted in "Development" section, not "Design"... Anyway, I'm up for writing a simple example, give me few hours ;)

biketool 2012-06-14 14:52

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by misiak (Post 1221356)
So it doesn't matter whether the headset is wired or wireless (bluetooth), the dbus signal will be the same? If yes, I can come up with minimalistic C and Python example for you taxizo, as I have wired headset (but I don't have any wireless, so I'm only able to test with wired one).

edit:I'm up for writing a simple example, give me few hours ;)

Great, plenty of us really appreciate the work!

misiak 2012-06-14 15:55

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by biketool (Post 1221843)
Great, plenty of us really appreciate the work!

No problem ;) I wanted to do that yesterday but I had planned hildon-desktop blacklisting tests (related to Meecolay development, for marmistrz) earlier and they took me more time than I thought - I will try to code something today, the C language example should be ready, I don't know if I will manage to finish the Python one today, but who knows ;)

biketool 2012-06-20 14:18

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Will this example will only work for the wired headset, or do you also know the output from a bluetooth headset answer button?

misiak 2012-06-20 14:22

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
I have C code which detects wired headset button presses. I need to:
1. Clean it up a bit (it's modified headset-control source)
2. Translate it to Python
3. Find someone to test it with bluetooth headsets.
Do you have bluetooth headset? If you do, you may try to install headset-button-enabler and headset-control from extras-devel and chceck if it works (it should start/stop music in stock media player when button is pressed - try long press, with my cheap wired headset I need to hold the button for 1-2 seconds before it's noticed by the phone)

skykooler 2012-06-20 14:38

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by misiak (Post 1224671)
I have C code which detects wired headset button presses. I need to:
1. Clean it up a bit (it's modified headset-control source)
2. Translate it to Python
3. Find someone to test it with bluetooth headsets.
Do you have bluetooth headset? If you do, you may try to install headset-button-enabler and headset-control from extras-devel and chceck if it works (it should start/stop music in stock media player when button is pressed - try long press, with my cheap wired headset I need to hold the button for 1-2 seconds before it's noticed by the phone)

I have a bluetooth headset I could test this with.

misiak 2012-06-20 14:41

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by skykooler (Post 1224675)
I have a bluetooth headset I could test this with.

Thank you. Could you do:
Code:

sudo gainroot
apt-get install headset-button-enabler headset-control

(if you are using FAM and have extras-devel configured in FAM, you can replace "apt-get" with "fapt-get") and check if it starts/stops music?

biketool 2012-06-20 15:04

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Misiak,
Still waiting for my replacement N900 :)
If I remember right headset-button-enabler headset-control did NOT control mediaplayer with the bluetooth even a one button in-ear unit, definately not with a BH-214.
I have to assume it is a very similar thing and the discovery or use would probably enable patching Skype to answer via BT aswell

marmistrz 2012-06-20 15:48

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by misiak (Post 1224671)
I have C code which detects wired headset button presses. I need to:
1. Clean it up a bit (it's modified headset-control source)
2. Translate it to Python
3. Find someone to test it with bluetooth headsets.
Do you have bluetooth headset? If you do, you may try to install headset-button-enabler and headset-control from extras-devel and chceck if it works (it should start/stop music in stock media player when button is pressed - try long press, with my cheap wired headset I need to hold the button for 1-2 seconds before it's noticed by the phone)

You can try cython, it's a C binding for Python iirc. I came across it while browsing extras-*

trlopes1974 2012-06-20 16:32

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
steped up on this thread...



Ok. Firts of all I have Nokia BH-111 BT headset.
all buttons work fine and control the device (media player - play/pause /next / prev) and phone (accept call & redial)

Doing some tests with dbus-monitor up:
Nokia-N900:~# dbus-monitor --system
signal sender=org.freedesktop.DBus -> dest=:1.529 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
string ":1.529"
signal sender=:1.12 -> dest=(null destination) serial=3995 path=/org/freedesktop/Hal/devices/computer_logicaldev_input_1; interface=org.freedesktop.Hal.Device; member=Condition
string "ButtonPressed"
string "play-cd"
signal sender=:1.48 -> dest=(null destination) serial=751 path=/com/nokia/tklock/signal; interface=com.nokia.tklock.signal; member=mm_key_press
uint32 208
uint32 269025044
signal sender=:1.12 -> dest=(null destination) serial=4032 path=/org/freedesktop/Hal/devices/computer_logicaldev_input_1; interface=org.freedesktop.Hal.Device; member=Condition
string "ButtonPressed"
string "next-song"
signal sender=:1.48 -> dest=(null destination) serial=760 path=/com/nokia/tklock/signal; interface=com.nokia.tklock.signal; member=mm_key_press
uint32 171
uint32 269025047
signal sender=:1.12 -> dest=(null destination) serial=4033 path=/org/freedesktop/Hal/devices/computer_logicaldev_input_1; interface=org.freedesktop.Hal.Device; member=Condition
string "ButtonPressed"
string "previous-song"
signal sender=:1.48 -> dest=(null destination) serial=761 path=/com/nokia/tklock/signal; interface=com.nokia.tklock.signal; member=mm_key_press
uint32 173
uint32 269025046

signal sender=:1.18 -> dest=(null destination) serial=6451 path=/com/nokia/csd/call; interface=com.nokia.csd.Call; member=CreateRequested
string "xxxTELNUMBER010"
uint32 0
signal sender=:1.18 -> dest=(null destination) serial=6452 path=/com/nokia/csd/call; interface=com.nokia.csd.Call; member=ServerStatus
boolean true
boolean false
signal sender=:1.18 -> dest=(null destination) serial=6453 path=/com/nokia/csd/call; interface=com.nokia.csd.Call; member=Created
object path "/com/nokia/csd/call/1"
string "xxxTELNUMBER010"


As you can see, dbus catches button press for headset play button, next and prev buttons.
Unfortunantly, it seems that it's not catching the "redial" or "answer/reject" button or they just dont generate dbus events...

misiak 2012-06-20 17:16

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by trlopes1974 (Post 1224708)
Ok. Firts of all I have Nokia BH-111 BT headset.
all buttons work fine and control the device (media player - play/pause /next / prev) and phone (accept call & redial)

Doing some tests with dbus-monitor up:
Nokia-N900:~# dbus-monitor --system
signal sender=org.freedesktop.DBus -> dest=:1.529 serial=2 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
string ":1.529"
signal sender=:1.12 -> dest=(null destination) serial=3995 path=/org/freedesktop/Hal/devices/computer_logicaldev_input_1; interface=org.freedesktop.Hal.Device; member=Condition
string "ButtonPressed"
string "play-cd"
signal sender=:1.48 -> dest=(null destination) serial=751 path=/com/nokia/tklock/signal; interface=com.nokia.tklock.signal; member=mm_key_press
uint32 208
uint32 269025044
signal sender=:1.12 -> dest=(null destination) serial=4032 path=/org/freedesktop/Hal/devices/computer_logicaldev_input_1; interface=org.freedesktop.Hal.Device; member=Condition
string "ButtonPressed"
string "next-song"
signal sender=:1.48 -> dest=(null destination) serial=760 path=/com/nokia/tklock/signal; interface=com.nokia.tklock.signal; member=mm_key_press
uint32 171
uint32 269025047
signal sender=:1.12 -> dest=(null destination) serial=4033 path=/org/freedesktop/Hal/devices/computer_logicaldev_input_1; interface=org.freedesktop.Hal.Device; member=Condition
string "ButtonPressed"
string "previous-song"
signal sender=:1.48 -> dest=(null destination) serial=761 path=/com/nokia/tklock/signal; interface=com.nokia.tklock.signal; member=mm_key_press
uint32 173
uint32 269025046

signal sender=:1.18 -> dest=(null destination) serial=6451 path=/com/nokia/csd/call; interface=com.nokia.csd.Call; member=CreateRequested
string "xxxTELNUMBER010"
uint32 0
signal sender=:1.18 -> dest=(null destination) serial=6452 path=/com/nokia/csd/call; interface=com.nokia.csd.Call; member=ServerStatus
boolean true
boolean false
signal sender=:1.18 -> dest=(null destination) serial=6453 path=/com/nokia/csd/call; interface=com.nokia.csd.Call; member=Created
object path "/com/nokia/csd/call/1"
string "xxxTELNUMBER010"


As you can see, dbus catches button press for headset play button, next and prev buttons.
Unfortunantly, it seems that it's not catching the "redial" or "answer/reject" button or they just dont generate dbus events...

Man, this log is golden. On my wired one-button headset I get lines similar to
Code:

signal sender=:1.12 -> dest=(null destination) serial=3995 path=/org/freedesktop/Hal/devices/computer_logicaldev_input_1; interface=org.freedesktop.Hal.Device; member=Condition
  string "ButtonPressed"
  string "play-cd"

but the second string (after "ButtonPressed") is always "phone". What hapens if you press button which is used for answering a call (not prev/next/play)? Or it's the same button for playing and for calling?

Edit: if no "ButtonPressed" signal is emited then, could you try installing "headset-button-enabler", reboot device and check if it is emitted then?

trlopes1974 2012-06-22 13:25

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Nokia-N900:~# dpkg -l | grep -i headset
ii headset-button-enabler 0.5 Enable wired headset button to be used outside of phone calls
ii headset-control 0.4 Daemon allowing control of Media Player with the wired headset button
ii maemo-statusmenu-headset 0.18+0m5 Headset status menu plugin

In my previous post:...
Unfortunantly, it seems that it's not catching the "redial" or "answer/reject" button or they just dont generate dbus events...
In this case the "phone" button
Yet, it works. if I press twice the "phone" button, n900 redials the last number. Yet no dbus-event is generated....

thp 2012-06-22 23:13

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Have a look at the MediaButtonsHandler here:

https://github.com/gpodder/gpodder/b...mlui/helper.py

You can even remove all the Qt stuff around it, and just use the "dbus" module (be sure to use a GLib or Qt main loop though, as you are connecting to signals).

HTH :)

biketool 2012-06-23 18:03

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by thp (Post 1225996)
Have a look at the MediaButtonsHandler here:

here is that code:

import dbus
system_bus = dbus.SystemBus()
system_bus.add_signal_receiver(self.handle_button, 'Condition',
'org.freedesktop.Hal.Device', None, headset_path)
if gpodder.ui.harmattan:
system_bus.add_signal_receiver(self.handle_button, 'Condition',
'org.freedesktop.Hal.Device', None, headset_path2)

def handle_button(self, signal, button):
if signal == 'ButtonPressed':
if button in ('play-cd', 'phone'):
self.playPressed.emit()
elif button == 'pause-cd':
self.pausePressed.emit()
elif button == 'previous-song':
self.previousPressed.emit()
elif button == 'next-song':
self.nextPressed.emit()

playPressed = QtCore.Signal()
pausePressed = QtCore.Signal()
previousPressed = QtCore.Signal()
nextPressed = QtCore.Signal()

I think the "Phone" it is talking about though is phone in use not the headset button?

biketool 2012-06-24 18:17

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Misiak
I started this thread in Maemo5 dev http://talk.maemo.org/showthread.php?p=1226840
Hoping it leads to a headset control enabler package similar to the wired headset control but for Bluetooth.
If you had this would it just be left to testing for bugs?
What else do you need?
thanks again!

biketool 2012-06-26 09:31

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Question,
Where does Headset Button Enabler package grab the wired headset signal so it can be sent to dbus? I imagine the bluetooth answer button sends to the same process.

This for the N810 seems obsolete for the N900/Maemo5 but I could be wrong. http://talk.maemo.org/archive/index.php/t-21182.html Still waiting for my N900 so I cant check.

signal sender=:1.0 -> dest=(null destination) path=/com/nokia/osso_hp_ls_controller; interface=com.nokia.osso_hp_ls_controller.headset; member=button_pressed
signal sender=:1.0 -> dest=(null destination) path=/com/nokia/osso_hp_ls_controller; interface=com.nokia.osso_hp_ls_controller.headset; member=button_released

misiak 2012-06-26 10:29

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by biketool (Post 1227554)
Question,
Where does Headset Button Enabler package grab the wired headset signal so it can be sent to dbus? I imagine the bluetooth answer button sends to the same process.

This for the N810 seems obsolete for the N900/Maemo5 but I could be wrong. http://talk.maemo.org/archive/index.php/t-21182.html Still waiting for my N900 so I cant check.

signal sender=:1.0 -> dest=(null destination) path=/com/nokia/osso_hp_ls_controller; interface=com.nokia.osso_hp_ls_controller.headset; member=button_pressed
signal sender=:1.0 -> dest=(null destination) path=/com/nokia/osso_hp_ls_controller; interface=com.nokia.osso_hp_ls_controller.headset; member=button_released

I think that "Headset button enabler" package only changes policies in post-install scripts, it doesn't actually emit any dbus messages. It's "headset control" (for mediaplayer) that has executable "headset-controld" which checks for button press and emits dbus signal. On N900 with only "headset button enabler" package installed, i don't see any messages in dbus when pressing headset button. Only when "headset control" is installed and "headset-controld" is running. So we would need a change in "headset control" package, otherwise there will be conflicts with any other package trying to read button press on headset (e.g. saera will start to listen and, at the same time media player will start to play music).

Thanks for your help :) And sorry for delays, I'm a busy man lately...

biketool 2012-06-26 12:03

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
No worries, we appreciate the work you are doing when you can!
I hope the input and research helps.

gionni88 2012-06-26 16:09

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by gionni88 (Post 1221343)
On n900 if I don't remember wrong the wired button is disabled but you may enable it just with an amixer command. You don't need anything else, just to enable the wired button and listen to dbus events.

From QRadio:

Code:

//To connect to wired headset button:
QDBusConnection::systemBus().connect(QString(),  "/org/freedesktop/Hal/devices/computer_logicaldev_input_1",
                                        "org.freedesktop.Hal.Device",
                                        "Condition",
                                        this, SLOT(headSetButtonPressed()));

//to enable headset button, it's a shell command
amixer -qc0 cset iface=MIXER,name='Jack Bias Switch' on

//to disable:
amixer -qc0 cset iface=MIXER,name='Jack Bias Switch' off

HeadsetButtonEnabler configures your alsa settings to keep the headset working. By default on the N900 NO current goes up to the headset button when outside any call.

biketool 2012-07-08 18:55

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
So it seems that the information is gathered here to build a bluetooth version of HeadsetButtonEnabler for general purpose control of ausio in addition to applications in Saera. Now someone needs to change a few lines of code and rename the package to reflect bluetooth rather than wired headset and compile it to get the bluetooth headset presses to show up in dbus for apps to see?

rakeshyadav 2012-12-14 06:39

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
okay,thank you

misiak 2012-12-14 11:11

Re: Python - Using Bluetooth/Wired Headset Answer Button
 
Quote:

Originally Posted by biketool (Post 1234002)
So it seems that the information is gathered here to build a bluetooth version of HeadsetButtonEnabler for general purpose control of ausio in addition to applications in Saera. Now someone needs to change a few lines of code and rename the package to reflect bluetooth rather than wired headset and compile it to get the bluetooth headset presses to show up in dbus for apps to see?

To enable dbus signals, the deamon should be written which listens to HAL signals and emits dbus signals ;) And I'm not sure if it's just as easy as "someone needs to change a few lines of code and rename the package".


All times are GMT. The time now is 21:24.

vBulletin® Version 3.8.8