2011-08-03 18:04:48 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* examples/nxlines/nxlines_main.c
|
|
|
|
*
|
2019-04-02 15:06:06 +02:00
|
|
|
* Copyright (C) 2011-2012, 2015-2017, 2019 Gregory Nutt. All rights
|
|
|
|
* reserved.
|
2012-05-13 17:14:53 +02:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2011-08-03 18:04:48 +02:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2015-04-09 22:23:31 +02:00
|
|
|
#include <sys/boardctl.h>
|
2011-08-03 18:04:48 +02:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2015-04-04 19:49:15 +02:00
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/board.h>
|
|
|
|
|
2011-08-03 18:04:48 +02:00
|
|
|
#include <nuttx/nx/nx.h>
|
|
|
|
#include <nuttx/nx/nxglib.h>
|
|
|
|
|
|
|
|
#include "nxlines.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Configuration ************************************************************/
|
|
|
|
/* If not specified, assume that the hardware supports one video plane */
|
|
|
|
|
|
|
|
#ifndef CONFIG_EXAMPLES_NXLINES_VPLANE
|
|
|
|
# define CONFIG_EXAMPLES_NXLINES_VPLANE 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* If not specified, assume that the hardware supports one LCD device */
|
|
|
|
|
|
|
|
#ifndef CONFIG_EXAMPLES_NXLINES_DEVNO
|
|
|
|
# define CONFIG_EXAMPLES_NXLINES_DEVNO 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct nxlines_data_s g_nxlines =
|
|
|
|
{
|
2017-10-15 00:52:20 +02:00
|
|
|
NULL, /* hnx */
|
|
|
|
NULL, /* hbkgd */
|
|
|
|
false, /* connected */
|
|
|
|
0, /* xres */
|
|
|
|
0, /* yres */
|
|
|
|
false, /* havpos */
|
|
|
|
SEM_INITIALIZER(0), /* eventsem */
|
|
|
|
NXEXIT_SUCCESS /* exit code */
|
2011-08-03 18:04:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxlines_initialize
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline int nxlines_initialize(void)
|
|
|
|
{
|
2017-10-15 00:52:20 +02:00
|
|
|
struct sched_param param;
|
|
|
|
pthread_t thread;
|
2016-04-22 21:38:06 +02:00
|
|
|
int ret;
|
2011-08-03 18:04:48 +02:00
|
|
|
|
2017-10-15 00:52:20 +02:00
|
|
|
/* Set the client task priority */
|
2015-04-16 15:39:00 +02:00
|
|
|
|
2017-10-15 00:52:20 +02:00
|
|
|
param.sched_priority = CONFIG_EXAMPLES_NXLINES_CLIENTPRIO;
|
|
|
|
ret = sched_setparam(0, ¶m);
|
2015-04-16 15:39:00 +02:00
|
|
|
if (ret < 0)
|
2011-08-03 18:04:48 +02:00
|
|
|
{
|
2017-10-15 00:52:20 +02:00
|
|
|
printf("nxlines_initialize: sched_setparam failed: %d\n" , ret);
|
2011-08-03 18:04:48 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2017-10-15 00:52:20 +02:00
|
|
|
/* Start the NX server kernel thread */
|
2015-04-16 15:39:00 +02:00
|
|
|
|
2017-10-15 00:52:20 +02:00
|
|
|
ret = boardctl(BOARDIOC_NX_START, 0);
|
2011-08-03 18:04:48 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2017-10-15 00:52:20 +02:00
|
|
|
printf("nxlines_initialize: Failed to start the NX server: %d\n", errno);
|
2011-08-03 18:04:48 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2017-10-15 00:52:20 +02:00
|
|
|
/* Connect to the server */
|
2011-08-03 18:04:48 +02:00
|
|
|
|
2017-10-15 00:52:20 +02:00
|
|
|
g_nxlines.hnx = nx_connect();
|
|
|
|
if (g_nxlines.hnx)
|
2011-08-03 18:04:48 +02:00
|
|
|
{
|
2017-10-15 00:52:20 +02:00
|
|
|
pthread_attr_t attr;
|
2016-04-14 20:23:52 +02:00
|
|
|
|
2017-10-15 00:52:20 +02:00
|
|
|
#ifdef CONFIG_VNCSERVER
|
|
|
|
/* Setup the VNC server to support keyboard/mouse inputs */
|
|
|
|
|
2019-04-02 15:06:06 +02:00
|
|
|
struct boardioc_vncstart_s vnc =
|
|
|
|
{
|
|
|
|
0, g_nxlines.hnx
|
|
|
|
};
|
|
|
|
|
|
|
|
ret = boardctl(BOARDIOC_VNC_START, (uintptr_t)&vnc);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
printf("boardctl(BOARDIOC_VNC_START) failed: %d\n", ret);
|
|
|
|
nx_disconnect(g_nxlines.hnx);
|
|
|
|
return ERROR;
|
|
|
|
}
|
2011-08-03 18:04:48 +02:00
|
|
|
#endif
|
2019-04-02 15:06:06 +02:00
|
|
|
|
2017-10-15 00:52:20 +02:00
|
|
|
/* Start a separate thread to listen for server events. This is probably
|
|
|
|
* the least efficient way to do this, but it makes this example flow more
|
|
|
|
* smoothly.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
pthread_attr_init(&attr);
|
2017-10-15 00:52:20 +02:00
|
|
|
param.sched_priority = CONFIG_EXAMPLES_NXLINES_LISTENERPRIO;
|
2020-01-02 13:09:50 +01:00
|
|
|
pthread_attr_setschedparam(&attr, ¶m);
|
|
|
|
pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NXLINES_LISTENER_STACKSIZE);
|
2017-10-15 00:52:20 +02:00
|
|
|
|
|
|
|
ret = pthread_create(&thread, &attr, nxlines_listener, NULL);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
printf("nxlines_initialize: pthread_create failed: %d\n", ret);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Don't return until we are connected to the server */
|
|
|
|
|
|
|
|
while (!g_nxlines.connected)
|
|
|
|
{
|
|
|
|
/* Wait for the listener thread to wake us up when we really
|
|
|
|
* are connected.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
sem_wait(&g_nxlines.eventsem);
|
2017-10-15 00:52:20 +02:00
|
|
|
}
|
2011-08-03 18:04:48 +02:00
|
|
|
}
|
2017-10-15 00:52:20 +02:00
|
|
|
else
|
2016-04-22 21:38:06 +02:00
|
|
|
{
|
2017-10-15 00:52:20 +02:00
|
|
|
printf("nxlines_initialize: nx_connect failed: %d\n", errno);
|
2016-04-22 21:38:06 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
2017-10-15 00:52:20 +02:00
|
|
|
|
2011-08-03 18:04:48 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-08-30 22:13:50 +02:00
|
|
|
* Name: nxlines_main
|
2011-08-03 18:04:48 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-06 17:23:23 +02:00
|
|
|
int main(int argc, FAR char *argv[])
|
2011-08-03 18:04:48 +02:00
|
|
|
{
|
|
|
|
nxgl_mxpixel_t color;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Initialize NX */
|
|
|
|
|
|
|
|
ret = nxlines_initialize();
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxlines_main: NX handle=%p\n", g_nxlines.hnx);
|
2011-08-03 18:04:48 +02:00
|
|
|
if (!g_nxlines.hnx || ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxlines_main: Failed to get NX handle: %d\n", errno);
|
2017-10-15 00:52:20 +02:00
|
|
|
g_nxlines.code = NXEXIT_INIT;
|
2011-08-03 18:04:48 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the background to the configured background color */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxlines_main: Set background color=%d\n",
|
|
|
|
CONFIG_EXAMPLES_NXLINES_BGCOLOR);
|
2011-08-03 18:04:48 +02:00
|
|
|
|
|
|
|
color = CONFIG_EXAMPLES_NXLINES_BGCOLOR;
|
|
|
|
ret = nx_setbgcolor(g_nxlines.hnx, &color);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxlines_main: nx_setbgcolor failed: %d\n", errno);
|
2011-08-03 18:04:48 +02:00
|
|
|
g_nxlines.code = NXEXIT_NXSETBGCOLOR;
|
|
|
|
goto errout_with_nx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the background window */
|
|
|
|
|
2012-05-13 17:14:53 +02:00
|
|
|
ret = nx_requestbkgd(g_nxlines.hnx, &g_nxlinescb, NULL);
|
2011-08-03 18:04:48 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxlines_main: nx_setbgcolor failed: %d\n", errno);
|
2011-08-03 18:04:48 +02:00
|
|
|
g_nxlines.code = NXEXIT_NXREQUESTBKGD;
|
|
|
|
goto errout_with_nx;
|
|
|
|
}
|
|
|
|
|
2017-10-16 15:13:38 +02:00
|
|
|
/* Wait until we have the screen resolution. */
|
2011-08-03 18:04:48 +02:00
|
|
|
|
|
|
|
while (!g_nxlines.havepos)
|
|
|
|
{
|
2020-01-02 13:09:50 +01:00
|
|
|
sem_wait(&g_nxlines.eventsem);
|
2011-08-03 18:04:48 +02:00
|
|
|
}
|
2017-10-15 00:52:20 +02:00
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("nxlines_main: Screen resolution (%d,%d)\n", g_nxlines.xres, g_nxlines.yres);
|
2011-08-03 18:04:48 +02:00
|
|
|
|
|
|
|
/* Now, say perform the lines (these test does not return so the remaining
|
2014-04-14 00:24:28 +02:00
|
|
|
* logic is cosmetic).
|
2011-08-03 18:04:48 +02:00
|
|
|
*/
|
|
|
|
|
2011-08-03 23:49:31 +02:00
|
|
|
nxlines_test(g_nxlines.hbkgd);
|
2011-08-03 18:04:48 +02:00
|
|
|
|
|
|
|
/* Release background */
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
nx_releasebkgd(g_nxlines.hbkgd);
|
2011-08-03 18:04:48 +02:00
|
|
|
|
|
|
|
/* Close NX */
|
|
|
|
|
|
|
|
errout_with_nx:
|
2017-10-15 00:52:20 +02:00
|
|
|
printf("nxhello_main: Disconnect from the server\n");
|
|
|
|
nx_disconnect(g_nxlines.hnx);
|
|
|
|
|
2011-08-03 18:04:48 +02:00
|
|
|
errout:
|
|
|
|
return g_nxlines.code;
|
|
|
|
}
|