From af233cacc6967e1920b100bdf1af591664cd2a73 Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 4 Dec 2008 03:19:59 +0000 Subject: [PATCH] Enable keypad input git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1411 42af7a65-404d-4744-a932-0658087f49c3 --- configs/sim/nx/defconfig | 2 +- configs/sim/nx/defconfig-x11 | 2 +- examples/nx/nx_events.c | 48 ++++++++---------------------------- examples/nx/nx_main.c | 41 ++++++++++++++++++++++++++++++ graphics/nxmu/nx_kbdchin.c | 2 +- graphics/nxmu/nx_kbdin.c | 11 +++++---- graphics/nxmu/nxfe.h | 8 +++--- graphics/nxmu/nxmu_kbdin.c | 20 +++++++-------- graphics/nxsu/nx_kbdin.c | 4 +-- graphics/nxtk/nxtk_events.c | 8 +++--- include/nuttx/nx.h | 4 +-- 11 files changed, 82 insertions(+), 68 deletions(-) diff --git a/configs/sim/nx/defconfig b/configs/sim/nx/defconfig index d33a70c546..c2c378bceb 100644 --- a/configs/sim/nx/defconfig +++ b/configs/sim/nx/defconfig @@ -342,7 +342,7 @@ CONFIG_NXGLIB_DISABLE_24BPP=y CONFIG_NXGLIB_DISABLE_32BPP=y CONFIG_NXGL_PACKEDMSFIRST=n CONFIG_NX_MOUSE=y -CONFIG_NX_KBD=n +CONFIG_NX_KBD=y CONFIG_NX_BLOCKING=y CONFIG_NX_MXSERVERMSGS=32 CONFIG_NX_MXCLIENTMSGS=16 diff --git a/configs/sim/nx/defconfig-x11 b/configs/sim/nx/defconfig-x11 index 5cd232cea1..e974d4671c 100644 --- a/configs/sim/nx/defconfig-x11 +++ b/configs/sim/nx/defconfig-x11 @@ -342,7 +342,7 @@ CONFIG_NXGLIB_DISABLE_24BPP=y CONFIG_NXGLIB_DISABLE_32BPP=n CONFIG_NXGL_PACKEDMSFIRST=n CONFIG_NX_MOUSE=y -CONFIG_NX_KBD=n +CONFIG_NX_KBD=y CONFIG_NX_BLOCKING=y CONFIG_NX_MXSERVERMSGS=32 CONFIG_NX_MXCLIENTMSGS=16 diff --git a/examples/nx/nx_events.c b/examples/nx/nx_events.c index a3c7d78309..864b267c8a 100644 --- a/examples/nx/nx_events.c +++ b/examples/nx/nx_events.c @@ -41,6 +41,7 @@ #include #include +#include #include #include #include @@ -78,7 +79,7 @@ static void nxeg_mousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos, ubyte buttons, FAR void *arg); #endif #ifdef CONFIG_NX_KBD -static void nxeg_kbdin(NXEGWINDOW hwnd, ubyte nch, const ubyte *ch); +static void nxeg_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg); #endif #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS @@ -93,7 +94,7 @@ static void nxeg_tbmousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos, ubyte buttons, FAR void *arg); #endif #ifdef CONFIG_NX_KBD -static void nxeg_tbkbdin(NXEGWINDOW hwnd, ubyte nch, const ubyte *ch); +static void nxeg_tbkbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg); #endif #endif @@ -256,11 +257,11 @@ static void nxeg_kbdinfo(ubyte nch, const ubyte *ch) { if (isprint(ch[i])) { - message(" ch[%d]= (%02x)", i, ch[i]); + message(" ch[%d]=%c (%02x)\n", i, ch[i], ch[i]); } else { - message(" ch[%d]=%c (%02x)", i, ch[i], ch[i]); + message(" ch[%d]= (%02x)\n", i, ch[i]); } } } @@ -271,9 +272,9 @@ static void nxeg_kbdinfo(ubyte nch, const ubyte *ch) ****************************************************************************/ #ifdef CONFIG_NX_KBD -static void nxeg_kbdin(NXEGWINDOW hwnd, ubyte nch, const ubyte *ch) +static void nxeg_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg) { - message("nxeg_kbdin: hwnd=%p nch=%d\n", hwnd, nch); + message("nxeg_kbdin%d: hwnd=%p nch=%d\n", (int)arg, hwnd, nch); nxeg_kbdinfo(nch, ch); } #endif @@ -333,44 +334,15 @@ static void nxeg_tbmousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos, #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS #ifdef CONFIG_NX_KBD -static void nxeg_tbkbdin(NXEGWINDOW hwnd, ubyte nch, const ubyte *ch) +static void nxeg_tbkbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg) { - message("nxeg_tbkbdin: ERROR -- toolbar should not received keyboard input\n"; - message("nxeg_tbkbdin: hwnd=%p nch=%d\n", hwnd, nch); + message("nxeg_tbkbdin: ERROR -- toolbar should not received keyboard input\n"); + message("nxeg_tbkbdin%d: hwnd=%p nch=%d\n", (int)arg, hwnd, nch); nxeg_kbdinfo(nch, ch); } #endif #endif -/**************************************************************************** - * Name: nxeg_kbdin2 - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS -#ifdef CONFIG_NX_KBD -static void nxeg_kbdin2(NXEGWINDOW hwnd, ubyte nch, const ubyte *ch) -{ - message("nxeg_kbdin2: hwnd=%p nch=%d\n", hwnd, nch); - nxeg_kbdinfo(nch, ch); -} -#endif -#endif - -/**************************************************************************** - * Name: nxeg_mousein2 - ****************************************************************************/ - -#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS -#ifdef CONFIG_NX_MOUSE -static void nxeg_mousein2(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos, - ubyte buttons, FAR void *arg) -{ - message("nxeg_mousein%d: hwnd=%p pos=(%d,%d) button=%02x\n", - (int)arg, hwnd, pos->x, pos->y, buttons); -} -#endif -#endif - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/examples/nx/nx_main.c b/examples/nx/nx_main.c index 7e68b47bd8..ed7b7a3bb0 100644 --- a/examples/nx/nx_main.c +++ b/examples/nx/nx_main.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,12 @@ static int g_exitcode = NXEXIT_SUCCESS; +#ifdef CONFIG_NX_KBD +static const ubyte g_kbdmsg1[] = "NuttX is cool!"; +static const ubyte g_kbdmsg2[] = "NuttX is fun!"; +#endif + + /**************************************************************************** * Public Data ****************************************************************************/ @@ -656,6 +663,23 @@ int user_start(int argc, char *argv[]) /* Sleep a bit */ + message("user_start: Sleeping\n\n"); + sleep(1); +#endif + + /* Give keyboard input to the top window -- should be window #2 */ + +#ifdef CONFIG_NX_KBD + message("user_start: Send keyboard input: %s\n", g_kbdmsg1); + ret = nx_kbdin(g_hnx, strlen((FAR const char *)g_kbdmsg1), g_kbdmsg1); + if (ret < 0) + { + message("user_start: nx_kbdin failed: %d\n", errno); + goto errout_with_hwnd2; + } + + /* Sleep a bit */ + message("user_start: Sleeping\n\n"); sleep(1); #endif @@ -681,6 +705,23 @@ int user_start(int argc, char *argv[]) /* Sleep a bit */ + message("user_start: Sleeping\n\n"); + sleep(1); +#endif + + /* Give keyboard input to the top window -- should be window #1 */ + +#ifdef CONFIG_NX_KBD + message("user_start: Send keyboard input: %s\n", g_kbdmsg2); + ret = nx_kbdin(g_hnx, strlen((FAR const char *)g_kbdmsg2), g_kbdmsg2); + if (ret < 0) + { + message("user_start: nx_kbdin failed: %d\n", errno); + goto errout_with_hwnd2; + } + + /* Sleep a bit */ + message("user_start: Sleeping\n\n"); sleep(1); #endif diff --git a/graphics/nxmu/nx_kbdchin.c b/graphics/nxmu/nx_kbdchin.c index 4f16c1d287..e83c9a0a27 100644 --- a/graphics/nxmu/nx_kbdchin.c +++ b/graphics/nxmu/nx_kbdchin.c @@ -94,7 +94,7 @@ int nx_kbdchin(NXHANDLE handle, ubyte ch) outmsg.nch = 1; outmsg.ch[0] = ch; - ret = mq_send(conn->c_cwrmq, &outmsg, sizeof(struct nxsvrmsg_kbdin_s), NX_SVRMSG_PRIO); + ret = mq_send(conn->cwrmq, &outmsg, sizeof(struct nxsvrmsg_kbdin_s), NX_SVRMSG_PRIO); if (ret < 0) { gdbg("mq_send failed: %d\n", errno); diff --git a/graphics/nxmu/nx_kbdin.c b/graphics/nxmu/nx_kbdin.c index 46229a94e8..e9665e89b9 100644 --- a/graphics/nxmu/nx_kbdin.c +++ b/graphics/nxmu/nx_kbdin.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -82,7 +83,7 @@ * ****************************************************************************/ -int int nx_kbdin(NXHANDLE handle, ubyte nch const char *ch) +int nx_kbdin(NXHANDLE handle, ubyte nch, FAR const ubyte *ch) { FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; FAR struct nxsvrmsg_kbdin_s *outmsg; @@ -104,15 +105,15 @@ int int nx_kbdin(NXHANDLE handle, ubyte nch const char *ch) /* Inform the server of the new keypad data */ - outsg->msgid = NX_SVRMSG_KBDIN; - outmsg->nch = nch; + outmsg->msgid = NX_SVRMSG_KBDIN; + outmsg->nch = nch; - for (i = 0; i < nch; i+) + for (i = 0; i < nch; i++) { outmsg->ch[i] = ch[i]; } - ret = mq_send(conn->c_cwrmq, outmsg, size, NX_SVRMSG_PRIO); + ret = mq_send(conn->cwrmq, outmsg, size, NX_SVRMSG_PRIO); if (ret < 0) { gdbg("mq_send failed: %d\n", errno); diff --git a/graphics/nxmu/nxfe.h b/graphics/nxmu/nxfe.h index e036bf6756..47a804c497 100644 --- a/graphics/nxmu/nxfe.h +++ b/graphics/nxmu/nxfe.h @@ -237,11 +237,11 @@ struct nxclimsg_mousein_s /* This message reports a new keypad event to a particular window */ #ifdef CONFIG_NX_KBD -struct nxclimsg_key +struct nxclimsg_kbdin_s { uint32 msgid; /* NX_CLIMSG_KBDIN */ FAR struct nxbe_window_s *wnd; /* The handle of window receiving keypad input */ - ubyte nch /* Number of characters received */ + ubyte nch; /* Number of characters received */ ubyte ch[1]; /* Array of received characters */ }; #endif @@ -408,7 +408,7 @@ struct nxsvrmsg_mousein_s struct nxsvrmsg_kbdin_s { uint32 msgid; /* NX_SVRMSG_KBDIN */ - ubyte nch /* Number of characters received */ + ubyte nch ; /* Number of characters received */ ubyte ch[1]; /* Array of received characters */ }; #endif @@ -613,7 +613,7 @@ EXTERN int nxmu_mousein(FAR struct nxfe_state_s *fe, ****************************************************************************/ #ifdef CONFIG_NX_KBD -EXTERN void nxmu_kbdin(FAR struct nxfe_state_s *fe, ubyte nch, ubyte *ch); +EXTERN void nxmu_kbdin(FAR struct nxfe_state_s *fe, ubyte nch, FAR ubyte *ch); #endif #undef EXTERN diff --git a/graphics/nxmu/nxmu_kbdin.c b/graphics/nxmu/nxmu_kbdin.c index 35af516ae1..9035333577 100644 --- a/graphics/nxmu/nxmu_kbdin.c +++ b/graphics/nxmu/nxmu_kbdin.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -82,10 +83,9 @@ * ****************************************************************************/ -void nxmu_kbdin(FAR struct nxs_server_s *svr, ubyte nch, ubyte *ch) +void nxmu_kbdin(FAR struct nxfe_state_s *fe, ubyte nch, FAR ubyte *ch) { - struct nxbe_window_s *wnd; - FAR struct nxclimgs_kbdin_s *outmsg; + FAR struct nxclimsg_kbdin_s *outmsg; int size; int ret; int i; @@ -94,22 +94,22 @@ void nxmu_kbdin(FAR struct nxs_server_s *svr, ubyte nch, ubyte *ch) * character data. */ - size = sizeof(struct nxclimgs_kbdin_s) + nch - 1; - outmsg = (FAR struct nxclimgs_kbdin_s *)malloc(size); + size = sizeof(struct nxclimsg_kbdin_s) + nch - 1; + outmsg = (FAR struct nxclimsg_kbdin_s *)malloc(size); if (outmsg) { /* Give the keypad input only to the top child */ - outsg->msgid = NX_SVRMSG_KBDIN; - outmsg->wnd = svr->topwnd; - outmsg->nch = nch; + outmsg->msgid = NX_CLIMSG_KBDIN; + outmsg->wnd = fe->be.topwnd; + outmsg->nch = nch; - for (i = 0; i < nch; i+) + for (i = 0; i < nch; i++) { outmsg->ch[i] = ch[i]; } - ret = mq_send(svr->topwnd->conn->swrmq, outmsg, size, NX_SVRMSG_PRIO); + ret = mq_send(fe->be.topwnd->conn->swrmq, outmsg, size, NX_SVRMSG_PRIO); if (ret < 0) { gdbg("mq_send failed: %d\n", errno); diff --git a/graphics/nxsu/nx_kbdin.c b/graphics/nxsu/nx_kbdin.c index 3fe6a26c0f..54081d6625 100644 --- a/graphics/nxsu/nx_kbdin.c +++ b/graphics/nxsu/nx_kbdin.c @@ -81,7 +81,7 @@ * ****************************************************************************/ -int int nx_kbdin(NXHANDLE handle, ubyte nch const char *ch) +int nx_kbdin(NXHANDLE handle, ubyte nch, FAR const ubyte *ch) { FAR struct nxfe_state_s *fe = (FAR struct nxfe_state_s *)handle; FAR struct nxbe_window_s *wnd = fe->be.topwnd; @@ -92,7 +92,7 @@ int int nx_kbdin(NXHANDLE handle, ubyte nch const char *ch) if (wnd->cb->kbdin) { - wnd->cb->kbdin(wnd, kbd->nch, kbd->ch, wnd->arg); + wnd->cb->kbdin(wnd, nch, ch, wnd->arg); } } diff --git a/graphics/nxtk/nxtk_events.c b/graphics/nxtk/nxtk_events.c index 1832eda75d..52323a7514 100644 --- a/graphics/nxtk/nxtk_events.c +++ b/graphics/nxtk/nxtk_events.c @@ -72,7 +72,7 @@ static void nxtk_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, ubyte buttons, FAR void *arg); #endif #ifdef CONFIG_NX_KBD -static void nxtk_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch); +static void nxtk_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg); #endif /**************************************************************************** @@ -91,7 +91,7 @@ const struct nx_callback_s g_nxtkcb = , nxtk_mousein /* mousein */ #endif #ifdef CONFIG_NX_KBD - , nxtk_kbdin1 /* kbdin */ + , nxtk_kbdin /* kbdin */ #endif }; @@ -252,7 +252,7 @@ static void nxtk_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, ****************************************************************************/ #ifdef CONFIG_NX_KBD -static void nxtk_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch) +static void nxtk_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg) { FAR struct nxtk_framedwindow_s *fwnd = (FAR struct nxtk_framedwindow_s *)hwnd; @@ -260,7 +260,7 @@ static void nxtk_kbdin(NXWINDOW hwnd, ubyte nch, const ubyte *ch) if (fwnd->fwcb->kbdin) { - fwnd->fwcb->kbdin((NXTKWINDOW)fwnd, nch, ch); + fwnd->fwcb->kbdin((NXTKWINDOW)fwnd, nch, ch, fwnd->fwarg); } } #endif diff --git a/include/nuttx/nx.h b/include/nuttx/nx.h index 1c5c915316..79abbdd761 100644 --- a/include/nuttx/nx.h +++ b/include/nuttx/nx.h @@ -177,7 +177,7 @@ struct nx_callback_s **************************************************************************/ #ifdef CONFIG_NX_KBD - void (*kbdin)(NXWINDOW hwnd, ubyte nch, const ubyte *ch, FAR void *arg); + void (*kbdin)(NXWINDOW hwnd, ubyte nch, FAR const ubyte *ch, FAR void *arg); #endif }; @@ -687,7 +687,7 @@ EXTERN int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s *dest, #ifdef CONFIG_NX_KBD EXTERN int nx_kbdchin(NXHANDLE handle, ubyte ch); -EXTERN int nx_kbdin(NXHANDLE handle, ubyte nch const char *ch); +EXTERN int nx_kbdin(NXHANDLE handle, ubyte nch, FAR const ubyte *ch); #endif /****************************************************************************