mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge branch 'master' of github.com:hwhw/kindlepdfviewer
This commit is contained in:
14
Makefile
14
Makefile
@@ -76,7 +76,7 @@ THIRDPARTYLIBS := $(MUPDFLIBDIR)/libfreetype.a \
|
||||
|
||||
LUALIB := $(LUADIR)/src/liblua.a
|
||||
|
||||
all:kpdfview slider_watcher
|
||||
all:kpdfview
|
||||
|
||||
kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft.o lfs.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRENGINELIBS)
|
||||
$(CC) -lm -ldl -lpthread $(EMU_LDFLAGS) -lstdc++ \
|
||||
@@ -98,17 +98,14 @@ kpdfview: kpdfview.o einkfb.o pdf.o blitbuffer.o drawcontext.o input.o util.o ft
|
||||
$(CRENGINELIBS) \
|
||||
-o kpdfview
|
||||
|
||||
einkfb.o input.o: %.o: %.c
|
||||
$(CC) -c $(KPDFREADER_CFLAGS) $(EMU_CFLAGS) $< -o $@
|
||||
|
||||
slider_watcher: slider_watcher.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
ft.o: %.o: %.c
|
||||
$(CC) -c $(KPDFREADER_CFLAGS) -I$(FREETYPEDIR)/include $< -o $@
|
||||
|
||||
kpdfview.o pdf.o blitbuffer.o util.o drawcontext.o: %.o: %.c
|
||||
$(CC) -c $(KPDFREADER_CFLAGS) -I$(LFSDIR)/src $< -o $@
|
||||
kpdfview.o pdf.o blitbuffer.o util.o drawcontext.o einkfb.o input.o: %.o: %.c
|
||||
$(CC) -c $(KPDFREADER_CFLAGS) $(EMU_CFLAGS) -I$(LFSDIR)/src $< -o $@
|
||||
|
||||
djvu.o: %.o: %.c
|
||||
$(CC) -c $(KPDFREADER_CFLAGS) -I$(DJVUDIR)/ $< -o $@
|
||||
@@ -190,11 +187,12 @@ install:
|
||||
scp launchpad/* root@192.168.2.2:/mnt/us/launchpad/
|
||||
|
||||
VERSION?=$(shell git rev-parse --short HEAD)
|
||||
customupdate: kpdfview
|
||||
customupdate: all
|
||||
# ensure that build binary is for ARM
|
||||
file kpdfview | grep ARM || exit 1
|
||||
rm -Rf $(INSTALL_DIR)
|
||||
mkdir $(INSTALL_DIR)
|
||||
cp -p README.TXT COPYING kpdfview slider_watcher *.lua $(INSTALL_DIR)
|
||||
cp -p README.TXT COPYING kpdfview *.lua $(INSTALL_DIR)
|
||||
mkdir $(INSTALL_DIR)/data
|
||||
cp -rpL data/*.css $(INSTALL_DIR)/data
|
||||
cp -rp fonts $(INSTALL_DIR)
|
||||
|
||||
98
input.c
98
input.c
@@ -19,29 +19,95 @@
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <linux/input.h>
|
||||
#include "input.h"
|
||||
|
||||
#define OUTPUT_SIZE 21
|
||||
#define CODE_IN_SAVER 10000
|
||||
#define CODE_OUT_SAVER 10001
|
||||
|
||||
#define NUM_FDS 4
|
||||
int inputfds[4] = { -1, -1, -1, -1 };
|
||||
|
||||
static int openInputDevice(lua_State *L) {
|
||||
#ifndef EMULATE_READER
|
||||
int findFreeFdSlot() {
|
||||
int i;
|
||||
const char* inputdevice = luaL_checkstring(L, 1);
|
||||
|
||||
for(i=0; i<NUM_FDS; i++) {
|
||||
if(inputfds[i] == -1) {
|
||||
inputfds[i] = open(inputdevice, O_RDONLY | O_NONBLOCK, 0);
|
||||
if(inputfds[i] != -1) {
|
||||
ioctl(inputfds[i], EVIOCGRAB, 1);
|
||||
return 0;
|
||||
} else {
|
||||
return luaL_error(L, "error opening input device <%s>: %d", inputdevice, errno);
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int openInputDevice(lua_State *L) {
|
||||
#ifndef EMULATE_READER
|
||||
int fd;
|
||||
const char* inputdevice = luaL_checkstring(L, 1);
|
||||
|
||||
fd = findFreeFdSlot();
|
||||
if(fd == -1) {
|
||||
return luaL_error(L, "no free slot for new input device <%s>", inputdevice);
|
||||
}
|
||||
|
||||
if(!strcmp("slider",inputdevice)) {
|
||||
/* special case: the power slider */
|
||||
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
|
||||
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
return luaL_error(L, "cannot initialize SDL.");
|
||||
@@ -66,7 +132,7 @@ static int waitForInput(lua_State *L) {
|
||||
fd_set fds;
|
||||
struct timeval timeout;
|
||||
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_usec = (usecs%1000000);
|
||||
@@ -81,7 +147,11 @@ static int waitForInput(lua_State *L) {
|
||||
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) {
|
||||
return luaL_error(L, "Waiting for input failed: %d\n", errno);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
[Actions]
|
||||
P P = !/mnt/us/launchpad/kpdf.sh
|
||||
P D = !/mnt/us/launchpad/kpdf.sh /mnt/us/documents
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
#!/bin/sh
|
||||
SLIDER_EVENT_PIPE="/tmp/event_slider"
|
||||
export LC_ALL="en_US.UTF-8"
|
||||
|
||||
echo unlock > /proc/keypad
|
||||
echo unlock > /proc/fiveway
|
||||
|
||||
cd /mnt/us/kindlepdfviewer/
|
||||
./reader.lua "$1" 2> /mnt/us/kindlepdfviewer/crash.log
|
||||
|
||||
# create the named pipe for power slider event
|
||||
if [ ! -p $SLIDER_EVENT_PIPE ]; then
|
||||
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 slider_watcher
|
||||
echo 1 > /proc/eink_fb/update_display
|
||||
|
||||
15
reader.lua
15
reader.lua
@@ -69,9 +69,6 @@ function showusage()
|
||||
print("-g, --goto=page start reading on page")
|
||||
print("-G, --gamma=GAMMA set gamma correction")
|
||||
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("")
|
||||
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()
|
||||
end
|
||||
|
||||
|
||||
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
|
||||
if util.isEmulated()==1 then
|
||||
input.open("")
|
||||
-- SDL key codes
|
||||
setEmuKeycodes()
|
||||
else
|
||||
input.open("slider")
|
||||
input.open("/dev/input/event0")
|
||||
input.open("/dev/input/event1")
|
||||
input.open("/tmp/event_slider")
|
||||
|
||||
-- check if we are running on Kindle 3 (additional volume input)
|
||||
local f=lfs.attributes("/dev/input/event2")
|
||||
|
||||
10
util.c
10
util.c
@@ -46,9 +46,19 @@ static int utf8charcode(lua_State *L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int isEmulated(lua_State *L) {
|
||||
#ifdef EMULATE_READER
|
||||
lua_pushinteger(L, 1);
|
||||
#else
|
||||
lua_pushinteger(L, 0);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const struct luaL_Reg util_func[] = {
|
||||
{"gettime", gettime},
|
||||
{"utf8charcode", utf8charcode},
|
||||
{"isEmulated", isEmulated},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user