M1cha / android_device_xiaomi_aries

Xiaomi MI2
24 stars 25 forks source link

Wired headset buttons cause no reaction. #5

Closed Giangiva closed 9 years ago

Giangiva commented 10 years ago

I have a Mi2S 32GB bought directly from xiaomi. I also own a wired headset from xiaomi as well, which is working fine with the MIUI rom (ok, it's not the best, but it's working... :-) ) When plugged in the phone using this rom, I can hear the sound through it, but pressing the buttons has no effect. I even tried watching the logcat, but I couldn't notice any change in it when pressing the buttons on the headset.

M1cha commented 10 years ago

This seems to be the device: I/InputReader( 568): Device added: id=3, name='apq8064-tabla-snd-card Headset Jack', sources=0x80000000

I think we need to create "apq8064-tabla-snd-card_Headset_Jack.kl" but I don't know the keycodes for this device and I don't know how to find them, too. Any idea?

Giangiva commented 10 years ago

I have installed the cm 10.2 4.3.1 made by cofface in my system2: do you think I can get those keycodes using that rom? Or, since your kernel is different, also the keycodes will be different? btw, is this a problem only on my phone (Mi2S) or do you see it in your one too (you own a Mi2, don't you)? Another idea: since the device seems to be created, can't we read its events from any place in /proc or in /sys?

M1cha commented 10 years ago

I don't know if that works but you could try to get the keycodes via CWM. advanced -> key test

Giangiva commented 10 years ago

I tried it, but I got no reaction... :-( The only code I got is the one for the 'back' key that I pressed to get out of the key test.

M1cha commented 10 years ago

Does this app show the keycodes? https://github.com/chrisboyle/keytest/downloads

Giangiva commented 10 years ago

Unfortunately, not. I can see other buttons with it: menu, back, but nothing happens when I press the keys on the headset.

ghost commented 10 years ago

I have Klipsch earphones (w/ microphone and single button), which work fully on Miui w/ MI2S 32GB.

The "key test.apk" does not register any key press for the earphones button, while CWM reports ScanCode 256.

Just for the information of those interested: from the view point of plug wiring, MI2 seems compatible with iPhone with the only difference that volume +/- buttons (if exist) do not work on Android. This is IMHO true for any recent Android devices (e.g. last "smart" Samsung with the old "nokia" style was SGS i9000). There are available simple adapters, which switch the mic & ground. The two existing "standards" are shown at the attached picture. zs-1

ghost commented 10 years ago

Ivan's ROM (see the other issue #6 ) reads the Scan Code as 226. ivan_button

Giangiva commented 10 years ago

Hi M1cha,

today, with the 3/12/2013 release, I tried again the wired headset: no luck. Then I tried with the key test in the cwm recovery: success! The "play" button is code 256 The "forward" button is code 257 The "rewind" button is code 258 Given that, now, the system seems to be able to read the keys, how can I "convince" the apps to do something with these keys?

Vosje commented 10 years ago

Hi Guys,

I have the same problem, am using an IPhone headset. During Phone calls the mic doesn't work. I can hear the otter person, they can't hear me

M1cha commented 10 years ago

Vosje: that's a different problem and has nothing to do with this issue.

Vosje commented 10 years ago

Ok sorry, I'll make a new post for this one then.

Vosje commented 10 years ago

I’ve tested this, the internal mic doesn’t work when I connect my headset

Van: M1cha [mailto:notifications@github.com] Verzonden: donderdag 12 december 2013 11:02 Aan: M1cha/android_device_xiaomi_aries CC: Vosje Onderwerp: Re: [android_device_xiaomi_aries] Wired headset buttons cause no reaction. (#5)

Vosje: that's a different problem and has nothing to do with this issue.

— Reply to this email directly or view it on GitHub https://github.com/M1cha/android_device_xiaomi_aries/issues/5#issuecomment-30403133 . https://github.com/notifications/beacon/LpC5HU4AhD5GXAfa-5Ysuz7r-G5u1avzgNC0YB9dULC46TN-ROemz8tSyiWdcNwX.gif

M1cha commented 10 years ago

does that work? http://d-h.st/Fw5

ghost commented 10 years ago

Nope. Flashed it and cannot see any change. No reaction, Key Test apk does not notice the presses either.

DaRoni commented 10 years ago

the same problem with headphones on mi2, headphones from xiaomi http://www.ebay.com/itm/New-Xiaomi-PISTON-Earphones-Headset-Headphones-w-wire-control-for-MI2-MI2A-MI2S-/290950250173 upd1 keycode_test-signed.zip did not help upd2 here can be help with the problem. https://www.dropbox.com/s/jrczribp3745hbh/2013-12-17_183806_logcat.txt https://www.dropbox.com/s/k563o4lay0e0pyv/2013-12-17_183817_dmesg.txt https://www.dropbox.com/s/eq1b3bbcw9ogms6/2013-12-17_183826_bugreport.txt

M1cha commented 10 years ago

can u confirm that this is fixed in latest build from linuxx?

jrizzoli commented 10 years ago

I don't have buttons on my headset, so I can't try, but if it should works if m1cha pushed the commit before 18-01-14 22:30 (GMT+1)

DaRoni commented 10 years ago

Works only increase the volume button. Play button and decrease the volume button does not work. flashed cm-11-20140118-UNOFFICIAL-ARIS + pa_gapps-modular-full-4.4.2-20140117-signed, checked with Apollo.

M1cha commented 10 years ago

dump the keycodes in CWM, and check with input test apps if the buttons are at least recognized

DaRoni commented 10 years ago

same as before The "play" button is code 256 The "forward" button is code 257 The "rewind" button is code 258

M1cha commented 10 years ago

ah ok that's the reason. u don't have play, vol+ and vol- u have play, forward,rewind

M1cha commented 10 years ago

ah and btw please ceck the keycodes with the app I've posted above. CWM uses 4.1 kernel and shows different keycodes

ghost commented 10 years ago

Just for those interested: it appears that "vol +" and "vol -" on Apple headset use different resistance (Ohm) values than "rewind" and "forward" on some Android headsets. And what may work on one Android, may not necessarily work on another Android.

I wonder, if the driver/hw in Mi2 can catch all the "key presses" of various headsets or just some. (I have only a single button headset, however.)

At least Play/Pause button seems to be the same accross platforms.

http://www.instructables.com/id/Galaxy-Nexus-and-others-headset-remote-with-medi/

DaRoni commented 10 years ago

V+ https://www.dropbox.com/s/64lzhx2vgo54iib/22012014086.JPG play https://www.dropbox.com/s/nkalzsdu5ccerzu/22012014087.JPG V- no reaction https://www.dropbox.com/s/0bovsmku7398d5a/22012014088.JPG

ghost commented 10 years ago

On CM @ 2014-01-25: I was surprised, that presses of the single button on my headset generates different scanCodes in Keytest.apkg, namely 256, 257, 258, 263. Quite randomly, without a clear pattern. scanCode 263 maps to Keycode 25 (volume down), scanCode 257 maps to Keycode 79 (headsethook), while the others are not mapped to any Keycode. I have shot a screen cast, if needed.

On ivan's ROM [1], the presses of the button alwaysgenerate the same scanCode 226 (which is mapped to Key code 79.

http://xiaomi.eu/community/threads/aosp-4-4-kitkat-rom-aosp-by-ivan.22682/page-10#post-195465

Could it be a driver issue?

Edit1: the same headset (Klipsch) behaves the same on another Mi2S phone with M1cha's CM11. A different headset (iFrogz audio) generates just a single scanCode 256 on the same ROM.

ghost commented 10 years ago

@M1cha: how about opening a thread at xiaomi.eu to find out what scanCodes exist for various users with current release of your CM11?

For myself, I am just fine to edit apq8064-tabla-snd-card_Headset_Jack.kl after flashing CM11, but resolving the bug might be a bit better ;-)

LobsterJohnson commented 10 years ago

Here is what I got with my philips uptown using the play/answer button with CM11 by cofface:

Keycode:79 KeyEvent: KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_HEADSETHOOK, scanCode=226, metaState=0, flags=0x8, repeat=226, metaState=0, flags=0x8, repeatCount=0, eventTime71612207, downTime=71612207, deviceld=3, source0x101

shivwolf commented 10 years ago

Same problem. Me on mi2s with dual boot: On cyanogenmod 11-20140619-nightly-aries:

Got the m1cha recovery. Can I test something to you?

shivwolf commented 10 years ago

Same problem. Me on mi2s with dual boot: On cyanogenmod 11-20140619-nightly-aries: Volume + works as - Play works ok Volume - don't works On miui v5 works fine.

Got the m1cha recovery. Can I test something to you?

disparil commented 10 years ago

Same problem here Me on Mi2 with WIUI v5 KK 4.4.4 (based on CM11)

Volume + works as - Play works ok Volume - don't works

JustAMan commented 9 years ago

I have Xiaomi Gold Pistons (headset with 3 buttons) and Xiaomi MiKey (in-jack button), both don't work correctly in CM11 (but work okay in stock MIUI, so hardware is okay).

No buttons seem to work (not even play/pause button on the headset, at least it won't control Apollo player).

I tried testing buttons in the CWM I have (some 6.0.x I believe), and it detects play and some volume (up or down - don't remember), but doesn't detect neither other volume button nor MiKey presses.

I'm using CM11 m8 snapshot.

How can I debug this thing? :)

P.S. Tried KeyTest app - it, too, detects volume up and play/pause presses (though it says "keyCode=KEYCODE_UNKNOWN" for both), scan code for volume up is 262, for play is 256.

JustAMan commented 9 years ago

I think I see why Xiaomi headset buttons don't work - they use different resistance values for buttons compared to what the kernel in @M1cha build expects.

I've compared "sound/soc/msm/apq8064.c" in kernel source between @M1cha version and official (at least that's what I found) version from Xiaomi (https://github.com/MiCode/mi2_kernel), and they differ in the function that I understand as setting button resistances: at

static void *def_tabla_mbhc_cal(void)

somewhere in its code there is this:

Xiaomi M1cha
btn_low[0] = -75; btn_low[0] = -50;
btn_high[0] = 150; btn_high[0] = 10;
btn_low[1] = 151; btn_low[1] = 11;
btn_high[1] = 330; btn_high[1] = 52;
btn_low[2] = 331; btn_low[2] = 53;
btn_high[2] = 655; btn_high[2] = 94;
btn_low[3] = 21; btn_low[3] = 95;
btn_high[3] = 62; btn_high[3] = 133;
btn_low[4] = 154; btn_low[4] = 134;
btn_high[4] = 181; btn_high[4] = 171;
btn_low[5] = 182; btn_low[5] = 172;
btn_high[5] = 218; btn_high[5] = 208;
btn_low[6] = 219; btn_low[6] = 209;
btn_high[6] = 254; btn_high[6] = 244;
btn_low[7] = 63; btn_low[7] = 245;
btn_high[7] = 104; btn_high[7] = 330;

I think I may try to compile my own fork of @M1cha kernel with those lines taken from Xiaomi to fix Xiaomi headset buttons.

JustAMan commented 9 years ago

I've fixed (at least on my device) both Xiaomi Pistons (gold, v.2) and MiKey with CM11 m8. I had to re-compile the kernel (with some changes) and to change keylayout file.

Pull requests are: https://github.com/M1cha/android_kernel_xiaomi_aries/pull/2 https://github.com/M1cha/android_device_xiaomi_aries/pull/62

JustAMan commented 9 years ago

If anyone is using CM11 m8 stable release - here's CWM-flashable patch that fixes MiKey and Xiaomi Pistons https://github.com/JustAMan/android_kernel_xiaomi_aries/releases/download/pistons-mikey-fixed/cm11-pistons-mikey-fix.zip

At least on my Mi2S it works perfectly after that. Give it a try and let me know if it fails.

shivwolf commented 9 years ago

Thank you JustAMan, i´ll try it this evening and comment here. Is it just a patch? Or is a complete recovery for pistons & mikey?

JustAMan commented 9 years ago

It's new kernel (based on latest cm-11 version from M1cha repos) which fixes buttons on the headset and MiKey (at least on my device).

It should be applied via CWM just like any other update package - via "install zip from sdcard" menu.

shivwolf commented 9 years ago

Perfect, I´ll give a try!

shivwolf commented 9 years ago

Works fine on my mi2s (32GB) Cm11 snapshot + Cwm recovery(m1cha)

A lot of thanks JustAMan & Co.

jrizzoli commented 9 years ago

Can I commit this to cm for u? (I'll give u credits ofc)

Sent from my Xiaomi Mi 2S On Sep 8, 2014 5:42 PM, "shivwolf" notifications@github.com wrote:

Works fine on my mi2s (32GB) Cm11 snapshot + Cwm recovery(m1cha)

A lot of thanks JustAMan & Co.

— Reply to this email directly or view it on GitHub https://github.com/M1cha/android_device_xiaomi_aries/issues/5#issuecomment-54840021 .

M1cha commented 9 years ago

It has been merged to CM already.

jrizzoli commented 9 years ago

Better :P

2014-09-08 17:47 GMT+02:00 M1cha notifications@github.com:

It has been merged to CM already.

— Reply to this email directly or view it on GitHub https://github.com/M1cha/android_device_xiaomi_aries/issues/5#issuecomment-54840731 .

archont00 commented 9 years ago

Hello guys, the new values for btn_[high|low] have an affect on scan codes.

My earbuds report various scan codes for a single button press - IMHO the precision of Mi2s is better than the precision of resistors in the earbuds. I can simply assign the same Key Code to the various Scan Codes in "apq8064...Button_Jack.kl" config file to resolve the problem for myself, though it would be better to have the "bigger" config file available for everyone.

This is a good solution as long as the reported scan codes do not overlap with Volume Up/Down of other earbuds.

To check if there is an overlap or not, I would appreciate if you can report again the Scan Codes for your earbuds.

After installing the patched kernel (or at least CM nightly 2014-09-09), will you please run the Key Test app and report:

Earbud name
Button   ScanCode
-----------------------------------------------------
Klipsch for Android with microphone
Play/Pause  256 (most often), 257 , 258, 263 (rarely)

Apple earbuds with microphone
Play/Pause   256
Volume Up  - ignored
Volume Down - ignored

The Volume Up/Down being ignored is expected behaviour, since Apple uses a different technology for these buttons (probably capacitators instead of resistors).

Thnx a lot!

shivwolf commented 9 years ago

Earbud: Xiaomi Piston

Keytest inside recovery(m1cha): up - 263 down - ignored play - 257

keytest.apk in CM 11 + JustAMan patch: up - 24 down - 25 play - 79

keytest.apk in miui up - 24 down - 25 play - 79

JustAMan commented 9 years ago

@milankni Play/pause button should be as easy as making 0 resistance, so it should always be scan code 256.

I can provide you a "debug" kernel which dumps measured voltage in dmesg, and we can try to see if specific values need to be tuned.

archont00 commented 9 years ago

@JustAMan You are about right, however on xda it is mentioned that the resistor value for pressed play/pause button is not neccessarily close to 0 Ohm (short-circuit), E.g. Samsung earbuds have slightly higher resistence.

http://forum.xda-developers.com/showpost.php?p=34185923&postcount=24

My Klipsch earbuds may have a buggy button (worn out?) leading to some inconsistent values and now I guess a workaround of assigning mutliple scanCodes to a single Key Code should not be pushed upstream. Anyway, if you are so kind and provide me with the debug kernel, I would be happy to see the voltages. (I assume there is not a direct correlation between voltage/resistence and scanCodes. I will try to look into the code if I can find the mapping).

M1cha commented 9 years ago

@milankni does you have different scancodes in MIUI, too? It could be a kernel bug.

JustAMan commented 9 years ago

@milankni Here you go: https://github.com/JustAMan/android_kernel_xiaomi_aries/releases/download/pistons-mikey-fixed/cm11-debug-buttons.zip

You just flash it with CWM, boot your phone, wait till it finishes booting, plug your headset and press some buttons. Then with "adb shell su -c dmesg >dmesg.txt" you get dmesg and search for "mv=" string there, it would be some voltage measurements made by the kernel (either when you plug something - it measures voltage to understand what you've plugged, or when you press a button).

shivwolf commented 9 years ago

Im trying to test things for u guys, but isn´t working too well.

I´ve installed the test program by JustAMan, entered the console and when I wrote the line, I get the message: "can´t create dmesg.txt :Read-only file system"

I´d tried adb shell su -c dmesg >/mnt/sdcard/prueba.txt and this responses: Error: device not found. But this time I get the "prueba.txt" file, but inside, only appears daemon not running.starting it now on port 5038 * *daemon started succesfully

Any tip?

M1cha commented 9 years ago

adb is used to establish a connection with a android device. Since you're using terminal emulator you don't need that connection. Just remove the "adb shell" part of your command.