switched slider handling to a fork()ed process

pull/2/merge
HW 12 years ago
parent 4e542f7d4f
commit 877ecdfb71

@ -19,29 +19,95 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h>
#include <linux/input.h> #include <linux/input.h>
#include "input.h" #include "input.h"
#define OUTPUT_SIZE 21
#define CODE_IN_SAVER 10000
#define CODE_OUT_SAVER 10001
#define NUM_FDS 4 #define NUM_FDS 4
int inputfds[4] = { -1, -1, -1, -1 }; int inputfds[4] = { -1, -1, -1, -1 };
int findFreeFdSlot() {
int i;
for(i=0; i<NUM_FDS; i++) {
if(inputfds[i] == -1) {
return i;
}
}
return -1;
}
static int openInputDevice(lua_State *L) { static int openInputDevice(lua_State *L) {
#ifndef EMULATE_READER #ifndef EMULATE_READER
int i; int fd;
const char* inputdevice = luaL_checkstring(L, 1); const char* inputdevice = luaL_checkstring(L, 1);
for(i=0; i<NUM_FDS; i++) { fd = findFreeFdSlot();
if(inputfds[i] == -1) { if(fd == -1) {
inputfds[i] = open(inputdevice, O_RDONLY | O_NONBLOCK, 0); return luaL_error(L, "no free slot for new input device <%s>", inputdevice);
if(inputfds[i] != -1) { }
ioctl(inputfds[i], EVIOCGRAB, 1);
return 0; if(!strcmp("slider",inputdevice)) {
} else { /* special case: the power slider */
return luaL_error(L, "error opening input device <%s>: %d", inputdevice, errno); int pipefd[2];
int childpid;
pipe(pipefd);
if((childpid = fork()) == -1) {
return luaL_error(L, "cannot fork() slider event listener");
}
if(childpid == 0) {
FILE *fp;
char std_out[OUTPUT_SIZE] = "";
struct input_event ev;
int ret;
__u16 key_code = 10000;
close(pipefd[0]);
ev.type = EV_KEY;
ev.code = key_code;
ev.value = 1;
/* listen power slider events */
while(1) {
fp = popen("exec lipc-wait-event com.lab126.powerd goingToScreenSaver,outOfScreenSaver", "r");
if(fgets(std_out, OUTPUT_SIZE, fp) == NULL) {
break;
}
pclose(fp);
if(std_out[0] == 'g') {
ev.code = CODE_IN_SAVER;
} else if(std_out[0] == 'o') {
ev.code = CODE_OUT_SAVER;
} else {
printf("Unrecognized event.\n");
}
/* fill event struct */
gettimeofday(&ev.time, NULL);
/* generate event */
if(write(pipefd[1], &ev, sizeof(struct input_event)) == -1) {
break;
}
} }
exit(0); /* cannot be reached?! */
} else {
close(pipefd[1]);
inputfds[fd] = pipefd[0];
}
} else {
inputfds[fd] = open(inputdevice, O_RDONLY | O_NONBLOCK, 0);
if(inputfds[fd] != -1) {
ioctl(inputfds[fd], EVIOCGRAB, 1);
return 0;
} else {
return luaL_error(L, "error opening input device <%s>: %d", inputdevice, errno);
} }
} }
return luaL_error(L, "no free slot for new input device <%s>", inputdevice);
#else #else
if(SDL_Init(SDL_INIT_VIDEO) < 0) { if(SDL_Init(SDL_INIT_VIDEO) < 0) {
return luaL_error(L, "cannot initialize SDL."); return luaL_error(L, "cannot initialize SDL.");
@ -66,7 +132,7 @@ static int waitForInput(lua_State *L) {
fd_set fds; fd_set fds;
struct timeval timeout; struct timeval timeout;
int i, num, nfds; int i, num, nfds;
int usecs = luaL_optint(L, 1, 0x7FFFFFFF); int usecs = luaL_optint(L, 1, -1); // we check for <0 later
timeout.tv_sec = (usecs/1000000); timeout.tv_sec = (usecs/1000000);
timeout.tv_usec = (usecs%1000000); timeout.tv_usec = (usecs%1000000);
@ -81,7 +147,11 @@ static int waitForInput(lua_State *L) {
nfds = inputfds[i] + 1; nfds = inputfds[i] + 1;
} }
num = select(nfds, &fds, NULL, NULL, &timeout); /* when no value is given as argument, we pass
* NULL to select() for the timeout value, setting no
* timeout at all.
*/
num = select(nfds, &fds, NULL, NULL, (usecs < 0) ? NULL : &timeout);
if(num < 0) { if(num < 0) {
return luaL_error(L, "Waiting for input failed: %d\n", errno); return luaL_error(L, "Waiting for input failed: %d\n", errno);
} }

@ -1,19 +1,11 @@
#!/bin/sh #!/bin/sh
SLIDER_EVENT_PIPE="/tmp/event_slider"
export LC_ALL="en_US.UTF-8" export LC_ALL="en_US.UTF-8"
echo unlock > /proc/keypad echo unlock > /proc/keypad
echo unlock > /proc/fiveway echo unlock > /proc/fiveway
cd /mnt/us/kindlepdfviewer/
# create the named pipe for power slider event cd /mnt/us/kindlepdfviewer/
if [ ! -p $SLIDER_EVENT_PIPE ]; then ./reader.lua "$1" 2> /mnt/us/kindlepdfviewer/crash.log
mkfifo $SLIDER_EVENT_PIPE
fi
killall slider_watcher
./slider_watcher $SLIDER_EVENT_PIPE &
./reader.lua $1 2> /mnt/us/kindlepdfviewer/crash.log
killall -cont cvm killall -cont cvm
killall slider_watcher
echo 1 > /proc/eink_fb/update_display echo 1 > /proc/eink_fb/update_display

@ -69,9 +69,6 @@ function showusage()
print("-g, --goto=page start reading on page") print("-g, --goto=page start reading on page")
print("-G, --gamma=GAMMA set gamma correction") print("-G, --gamma=GAMMA set gamma correction")
print(" (floating point notation, e.g. \"1.5\")") print(" (floating point notation, e.g. \"1.5\")")
print("-d, --device=DEVICE set device specific configuration,")
print(" currently one of \"kdxg\" (default), \"k3\"")
print(" \"emu\" (DXG emulation)")
print("-h, --help show this usage help") print("-h, --help show this usage help")
print("") print("")
print("If you give the name of a directory instead of a file path, a file") print("If you give the name of a directory instead of a file path, a file")
@ -89,22 +86,14 @@ if optarg["h"] then
return showusage() return showusage()
end end
if util.isEmulated()==1 then
if optarg["d"] == "k3" then
-- for now, the only difference is the additional input device
input.open("/dev/input/event0")
input.open("/dev/input/event1")
input.open("/dev/input/event2")
input.open("/tmp/event_slider")
setK3Keycodes()
elseif optarg["d"] == "emu" then
input.open("") input.open("")
-- SDL key codes -- SDL key codes
setEmuKeycodes() setEmuKeycodes()
else else
input.open("slider")
input.open("/dev/input/event0") input.open("/dev/input/event0")
input.open("/dev/input/event1") input.open("/dev/input/event1")
input.open("/tmp/event_slider")
-- check if we are running on Kindle 3 (additional volume input) -- check if we are running on Kindle 3 (additional volume input)
local f=lfs.attributes("/dev/input/event2") local f=lfs.attributes("/dev/input/event2")

Loading…
Cancel
Save