PDA

View Full Version : Use of audio jack buttons



sedi
7th September 2017, 12:45
Hi,
I need an external hardware button to start a function of my app.

Do you have an idea if (or how) Qt is able to detect the pressing of an audio jack button like this one here?
https://www.gearbest.com/cables-adapter/pp_58618.html

Cheers,
Sebastian

high_flyer
7th September 2017, 16:54
Qt can't do that.
Its a hardware driver issue.
Once you have a driver that can deliver system events when the button is pressed, depending on the events type you might catch it with Qt.

sedi
8th September 2017, 22:50
I see what you mean. Shoot. Okay, I think I might be able to solve my (special) use case with an external microphone, being briefly switched on via a hardware button - and an audioInput that waits for a level bigger than a certain threshold to trigger the action. "AudioInput" Qt example seems a good starting point to me. Cumbersome for many use cases, okay for mine. Thank you!

sedi
18th September 2017, 22:45
Ok, I've got it to work. If you wanna do that on a tablet, be aware that you've got to trick the device into believing there's an actual headset. I've done that with two 32 Ohm resistors (R & L to Ground) and a cheap 1$ electret mic capsule like this: 12580


After that, you can use the Qt AudioInput example (https://doc.qt.io/qt-5/qtmultimedia-multimedia-audioinput-example.html) for the detection.
Just check for the audio level in "AudioInput::refreshDisplay()" for starters.

if (m_audioInfo->level() > yourThreshold) { ... }
Consider blocking your detection for a certain amount of time after a trigger impulse, to prevent double/multiple triggering by contact chatter.

Please note that the mic's circuit must be closed when you insert the headset jack into the device. After insertion, you can leave it open (just close it to trigger what you want to trigger), but you need to convince the device of seeing a headset while connecting. This applies to Android at least. On a windows laptop it was enough to just short-circuit the mic input for triggering.

All this is barely a Qt topic after all, but it might help Qt users that come with similar intentions of finding a switch/trigger possibility.