From 4ce74802e916605313af2762d585d184a2888b5f Mon Sep 17 00:00:00 2001 From: michux Date: Thu, 26 Mar 2009 23:11:12 +0000 Subject: vnc driver: add beta keypad support git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@1008 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- configure | 1 + drivers.m4 | 1 + drv_vnc.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/configure b/configure index 4b191b9..3a1f880 100755 --- a/configure +++ b/configure @@ -8606,6 +8606,7 @@ fi if test "$VNC" = "yes"; then if test "$has_vncserverlib" = "true"; then GRAPHIC="yes" + KEYPAD="yes" DRIVERS="$DRIVERS drv_vnc.o" DRVLIBS="$DRVLIBS -L/usr/local/lib -lvncserver -lz" diff --git a/drivers.m4 b/drivers.m4 index a6bf925..decfe0e 100644 --- a/drivers.m4 +++ b/drivers.m4 @@ -648,6 +648,7 @@ fi if test "$VNC" = "yes"; then if test "$has_vncserverlib" = "true"; then GRAPHIC="yes" + KEYPAD="yes" DRIVERS="$DRIVERS drv_vnc.o" DRVLIBS="$DRVLIBS -L/usr/local/lib -lvncserver -lz" AC_DEFINE(WITH_VNC,1,[vnc driver]) diff --git a/drv_vnc.c b/drv_vnc.c index 3262596..736197c 100644 --- a/drv_vnc.c +++ b/drv_vnc.c @@ -53,9 +53,10 @@ #include "widget_text.h" #include "widget_icon.h" #include "widget_bar.h" +#include "widget_keypad.h" #include "drv.h" - #include "drv_generic_graphic.h" +#include "drv_generic_keypad.h" //todo: fps limiter // key widget @@ -65,14 +66,17 @@ static char Name[] = "VNC"; -static rfbScreenInfoPtr server; -static int xres = 320; +static rfbScreenInfoPtr server; /* vnc device */ +static int xres = 320; /* screen settings */ static int yres = 200; static int BPP = 4; -static int max_clients = 2; +static int max_clients = 2; /* max connected clients */ +static int buttons = 2; /* number of keypad buttons */ + +static int clientCount = 0; /* currently connected clients */ -static int clientCount = 0; +/* called if a vnc client disconnects */ static void clientgone(rfbClientPtr cl) { if (clientCount > 0) @@ -80,7 +84,8 @@ static void clientgone(rfbClientPtr cl) debug("%d clients connecten", clientCount); } -static enum rfbNewClientAction newclient(rfbClientPtr cl) +/* called if a vnc client connect */ +static enum rfbNewClientAction hook_newclient(rfbClientPtr cl) { if (clientCount < max_clients) { clientCount++; @@ -94,18 +99,50 @@ static enum rfbNewClientAction newclient(rfbClientPtr cl) } /* handle mouse action */ -static void doptr(int buttonMask, int x, int y, rfbClientPtr cl) +static void hook_mouseaction(int buttonMask, int x, int y, rfbClientPtr cl) { if (x >= 0 && y >= 0 && x < xres && y < yres) { if (buttonMask) { - printf("btn:%d, x:%d, y:%d\n", buttonMask, x, y); + debug("button %d pressed", buttonMask); + drv_generic_keypad_press(buttonMask); } } rfbDefaultPtrAddEvent(buttonMask, x, y, cl); } +static int drv_vnc_keypad(const int num) +{ + int val = WIDGET_KEY_PRESSED; + + switch (num) { + case 1: + val += WIDGET_KEY_UP; + break; + case 2: + val += WIDGET_KEY_DOWN; + break; + case 3: + val += WIDGET_KEY_LEFT; + break; + case 4: + val += WIDGET_KEY_RIGHT; + break; + case 5: + val += WIDGET_KEY_CONFIRM; + break; + case 6: + val += WIDGET_KEY_CANCEL; + break; + default: + error("%s: unknown keypad value %d", Name, num); + } +debug("num %d, val %d", num, val); + return val; +} + +/* init the driver, read config */ static int drv_vnc_open(const char *Section) { if (cfg_number(Section, "xres", 320, 32, 2048, &xres) < 1) { @@ -123,7 +160,7 @@ static int drv_vnc_open(const char *Section) return 0; } - +/* shutdown driver, release allocated stuff */ static int drv_vnc_close(void) { rfbShutdownServer(server, TRUE); @@ -131,6 +168,7 @@ static int drv_vnc_close(void) return 0; } +/* actual blitting method */ static void drv_vnc_blit_it(const int row, const int col, const int height, const int width, unsigned char *buffer) { int r, c, ofs; @@ -195,8 +233,8 @@ static int drv_vnc_start(const char *section) server->desktopName = "LCD4Linux VNC Driver"; server->frameBuffer = (char *) malloc(xres * yres * BPP); server->alwaysShared = (1 == 1); - server->ptrAddEvent = doptr; - server->newClientHook = newclient; + server->ptrAddEvent = hook_mouseaction; + server->newClientHook = hook_newclient; /* Initialize the server */ rfbInitServer(server); @@ -239,6 +277,7 @@ int drv_vnc_init(const char *section, const int quiet) /* real worker functions */ drv_generic_graphic_real_blit = drv_vnc_blit; + drv_generic_keypad_real_press = drv_vnc_keypad; /* start display */ if ((ret = drv_vnc_start(section)) != 0) @@ -248,6 +287,10 @@ int drv_vnc_init(const char *section, const int quiet) if ((ret = drv_generic_graphic_init(section, Name)) != 0) return ret; + /* initialize generic key pad driver */ + if ((ret = drv_generic_keypad_init(section, Name)) != 0) + return ret; + if (!quiet) { char buffer[40]; qprintf(buffer, sizeof(buffer), "%s %dx%d", Name, DCOLS, DROWS); @@ -275,6 +318,7 @@ int drv_vnc_quit(const int quiet) } drv_generic_graphic_quit(); + drv_generic_keypad_quit(); debug("closing connection"); drv_vnc_close(); -- cgit v1.2.3