void arch_tcuninitialize(void) { /* Shut down the touchscreen driver */ sim_tcuninitialize(); /* Close NX */ nx_close(g_simtc.hnx); }
void board_tsc_teardown(void) { /* Shut down the touchscreen driver */ sim_tcuninitialize(); /* Close NX */ nx_close(g_simtc.hnx); }
int arch_tcinitialize(int minor) { FAR NX_DRIVERTYPE *dev; nxgl_mxpixel_t color; int ret; /* Initialize the simulated frame buffer device. We need to create an * X11 window to support the mouse-driven touchscreen simulation. */ ivdbg("Initializing framebuffer\n"); ret = up_fbinitialize(); if (ret < 0) { idbg("up_fbinitialize failed: %d\n", -ret); goto errout; } dev = up_fbgetvplane(0); if (!dev) { idbg("up_fbgetvplane 0 failed\n"); ret = -ENODEV; goto errout_with_fb; } /* Then open NX */ ivdbg("Open NX\n"); g_simtc.hnx = nx_open(dev); if (!g_simtc.hnx) { ret = -errno; idbg("nx_open failed: %d\n", ret); goto errout_with_fb; } /* Set the background to the configured background color */ ivdbg("Set background color=%d\n", CONFIG_EXAMPLES_TOUCHSCREEN_BGCOLOR); color = CONFIG_EXAMPLES_TOUCHSCREEN_BGCOLOR; ret = nx_setbgcolor(g_simtc.hnx, &color); if (ret < 0) { idbg("nx_setbgcolor failed: %d\n", ret); goto errout_with_nx; } /* Finally, initialize the touchscreen simulation on the X window */ ret = sim_tcinitialize(minor); if (ret < 0) { idbg("sim_tcinitialize failed: %d\n", ret); goto errout_with_nx; } return OK; errout_with_nx: nx_close(g_simtc.hnx); goto errout; errout_with_fb: fb_uninitialize(); errout: return ret; }
int nxlines_main(int argc, char *argv[]) { nxgl_mxpixel_t color; int ret; /* Initialize NX */ ret = nxlines_initialize(); message("nxlines_main: NX handle=%p\n", g_nxlines.hnx); if (!g_nxlines.hnx || ret < 0) { message("nxlines_main: Failed to get NX handle: %d\n", errno); g_nxlines.code = NXEXIT_NXOPEN; goto errout; } /* Set the background to the configured background color */ message("nxlines_main: Set background color=%d\n", CONFIG_EXAMPLES_NXLINES_BGCOLOR); color = CONFIG_EXAMPLES_NXLINES_BGCOLOR; ret = nx_setbgcolor(g_nxlines.hnx, &color); if (ret < 0) { message("nxlines_main: nx_setbgcolor failed: %d\n", errno); g_nxlines.code = NXEXIT_NXSETBGCOLOR; goto errout_with_nx; } /* Get the background window */ ret = nx_requestbkgd(g_nxlines.hnx, &g_nxlinescb, NULL); if (ret < 0) { message("nxlines_main: nx_setbgcolor failed: %d\n", errno); g_nxlines.code = NXEXIT_NXREQUESTBKGD; goto errout_with_nx; } /* Wait until we have the screen resolution. We'll have this immediately * unless we are dealing with the NX server. */ while (!g_nxlines.havepos) { (void)sem_wait(&g_nxlines.sem); } message("nxlines_main: Screen resolution (%d,%d)\n", g_nxlines.xres, g_nxlines.yres); /* Now, say perform the lines (these test does not return so the remaining * logic is cosmetic). */ nxlines_test(g_nxlines.hbkgd); /* Release background */ (void)nx_releasebkgd(g_nxlines.hbkgd); /* Close NX */ errout_with_nx: message("nxlines_main: Close NX\n"); nx_close(g_nxlines.hnx); errout: return g_nxlines.code; }
int nximage_main(int argc, char *argv[]) #endif { nxgl_mxpixel_t color; int ret; /* Initialize NX */ ret = nximage_initialize(); printf("nximage_main: NX handle=%p\n", g_nximage.hnx); if (!g_nximage.hnx || ret < 0) { printf("nximage_main: Failed to get NX handle: %d\n", errno); g_nximage.code = NXEXIT_NXOPEN; goto errout; } /* Set the background to the configured background color */ color = nximage_bgcolor(); printf("nximage_main: Set background color=%u\n", color); ret = nx_setbgcolor(g_nximage.hnx, &color); if (ret < 0) { printf("nximage_main: nx_setbgcolor failed: %d\n", errno); g_nximage.code = NXEXIT_NXSETBGCOLOR; goto errout_with_nx; } /* Get the background window */ ret = nx_requestbkgd(g_nximage.hnx, &g_nximagecb, NULL); if (ret < 0) { printf("nximage_main: nx_setbgcolor failed: %d\n", errno); g_nximage.code = NXEXIT_NXREQUESTBKGD; goto errout_with_nx; } /* Wait until we have the screen resolution. We'll have this immediately * unless we are dealing with the NX server. */ while (!g_nximage.havepos) { (void)sem_wait(&g_nximage.sem); } printf("nximage_main: Screen resolution (%d,%d)\n", g_nximage.xres, g_nximage.yres); /* Now, put up the NuttX logo and wait a bit so that it visible. */ nximage_image(g_nximage.hbkgd); sleep(5); /* Release background */ (void)nx_releasebkgd(g_nximage.hbkgd); /* Close NX */ errout_with_nx: printf("nximage_main: Close NX\n"); nx_close(g_nximage.hnx); errout: return g_nximage.code; }
int nxtext_main(int argc, char **argv) { FAR struct nxtext_state_s *bgstate; NXWINDOW hwnd = NULL; nxgl_mxpixel_t color; int popcnt; int bkgndx; int ret; /* Initialize NX */ ret = nxtext_initialize(); message("nxtext_main: NX handle=%p\n", g_hnx); if (!g_hnx || ret < 0) { message("nxtext_main: Failed to get NX handle: %d\n", errno); g_exitcode = NXEXIT_NXOPEN; goto errout; } /* Get the configured font handles */ g_bghfont = nxf_getfonthandle(CONFIG_EXAMPLES_NXTEXT_BGFONTID); if (!g_bghfont) { message("nxtext_main: Failed to get background font handle: %d\n", errno); g_exitcode = NXEXIT_FONTOPEN; goto errout; } g_puhfont = nxf_getfonthandle(CONFIG_EXAMPLES_NXTEXT_PUFONTID); if (!g_puhfont) { message("nxtext_main: Failed to get pop-up font handle: %d\n", errno); g_exitcode = NXEXIT_FONTOPEN; goto errout; } /* Set the background to the configured background color */ message("nxtext_main: Set background color=%d\n", CONFIG_EXAMPLES_NXTEXT_BGCOLOR); color = CONFIG_EXAMPLES_NXTEXT_BGCOLOR; ret = nx_setbgcolor(g_hnx, &color); if (ret < 0) { message("nxtext_main: nx_setbgcolor failed: %d\n", errno); g_exitcode = NXEXIT_NXSETBGCOLOR; goto errout_with_nx; } /* Get the background window */ bgstate = nxbg_getstate(); ret = nx_requestbkgd(g_hnx, &g_nxtextcb, bgstate); if (ret < 0) { message("nxtext_main: nx_setbgcolor failed: %d\n", errno); g_exitcode = NXEXIT_NXREQUESTBKGD; goto errout_with_nx; } /* Wait until we have the screen resolution. We'll have this immediately * unless we are dealing with the NX server. */ while (!b_haveresolution) { (void)sem_wait(&g_semevent); } message("nxtext_main: Screen resolution (%d,%d)\n", g_xres, g_yres); /* Now loop, adding text to the background and periodically presenting * a pop-up window. */ popcnt = 0; bkgndx = 0; for (;;) { /* Sleep for one second */ sleep(1); popcnt++; /* Each three seconds, create a pop-up window. Destroy the pop-up * window after two more seconds. */ if (popcnt == 3) { /* Create a pop-up window */ hwnd = nxpu_open(); /* Give keyboard input to the top window (which should be the pop-up) */ #ifdef CONFIG_NX_KBD message("nxtext_main: Send keyboard input: %s\n", g_pumsg); ret = nx_kbdin(g_hnx, strlen((FAR const char *)g_pumsg), g_pumsg); if (ret < 0) { message("nxtext_main: nx_kbdin failed: %d\n", errno); goto errout_with_hwnd; } #endif } else if (popcnt == 5) { /* Destroy the pop-up window and restart the sequence */ message("nxtext_main: Close pop-up\n"); (void)nxpu_close(hwnd); popcnt = 0; } /* Give another line of text to the background window. Force this * text to go the background by calling the background window interfaces * directly. */ nxbg_write(g_bgwnd, (FAR const uint8_t *)g_bgmsg[bkgndx], strlen(g_bgmsg[bkgndx])); if (++bkgndx >= BGMSG_LINES) { bkgndx = 0; } } /* Close the pop-up window */ errout_with_hwnd: if (popcnt >= 3) { message("nxtext_main: Close pop-up\n"); (void)nxpu_close(hwnd); } //errout_with_bkgd: (void)nx_releasebkgd(g_bgwnd); errout_with_nx: #ifdef CONFIG_NX_MULTIUSER /* Disconnect from the server */ message("nxtext_main: Disconnect from the server\n"); nx_disconnect(g_hnx); #else /* Close the server */ message("nxtext_main: Close NX\n"); nx_close(g_hnx); #endif errout: return g_exitcode; }
int nxhello_main(int argc, char *argv[]) #endif { nxgl_mxpixel_t color; int ret; /* Initialize NX */ ret = nxhello_initialize(); printf("nxhello_main: NX handle=%p\n", g_nxhello.hnx); if (!g_nxhello.hnx || ret < 0) { printf("nxhello_main: Failed to get NX handle: %d\n", errno); g_nxhello.code = NXEXIT_NXOPEN; goto errout; } /* Get the default font handle */ g_nxhello.hfont = nxf_getfonthandle(CONFIG_EXAMPLES_NXHELLO_FONTID); if (!g_nxhello.hfont) { printf("nxhello_main: Failed to get font handle: %d\n", errno); g_nxhello.code = NXEXIT_FONTOPEN; goto errout; } /* Set the background to the configured background color */ printf("nxhello_main: Set background color=%d\n", CONFIG_EXAMPLES_NXHELLO_BGCOLOR); color = CONFIG_EXAMPLES_NXHELLO_BGCOLOR; ret = nx_setbgcolor(g_nxhello.hnx, &color); if (ret < 0) { printf("nxhello_main: nx_setbgcolor failed: %d\n", errno); g_nxhello.code = NXEXIT_NXSETBGCOLOR; goto errout_with_nx; } /* Get the background window */ ret = nx_requestbkgd(g_nxhello.hnx, &g_nxhellocb, NULL); if (ret < 0) { printf("nxhello_main: nx_setbgcolor failed: %d\n", errno); g_nxhello.code = NXEXIT_NXREQUESTBKGD; goto errout_with_nx; } /* Wait until we have the screen resolution. We'll have this immediately * unless we are dealing with the NX server. */ while (!g_nxhello.havepos) { (void)sem_wait(&g_nxhello.sem); } printf("nxhello_main: Screen resolution (%d,%d)\n", g_nxhello.xres, g_nxhello.yres); /* Now, say hello and exit, sleeping a little before each. */ sleep(1); nxhello_hello(g_nxhello.hbkgd); sleep(5000); /* Release background */ (void)nx_releasebkgd(g_nxhello.hbkgd); /* Close NX */ errout_with_nx: printf("nxhello_main: Close NX\n"); nx_close(g_nxhello.hnx); errout: return g_nxhello.code; }
int nx_main(int argc, char *argv[]) { NXEGWINDOW hwnd1; NXEGWINDOW hwnd2; struct nxgl_size_s size; struct nxgl_point_s pt; nxgl_mxpixel_t color; int ret; /* Initialize */ ret = nxeg_initialize(); message("nx_main: NX handle=%p\n", g_hnx); if (!g_hnx || ret < 0) { message("nx_main: Failed to get NX handle: %d\n", errno); g_exitcode = NXEXIT_NXOPEN; goto errout; } /* Get the default font handle */ g_fonthandle = nxf_getfonthandle(CONFIG_EXAMPLES_NX_FONTID); if (!g_fonthandle) { message("nx_main: Failed to get font handle: %d\n", errno); g_exitcode = NXEXIT_FONTOPEN; goto errout; } /* Set the background to the configured background color */ message("nx_main: Set background color=%d\n", CONFIG_EXAMPLES_NX_BGCOLOR); color = CONFIG_EXAMPLES_NX_BGCOLOR; ret = nx_setbgcolor(g_hnx, &color); if (ret < 0) { message("nx_main: nx_setbgcolor failed: %d\n", errno); g_exitcode = NXEXIT_NXSETBGCOLOR; goto errout_with_nx; } /* Create window #1 */ message("nx_main: Create window #1\n"); nxeg_initstate(&g_wstate[0], 1, CONFIG_EXAMPLES_NX_COLOR1); hwnd1 = nxeg_openwindow(&g_nxcb, &g_wstate[0]); message("nx_main: hwnd1=%p\n", hwnd1); if (!hwnd1) { goto errout_with_nx; } /* Wait until we have the screen resolution */ while (!b_haveresolution) { (void)sem_wait(&g_semevent); } message("nx_main: Screen resolution (%d,%d)\n", g_xres, g_yres); /* Set the size of the window 1 */ size.w = g_xres / 2; size.h = g_yres / 2; message("nx_main: Set window #1 size to (%d,%d)\n", size.w, size.h); ret = nxeg_setsize(hwnd1, &size); if (ret < 0) { goto errout_with_hwnd1; } /* Sleep a bit -- both so that we can see the result of the above operations * but also, in the multi-user case, so that the server can get a chance to * actually do them! */ message("nx_main: Sleeping\n\n"); sleep(1); /* Set the position of window #1 */ pt.x = g_xres / 8; pt.y = g_yres / 8; message("nx_main: Set window #1 postion to (%d,%d)\n", pt.x, pt.y); ret = nxeg_setposition(hwnd1, &pt); if (ret < 0) { goto errout_with_hwnd1; } /* Sleep a bit */ message("nx_main: Sleeping\n\n"); sleep(1); /* Open the toolbar */ #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS message("nx_main: Add toolbar to window #1\n"); ret = nxeq_opentoolbar(hwnd1, CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT, &g_tbcb, &g_wstate[0]); if (ret < 0) { goto errout_with_hwnd1; } /* Sleep a bit */ message("nx_main: Sleeping\n\n"); sleep(1); #endif /* Create window #2 */ message("nx_main: Create window #2\n"); nxeg_initstate(&g_wstate[1], 2, CONFIG_EXAMPLES_NX_COLOR2); hwnd2 = nxeg_openwindow(&g_nxcb, &g_wstate[1]); message("nx_main: hwnd2=%p\n", hwnd2); if (!hwnd2) { goto errout_with_hwnd1; } /* Sleep a bit */ message("nx_main: Sleeping\n\n"); sleep(1); /* Set the size of the window 2 == size of window 1*/ message("nx_main: Set hwnd2 size to (%d,%d)\n", size.w, size.h); ret = nxeg_setsize(hwnd2, &size); if (ret < 0) { goto errout_with_hwnd2; } /* Sleep a bit */ message("nx_main: Sleeping\n\n"); sleep(1); /* Set the position of window #2 */ pt.x = g_xres - size.w - pt.x; pt.y = g_yres - size.h - pt.y; message("nx_main: Set hwnd2 postion to (%d,%d)\n", pt.x, pt.y); ret = nxeg_setposition(hwnd2, &pt); if (ret < 0) { goto errout_with_hwnd2; } /* Sleep a bit */ message("nx_main: Sleeping\n\n"); sleep(1); #ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS message("nx_main: Add toolbar to window #2\n"); ret = nxeq_opentoolbar(hwnd2, CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT, &g_tbcb, &g_wstate[1]); if (ret < 0) { goto errout_with_hwnd2; } /* Sleep a bit */ message("nx_main: Sleeping\n\n"); sleep(1); #endif /* Give keyboard input to the top window -- should be window #2 */ #ifdef CONFIG_NX_KBD message("nx_main: Send keyboard input: %s\n", g_kbdmsg1); ret = nx_kbdin(g_hnx, strlen((FAR const char *)g_kbdmsg1), g_kbdmsg1); if (ret < 0) { message("nx_main: nx_kbdin failed: %d\n", errno); goto errout_with_hwnd2; } /* Sleep a bit */ message("nx_main: Sleeping\n\n"); sleep(1); #endif /* Lower window 2 */ message("nx_main: Lower window #2\n"); ret = nxeg_lower(hwnd2); if (ret < 0) { goto errout_with_hwnd2; } /* Sleep a bit */ message("nx_main: Sleeping\n\n"); sleep(1); /* Put mouse left-button clicks all over the screen and see who responds */ #ifdef CONFIG_NX_MOUSE nxeg_drivemouse(); /* Sleep a bit */ message("nx_main: Sleeping\n\n"); sleep(1); #endif /* Give keyboard input to the top window -- should be window #1 */ #ifdef CONFIG_NX_KBD message("nx_main: Send keyboard input: %s\n", g_kbdmsg2); ret = nx_kbdin(g_hnx, strlen((FAR const char *)g_kbdmsg2), g_kbdmsg2); if (ret < 0) { message("nx_main: nx_kbdin failed: %d\n", errno); goto errout_with_hwnd2; } /* Sleep a bit */ message("nx_main: Sleeping\n\n"); sleep(1); #endif /* Raise window 2 */ message("nx_main: Raise window #2\n"); ret = nxeg_raise(hwnd2); if (ret < 0) { goto errout_with_hwnd2; } /* Put mouse left-button clicks all over the screen and see who responds */ #ifdef CONFIG_NX_MOUSE nxeg_drivemouse(); #endif /* Sleep a bit */ message("nx_main: Sleeping\n\n"); sleep(2); /* Close the window 2 */ errout_with_hwnd2: message("nx_main: Close window #2\n"); (void)nxeg_closewindow(hwnd2, &g_wstate[1]); /* Close the window1 */ errout_with_hwnd1: message("nx_main: Close window #1\n"); (void)nxeg_closewindow(hwnd1, &g_wstate[0]); errout_with_nx: #ifdef CONFIG_NX_MULTIUSER /* Disconnect from the server */ message("nx_main: Disconnect from the server\n"); nx_disconnect(g_hnx); #else /* Close the server */ message("nx_main: Close NX\n"); nx_close(g_hnx); #endif errout: return g_exitcode; }
int board_tsc_setup(int minor) { FAR NX_DRIVERTYPE *dev; nxgl_mxpixel_t color; int ret; /* Initialize the simulated frame buffer device. We need to create an * X11 window to support the mouse-driven touchscreen simulation. */ iinfo("Initializing framebuffer\n"); ret = up_fbinitialize(0); if (ret < 0) { ierr("ERROR: up_fbinitialize failed: %d\n", -ret); goto errout; } dev = up_fbgetvplane(0, 0); if (!dev) { ierr("ERROR: up_fbgetvplane 0 failed\n"); ret = -ENODEV; goto errout_with_fb; } /* Then open NX */ iinfo("Open NX\n"); g_simtc.hnx = nx_open(dev); if (!g_simtc.hnx) { ret = -errno; ierr("ERROR: nx_open failed: %d\n", ret); goto errout_with_fb; } #ifdef CONFIG_VNCSERVER /* Setup the VNC server to support keyboard/mouse inputs */ ret = vnc_default_fbinitialize(0, g_simtc.hnx); if (ret < 0) { ierr("ERROR: vnc_default_fbinitialize failed: %d\n", ret); goto errout_with_fb; } #endif /* Set the background to the configured background color */ iinfo("Set background color=%d\n", CONFIG_EXAMPLES_TOUCHSCREEN_BGCOLOR); color = CONFIG_EXAMPLES_TOUCHSCREEN_BGCOLOR; ret = nx_setbgcolor(g_simtc.hnx, &color); if (ret < 0) { ierr("ERROR: nx_setbgcolor failed: %d\n", ret); goto errout_with_nx; } /* Finally, initialize the touchscreen simulation on the X window */ ret = board_tsc_setup(minor); if (ret < 0) { ierr("ERROR: board_tsc_setup failed: %d\n", ret); goto errout_with_nx; } return OK; errout_with_nx: nx_close(g_simtc.hnx); goto errout; errout_with_fb: up_fbuninitialize(0); errout: return ret; }