sábado, 2 de novembro de 2013

Using ANT+ USB Sticks with Endomondo on Android

I needed to use my Garmin ANT+ HR Monitor with Endomondo PRO on Nexus 4 running a Suunto ANT+ USB stick with a externally powered USB OTG adapter (DIY). 

Don't understand why, but Endomondo won't support latest ANT+ API, so USB Sticks won't work, only devices which has the chip embedded as most of the high end Xperia, Galaxy S4 (on 4.3), etc...

The solution? Modify the Endomondo PRO apk so that it starts supporting it. As it's a really simple change, don't understand why it wasn't done before.
Hope these steps help someone else out, as I spend more time looking for a solution than doing the mod itself.


Disclaimer:
This requires some knowledge.   I'm assuming you know your way around in sideloading apps on Android, using command line in Linux or Windows and with a code editor.

Prerequisites:
  • Endomondo PRO (or regular) APK. You can't extract the PRO from your phone as it's a paid app, so get it online or get it straight from Play Store with the Chrome Extension APK Downloader: http://codekiem.com/2012/02/24/apk-downloader/
  • smali / baksmali decompiler : http://code.google.com/p/smali/ (you'll need java installed and properly configured)
  • A code editor in case you're using windows, as Notepad++ (for me in Linux, regular Gedit did fine)
  • I RECOMMEND doing this on linux. Install Ubuntu on a virtual machine using Virtuabox on your Windows and be happy. 
Intructions:

1) Open the .apk in an archiver program like WinRar, 7z, whatever, and extract the classes.dex file.

2) Decompile classes.dex file with the command baksmali classes.dex
It'll create a new folder "out" with a lot of files.

3) Open com/dsi/ant/Antinterface.smali in your code/text editor
Use Ctrl+F and search for ".line 1331"
Look for:

.line 1331 
:cond_1e 
sget-boolean v0, Lcom/dsi/ant/AntInterface;->mAntSupported:Z

4) replace: sget-boolean v0, Lcom/dsi/ant/AntInterface;->mAntSupported:Z
with: const/4 v0, 0x1

5) Recompile using smali out classes.dex

6) Open the apk in the archiver again and delete classes.dex. Copy the new classes.dex into the archive.

7) Copy the apk back to your phone

8) Resign the apk. I used ZipSigner. You can get it from the Google Play Store.

9) Make sure you uninstall the original app, then install from the modified apk.

10) Restart your phone.

11) Make sure the dongle is plugged in before you start the app.

Troubleshooting:

It took me some attempts before Endomondo saw the HR monitor when I scanned for it, so don't give up easy!
I used the ANT+ Demo app and the Heart Rate Graph to make sure the Stick was working before getting Endomondo to recognize it.
When you leave any of them running and connected to the stick and do the device search in Endomondo, you'll get a notification about Endomondo trying to get exclusivity for the ANT+ stick. So it'll help you make sure it's working

Reference:
My guide is heavily based on this guide: http://forum.xda-developers.com/showpost.php?p=32863924&postcount=9

sexta-feira, 16 de agosto de 2013

Adding a custom resolution on Ubuntu 12.04 for my Chromebook Pixel

Quick note about how I managed to solve this.

Commands are in RED:

First you get the info you'll need for the next command using cvt and the resolution:
user@Machine:~$ cvt 1680 1120
# 1680x1120 59.89 Hz (CVT) hsync: 69.59 kHz; pclk: 157.00 MHz
Modeline
"1680x1120_60.00"  157.00  1680 1792 1968 2256  1120 1123 1133 1162 -hsync +vsync

Then you run the xrandr with the information in bold returned by the previous command:
user@Machine:~$ sudo xrandr --newmode "1680x1120_60.00"  157.00  1680 1792 1968 2256  1120 1123 1133 1162 -hsync +vsync
Now you find out the name of the display being used with xrandr -q:
user@Machine:~$ sudo xrandr -q
Screen 0: minimum 320 x 200, current 1600 x 1024, maximum 8192 x 8192
eDP1 connected 1600x1024+0+0 (normal left inverted right x axis y axis) 272mm x 181mm
   2560x1700      60.0 +
   2048x1536      60.0 
   1920x1440      60.0 
   1856x1392      60.0 
   1792x1344      60.0 
   1920x1200      60.0 
   1920x1080      59.9 
   1600x1200      60.0 
   1680x1050      60.0     59.9 
   1600x1024      60.2*
   1400x1050      60.0 
   1280x1024      60.0 
   1440x900       59.9 
   1280x960       60.0 
   1360x768       59.8     60.0 
   1152x864       60.0 
   1024x768       60.0 
   800x600        60.3     56.2 
   640x480        59.9 
VGA1 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
DP1 disconnected (normal left inverted right x axis y axis)
  1680x1120_60.00 (0x124)  157.0MHz
        h: width  1680 start 1792 end 1968 total 2256 skew    0 clock   69.6KHz
        v: height 1120 start 1123 end 1133 total 1162           clock   59.9Hz
And now you'll add your new resolution using guess who? Yes... xrand.
user@Machine:~$ sudo xrandr --addmode eDP1 1680x1120_60.00
That's it... quick and painless...