#!/bin/sh

#define your next page/prev page buttons - this is actually copied from launchpad keydefs

#; Row1 
#Q = 16
#W = 17
#E = 18
#R = 19
#T = 20
#Y = 21
#U = 22
#I = 23
#O = 24
#P = 25

#; Row2 
#A = 30
#S = 31
#D = 32
#F = 33
#G = 34
#H = 35
#J = 36
#K = 37
#L = 38
#Del = 14

#; Row3 
#Z = 44
#X = 45
#C = 46
#V = 47
#B = 48
#N = 49
#M = 50
#Dot = 52
#Slash = 53
#Enter = 28

#; Row4 
#Shift = 42
#Alt = 56
#Space = 57
#aA = 90
#Sym = 94

#; Edge
#VPlus = 115
#VMinus = 114
#Home = 98
#< = 109
#> = 124
#Menu = 139
#Back = 91

#; FiveWay manipulator
#FW_Left = 105
#FW_Right = 106
#FW_Up = 122
#FW_Down = 123
#FW_Press = 92

#; Kindle3-specific keys
#; Row4
#;
#k3_aA =	190
#k3_Sym	= 126
#k3_Home	= 102
#k3_Back	= 158

#; Edge, left and right 
#k3_> = 191
#lk3_< = 193
#lk3_> = 104

#; bottom edge. same codes as on DXG, but generated by dev/input/event2 
#k3_VPlus = 115
#k3_VMinus = 114

#; FiveWay manipulator 
#k3_FW_Up = 103
#k3_FW_Down = 108
#k3_FW_Press = 194

#let's use some helpers
#send pid to ease terminating
echo $$ > /tmp/pageturn.pid
_FUNCTIONS=/etc/rc.d/functions
[ -f ${_FUNCTIONS} ] && . ${_FUNCTIONS}
#big loop
while true; do
{
#check if orientation is landscape
while [ "$(cat /sys/module/eink_fb_hal_broads/parameters/bs_orientation)" == "1" ]; do        
	{
#write input to temporary file
	waitforkey > /tmp/key
#read which key was pressed
	case "$(cat /tmp/key)" in
	"194 1")
	next_page;;
	"28 1") 
	prev_page;;
	esac
	}
done
}
done