/*******************************************************************
*Use Android phone as WiFi remote control to turn page on Kindle.
*Works when phone is locked/screen off
*Supports all kinds of hardware buttons(volume keys, headphone inline controls, external mouse/keyboard etc..)
*
*Requirements:
*Jailbroken Kindle with KUAL
*Rooted Android device
*
*by lucida
********************************************************************/



On Kindle

Jailbrake and install KUAL
Connect kindle to PC
Put "wifiremote" folder to "extensions"
Launch from KUAL's "Wifi Remote" menu

Configuration is done via bin/config.sh automatically
***************************************************
On Android

Phone has to be rooted.
Install "Terminal Emulator for Android" and "Gscript Lite", both are free.
https://play.google.com/store/apps/details?id=jackpal.androidterm&hl=en
https://play.google.com/store/apps/details?id=nl.rogro.GScriptLite&hl=en
And a file manager with root support(optional)

Under "Android-bin" folder select file accordingly. -Legacy binary is for pre-4.2 devices.
"ARM/android-remote" should work for most phones.
Copy "remote-android" to phone's "/data/local/tmp" folder and set permission to r-xr-xr-x.

Run "Terminal Emulator for Android" on the phone, input "su", the "getevent"
Press a hardware button, which can be volume key, headphones inline controls, bluetooth devices...etc.,
and watch screen output.

Usually a keypress will generate 4 lines of code

/dev/input/event3: 0001 0073 00000001
/dev/input/event3: 0000 0000 00000000
/dev/input/event3: 0001 0073 00000000
/dev/input/event3: 0000 0000 00000000

If the second column is "0001", write down the device path in first column, 
in this case, it's "/dev/input/event3", and 0x73 in 3rd column. 
Note: 73 is in hex and needed to covert to 115 in decimal.

The program supports upto 3 buttons in same device(with same /dev/input/event#), 
for right side(next page), left side(previous page) and top(menu) click correspondingly.

Now open "GScript Lite" and create 2 new scripts:
+++++++
Name: Run Service
Check Need SU
Content:
killall remote-android
nohup /data/local/tmp/remote-android /dev/input/eventX 192.168.1.xxx 54321 pass1234 x y z > /dev/null 2>&1

Name Stop Service
Check Need SU
Content:
killall remote-android
+++++++


*Parameters in "Run Service" script:
/dev/input/eventX 192.168.1.xxx 54321 pass1234 x y z

/dev/input/eventX The device path from "getevent" command
192.168.1.xxxkindle's ip address, run ";711" in kindle's search bar to get it.
54321default port#
pass1234default password
x y zbutton code, the number from "getevent"
these 3 codes are for prev page, next page and menu.
If the device has less than 3 buttons, set empty/unwanted button to 0.
For example:
VolDown is 114, VolUP is 115, so "114 0 115"means VolDown for next pageVoUp for menu, and no button for previous page


Now click "run service" from GScript to launch the service and "stop service" to stop it.

===========================
===========================

Source code is in src folder, feel free to build your own copy.