mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 03:33:34 +08:00
Resync new repository with old repo r5166
git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5153 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
config EXAMPLES_NX
|
||||
bool "NX graphics example"
|
||||
default n
|
||||
---help---
|
||||
Enable the NX graphics example
|
||||
|
||||
if EXAMPLES_NX
|
||||
endif
|
||||
@@ -0,0 +1,108 @@
|
||||
############################################################################
|
||||
# apps/examples/nx/Makefile
|
||||
#
|
||||
# Copyright (C) 2009-2011 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/.config
|
||||
-include $(TOPDIR)/Make.defs
|
||||
include $(APPDIR)/Make.defs
|
||||
|
||||
# NuttX NX Graphics Example.
|
||||
|
||||
ASRCS =
|
||||
CSRCS = nx_main.c nx_events.c nx_kbdin.c
|
||||
ifeq ($(CONFIG_NX_MULTIUSER),y)
|
||||
CSRCS += nx_server.c
|
||||
endif
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
BIN = "${shell cygpath -w $(APPDIR)/libapps$(LIBEXT)}"
|
||||
else
|
||||
BIN = "$(APPDIR)/libapps$(LIBEXT)"
|
||||
endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# NX built-in application info
|
||||
|
||||
APPNAME = nx
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 2048
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: context clean depend distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
.built: $(OBJS)
|
||||
@( for obj in $(OBJS) ; do \
|
||||
$(call ARCHIVE, $(BIN), $${obj}); \
|
||||
done ; )
|
||||
@touch .built
|
||||
|
||||
.context:
|
||||
ifeq ($(CONFIG_EXAMPLES_NX_BUILTIN),y)
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
@touch $@
|
||||
endif
|
||||
|
||||
context: .context
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
@rm -f *.o *~ .*.swp .built
|
||||
$(call CLEAN)
|
||||
|
||||
distclean: clean
|
||||
@rm -f Make.dep .depend
|
||||
|
||||
-include Make.dep
|
||||
@@ -0,0 +1,337 @@
|
||||
/****************************************************************************
|
||||
* examples/nx/nx_events.c
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <semaphore.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxtk.h>
|
||||
#include "nx_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void nxeg_redraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
bool morem, FAR void *arg);
|
||||
static void nxeg_position(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
|
||||
FAR const struct nxgl_point_s *pos,
|
||||
FAR const struct nxgl_rect_s *bounds,
|
||||
FAR void *arg);
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
static void nxeg_mousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg);
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static void nxeg_tbredraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
bool morem, FAR void *arg);
|
||||
static void nxeg_tbposition(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
|
||||
FAR const struct nxgl_point_s *pos,
|
||||
FAR const struct nxgl_rect_s *bounds,
|
||||
FAR void *arg);
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
static void nxeg_tbmousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
const struct nx_callback_s g_nxcb =
|
||||
{
|
||||
nxeg_redraw, /* redraw */
|
||||
nxeg_position /* position */
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
, nxeg_mousein /* mousein */
|
||||
#endif
|
||||
#ifdef CONFIG_NX_KBD
|
||||
, nxeg_kbdin /* my kbdin */
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
const struct nx_callback_s g_tbcb =
|
||||
{
|
||||
nxeg_tbredraw, /* redraw */
|
||||
nxeg_tbposition /* position */
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
, nxeg_tbmousein /* mousein */
|
||||
#endif
|
||||
#ifdef CONFIG_NX_KBD
|
||||
, nxeg_tbkbdin /* my kbdin */
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_fillwindow
|
||||
****************************************************************************/
|
||||
|
||||
static inline void nxeg_fillwindow(NXEGWINDOW hwnd,
|
||||
FAR const struct nxgl_rect_s *rect,
|
||||
FAR struct nxeg_state_s *st)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
ret = nx_fill(hwnd, rect, st->color);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_fillwindow: nx_fill failed: %d\n", errno);
|
||||
}
|
||||
#else
|
||||
ret = nxtk_fillwindow(hwnd, rect, st->color);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_fillwindow: nxtk_fillwindow failed: %d\n", errno);
|
||||
}
|
||||
#endif
|
||||
#ifdef CONFIG_NX_KBD
|
||||
nxeg_filltext(hwnd, rect, st);
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_fillwindow
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static inline void nxeg_filltoolbar(NXTKWINDOW htb,
|
||||
FAR const struct nxgl_rect_s *rect,
|
||||
nxgl_mxpixel_t color[CONFIG_NX_NPLANES])
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = nxtk_filltoolbar(htb, rect, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_filltoolbar: nxtk_filltoolbar failed: %d\n", errno);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_redraw
|
||||
****************************************************************************/
|
||||
|
||||
static void nxeg_redraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
bool more, FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
message("nxeg_redraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
|
||||
st->wnum, hwnd,
|
||||
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
|
||||
more ? "true" : "false");
|
||||
|
||||
nxeg_fillwindow(hwnd, rect, st);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_position
|
||||
****************************************************************************/
|
||||
|
||||
static void nxeg_position(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
|
||||
FAR const struct nxgl_point_s *pos,
|
||||
FAR const struct nxgl_rect_s *bounds,
|
||||
FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
|
||||
/* Report the position */
|
||||
|
||||
message("nxeg_position%d: hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
|
||||
st->wnum, hwnd, size->w, size->h, pos->x, pos->y,
|
||||
bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
|
||||
|
||||
/* Have we picked off the window bounds yet? */
|
||||
|
||||
if (!b_haveresolution)
|
||||
{
|
||||
/* Save the window limits (these should be the same for all places and all windows */
|
||||
|
||||
g_xres = bounds->pt2.x;
|
||||
g_yres = bounds->pt2.y;
|
||||
|
||||
b_haveresolution = true;
|
||||
sem_post(&g_semevent);
|
||||
message("nxeg_position2: Have xres=%d yres=%d\n", g_xres, g_yres);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_mousein
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
static void nxeg_mousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
message("nxeg_mousein%d: hwnd=%p pos=(%d,%d) button=%02x\n",
|
||||
st->wnum, hwnd, pos->x, pos->y, buttons);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_tbredraw
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static void nxeg_tbredraw(NXEGWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
bool more, FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
message("nxeg_tbredraw%d: hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
|
||||
st->wnum, hwnd,
|
||||
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
|
||||
more ? "true" : "false");
|
||||
nxeg_filltoolbar(hwnd, rect, g_tbcolor);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_position
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static void nxeg_tbposition(NXEGWINDOW hwnd, FAR const struct nxgl_size_s *size,
|
||||
FAR const struct nxgl_point_s *pos,
|
||||
FAR const struct nxgl_rect_s *bounds,
|
||||
FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
|
||||
/* Report the position */
|
||||
|
||||
message("nxeg_ptbosition%d: hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
|
||||
st->wnum, hwnd, size->w, size->h, pos->x, pos->y,
|
||||
bounds->pt1.x, bounds->pt1.y, bounds->pt2.x, bounds->pt2.y);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_tbmousein
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
static void nxeg_tbmousein(NXEGWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
|
||||
message("nxeg_tbmousein%d: hwnd=%p pos=(%d,%d) button=%02x\n",
|
||||
st->wnum, hwnd, pos->x, pos->y, buttons);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nx_listenerthread
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX_MULTIUSER
|
||||
FAR void *nx_listenerthread(FAR void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Process events forever */
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Handle the next event. If we were configured blocking, then
|
||||
* we will stay right here until the next event is received. Since
|
||||
* we have dedicated a while thread to servicing events, it would
|
||||
* be most natural to also select CONFIG_NX_BLOCKING -- if not, the
|
||||
* following would be a tight infinite loop (unless we added addition
|
||||
* logic with nx_eventnotify and sigwait to pace it).
|
||||
*/
|
||||
|
||||
ret = nx_eventhandler(g_hnx);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* An error occurred... assume that we have lost connection with
|
||||
* the server.
|
||||
*/
|
||||
|
||||
message("nx_listenerthread: Lost server connection: %d\n", errno);
|
||||
exit(NXEXIT_LOSTSERVERCONN);
|
||||
}
|
||||
|
||||
/* If we received a message, we must be connected */
|
||||
|
||||
if (!g_connected)
|
||||
{
|
||||
g_connected = true;
|
||||
sem_post(&g_semevent);
|
||||
message("nx_listenerthread: Connected\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,317 @@
|
||||
/****************************************************************************
|
||||
* examples/nx/nx_internal.h
|
||||
*
|
||||
* Copyright (C) 2008-2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __EXAMPLES_NX_NX_INTERNAL_H
|
||||
#define __EXAMPLES_NX_NX_INTERNAL_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxtk.h>
|
||||
#include <nuttx/nx/nxfonts.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_NX
|
||||
# error "NX is not enabled (CONFIG_NX)"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_VPLANE
|
||||
# define CONFIG_EXAMPLES_NX_VPLANE 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_BPP
|
||||
# define CONFIG_EXAMPLES_NX_BPP 32
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_BGCOLOR
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NX_BGCOLOR 0x007b68ee
|
||||
# elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NX_BGCOLOR 0x7b5d
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NX_BGCOLOR ' '
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_COLOR1
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NX_COLOR1 0x00e6e6fa
|
||||
# elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NX_COLOR1 0xe73f
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NX_COLOR1 '1'
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_COLOR2
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NX_COLOR2 0x00dcdcdc
|
||||
# elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NX_COLOR2 0xdefb
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NX_COLOR2 '2'
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_TBCOLOR
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NX_TBCOLOR 0x00a9a9a9
|
||||
# elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NX_TBCOLOR 0xad55
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NX_TBCOLOR 'T'
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_FONTID
|
||||
# define CONFIG_EXAMPLES_NX_FONTID NXFONT_DEFAULT
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_FONTCOLOR
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 24 || CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NX_FONTCOLOR 0x00000000
|
||||
# elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NX_FONTCOLOR 0x0000
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NX_FONTCOLOR 'F'
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT
|
||||
# define CONFIG_EXAMPLES_NX_TOOLBAR_HEIGHT 16
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NX_MULTIUSER
|
||||
# ifdef CONFIG_DISABLE_MQUEUE
|
||||
# error "The multi-threaded example requires MQ support (CONFIG_DISABLE_MQUEUE=n)"
|
||||
# endif
|
||||
# ifdef CONFIG_DISABLE_SIGNALS
|
||||
# error "This example requires signal support (CONFIG_DISABLE_SIGNALS=n)"
|
||||
# endif
|
||||
# ifdef CONFIG_DISABLE_PTHREAD
|
||||
# error "This example requires pthread support (CONFIG_DISABLE_PTHREAD=n)"
|
||||
# endif
|
||||
# ifndef CONFIG_NX_BLOCKING
|
||||
# error "This example depends on CONFIG_NX_BLOCKING"
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NX_STACKSIZE
|
||||
# define CONFIG_EXAMPLES_NX_STACKSIZE 2048
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NX_LISTENERPRIO
|
||||
# define CONFIG_EXAMPLES_NX_LISTENERPRIO 100
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NX_CLIENTPRIO
|
||||
# define CONFIG_EXAMPLES_NX_CLIENTPRIO 100
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NX_SERVERPRIO
|
||||
# define CONFIG_EXAMPLES_NX_SERVERPRIO 120
|
||||
# endif
|
||||
# ifndef CONFIG_EXAMPLES_NX_NOTIFYSIGNO
|
||||
# define CONFIG_EXAMPLES_NX_NOTIFYSIGNO 4
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
# define NXEGWINDOW NXWINDOW
|
||||
#else
|
||||
# define NXEGWINDOW NXTKWINDOW
|
||||
#endif
|
||||
|
||||
#define NXTK_MAXKBDCHARS 16
|
||||
|
||||
/* Debug ********************************************************************/
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message(...) lib_lowprintf(__VA_ARGS__)
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message(...) printf(__VA_ARGS__)
|
||||
# define msgflush() fflush(stdout)
|
||||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG
|
||||
# define message lib_lowprintf
|
||||
# define msgflush()
|
||||
# else
|
||||
# define message printf
|
||||
# define msgflush() fflush(stdout)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
enum exitcode_e
|
||||
{
|
||||
NXEXIT_SUCCESS = 0,
|
||||
NXEXIT_SIGPROCMASK,
|
||||
NXEXIT_SCHEDSETPARAM,
|
||||
NXEXIT_EVENTNOTIFY,
|
||||
NXEXIT_TASKCREATE,
|
||||
NXEXIT_PTHREADCREATE,
|
||||
NXEXIT_EXTINITIALIZE,
|
||||
NXEXIT_FBINITIALIZE,
|
||||
NXEXIT_FBGETVPLANE,
|
||||
NXEXIT_LCDINITIALIZE,
|
||||
NXEXIT_LCDGETDEV,
|
||||
NXEXIT_NXOPEN,
|
||||
NXEXIT_FONTOPEN,
|
||||
NXEXIT_NXOPENTOOLBAR,
|
||||
NXEXIT_NXCONNECT,
|
||||
NXEXIT_NXSETBGCOLOR,
|
||||
NXEXIT_NXOPENWINDOW,
|
||||
NXEXIT_NXSETSIZE,
|
||||
NXEXIT_NXSETPOSITION,
|
||||
NXEXIT_NXLOWER,
|
||||
NXEXIT_NXRAISE,
|
||||
NXEXIT_NXCLOSEWINDOW,
|
||||
NXEXIT_LOSTSERVERCONN
|
||||
};
|
||||
|
||||
/* Describes one cached glyph bitmap */
|
||||
|
||||
struct nxeg_glyph_s
|
||||
{
|
||||
uint8_t code; /* Character code */
|
||||
uint8_t height; /* Height of this glyph (in rows) */
|
||||
uint8_t width; /* Width of this glyph (in pixels) */
|
||||
uint8_t stride; /* Width of the glyph row (in bytes) */
|
||||
FAR uint8_t *bitmap; /* Allocated bitmap memory */
|
||||
};
|
||||
|
||||
/* Describes on character on the display */
|
||||
|
||||
struct nxeg_bitmap_s
|
||||
{
|
||||
struct nxgl_rect_s bounds; /* Size/position of bitmap */
|
||||
FAR const struct nxeg_glyph_s *glyph; /* The cached glyph */
|
||||
};
|
||||
|
||||
/* Describes the overall state of on one window */
|
||||
|
||||
struct nxeg_state_s
|
||||
{
|
||||
uint8_t wnum; /* Window number */
|
||||
nxgl_mxpixel_t color[CONFIG_NX_NPLANES]; /* Window color */
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
uint8_t height; /* Max height of a font in pixels */
|
||||
uint8_t width; /* Max width of a font in pixels */
|
||||
uint8_t spwidth; /* The width of a space */
|
||||
|
||||
uint8_t nchars; /* Number of KBD chars received */
|
||||
uint8_t nglyphs; /* Number of glyphs cached */
|
||||
|
||||
struct nxeg_bitmap_s bm[NXTK_MAXKBDCHARS];
|
||||
struct nxeg_glyph_s glyph[NXTK_MAXKBDCHARS];
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Variables
|
||||
****************************************************************************/
|
||||
|
||||
/* The connecton handle */
|
||||
|
||||
extern NXHANDLE g_hnx;
|
||||
|
||||
/* NX callback vtables */
|
||||
|
||||
extern const struct nx_callback_s g_nxcb;
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
extern const struct nx_callback_s g_tbcb;
|
||||
#endif
|
||||
|
||||
/* The font handle */
|
||||
|
||||
extern NXHANDLE g_fonthandle;
|
||||
|
||||
/* The screen resolution */
|
||||
|
||||
extern nxgl_coord_t g_xres;
|
||||
extern nxgl_coord_t g_yres;
|
||||
|
||||
extern bool b_haveresolution;
|
||||
#ifdef CONFIG_NX_MULTIUSER
|
||||
extern bool g_connected;
|
||||
#endif
|
||||
extern sem_t g_semevent;
|
||||
|
||||
/* Colors used to fill window 1 & 2 */
|
||||
|
||||
extern nxgl_mxpixel_t g_color1[CONFIG_NX_NPLANES];
|
||||
extern nxgl_mxpixel_t g_color2[CONFIG_NX_NPLANES];
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
extern nxgl_mxpixel_t g_tbcolor[CONFIG_NX_NPLANES];
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_EXTERNINIT
|
||||
extern FAR NX_DRIVERTYPE *up_nxdrvinit(unsigned int devno);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NX) && defined(CONFIG_NX_MULTIUSER)
|
||||
extern int nx_servertask(int argc, char *argv[]);
|
||||
extern FAR void *nx_listenerthread(FAR void *arg);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
extern void nxeg_kbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch, FAR void *arg);
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
extern void nxeg_tbkbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch, FAR void *arg);
|
||||
#endif
|
||||
extern void nxeg_filltext(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
FAR struct nxeg_state_s *st);
|
||||
#endif
|
||||
|
||||
#endif /* __EXAMPLES_NX_NX_INTERNAL_H */
|
||||
@@ -0,0 +1,467 @@
|
||||
/****************************************************************************
|
||||
* examples/nx/nx_kbdin.c
|
||||
*
|
||||
* Copyright (C) 2008, 2010-2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxtk.h>
|
||||
#include <nuttx/nx/nxfonts.h>
|
||||
|
||||
#include "nx_internal.h"
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Select renderer -- Some additional logic would be required to support
|
||||
* pixel depths that are not directly addressable (1,2,4, and 24).
|
||||
*/
|
||||
|
||||
#if CONFIG_EXAMPLES_NX_BPP == 1
|
||||
# define RENDERER nxf_convert_1bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 2
|
||||
# define RENDERER nxf_convert_2bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 4
|
||||
# define RENDERER nxf_convert_4bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 8
|
||||
# define RENDERER nxf_convert_8bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 16
|
||||
# define RENDERER nxf_convert_16bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 24
|
||||
# define RENDERER nxf_convert_24bpp
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 32
|
||||
# define RENDERER nxf_convert_32bpp
|
||||
#else
|
||||
# error "Unsupported CONFIG_EXAMPLES_NX_BPP"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_fillchar
|
||||
****************************************************************************/
|
||||
|
||||
static void nxeg_fillchar(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
FAR const struct nxeg_bitmap_s *bm)
|
||||
{
|
||||
FAR void *src = (FAR void *)bm->glyph->bitmap;
|
||||
struct nxgl_rect_s intersection;
|
||||
int ret;
|
||||
|
||||
/* Handle the special case of spaces which have no glyph bitmap */
|
||||
|
||||
if (src)
|
||||
{
|
||||
/* Get the intersection of the redraw region and the character bitmap */
|
||||
|
||||
nxgl_rectintersect(&intersection, rect, &bm->bounds);
|
||||
if (!nxgl_nullrect(&intersection))
|
||||
{
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
ret = nxtk_bitmapwindow((NXTKWINDOW)hwnd, &intersection, (FAR const void **)&src,
|
||||
&bm->bounds.pt1,
|
||||
(unsigned int)bm->glyph->stride);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_fillchar: nxtk_bitmapwindow failed: %d\n", errno);
|
||||
}
|
||||
#else
|
||||
ret = nx_bitmap((NXWINDOW)hwnd, &intersection, &src,
|
||||
&bm->bounds.pt1,
|
||||
(unsigned int)bm->glyph->stride);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_fillchar: nx_bitmapwindow failed: %d\n", errno);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_renderglyph
|
||||
****************************************************************************/
|
||||
|
||||
static inline FAR const struct nxeg_glyph_s *
|
||||
nxeg_renderglyph(FAR struct nxeg_state_s *st,
|
||||
FAR const struct nx_fontbitmap_s *bm, uint8_t ch)
|
||||
{
|
||||
FAR struct nxeg_glyph_s *glyph = NULL;
|
||||
FAR nxgl_mxpixel_t *ptr;
|
||||
#if CONFIG_EXAMPLES_NX_BPP < 8
|
||||
nxgl_mxpixel_t pixel;
|
||||
#endif
|
||||
int bmsize;
|
||||
int row;
|
||||
int col;
|
||||
int ret;
|
||||
|
||||
/* Make sure that there is room for another glyph */
|
||||
|
||||
message("nxeg_renderglyph: ch=%02x\n", ch);
|
||||
if (st->nglyphs < NXTK_MAXKBDCHARS)
|
||||
{
|
||||
/* Allocate the glyph */
|
||||
|
||||
glyph = &st->glyph[st->nglyphs];
|
||||
glyph->code = ch;
|
||||
|
||||
/* Get the dimensions of the glyph */
|
||||
|
||||
glyph->width = bm->metric.width + bm->metric.xoffset;
|
||||
glyph->height = bm->metric.height + bm->metric.yoffset;
|
||||
|
||||
/* Allocate memory to hold the glyph with its offsets */
|
||||
|
||||
glyph->stride = (glyph->width * CONFIG_EXAMPLES_NX_BPP + 7) / 8;
|
||||
bmsize = glyph->stride * glyph->height;
|
||||
glyph->bitmap = (FAR uint8_t *)malloc(bmsize);
|
||||
|
||||
if (glyph->bitmap)
|
||||
{
|
||||
/* Initialize the glyph memory to the background color */
|
||||
|
||||
#if CONFIG_EXAMPLES_NX_BPP < 8
|
||||
pixel = st->color[0];
|
||||
# if CONFIG_EXAMPLES_NX_BPP == 1
|
||||
/* Pack 1-bit pixels into a 2-bits */
|
||||
|
||||
pixel &= 0x01;
|
||||
pixel = (pixel) << 1 |pixel;
|
||||
# endif
|
||||
# if CONFIG_EXAMPLES_NX_BPP < 4
|
||||
/* Pack 2-bit pixels into a nibble */
|
||||
|
||||
pixel &= 0x03;
|
||||
pixel = (pixel) << 2 |pixel;
|
||||
# endif
|
||||
|
||||
/* Pack 4-bit nibbles into a byte */
|
||||
|
||||
pixel &= 0x0f;
|
||||
pixel = (pixel) << 4 | pixel;
|
||||
|
||||
ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap;
|
||||
for (row = 0; row < glyph->height; row++)
|
||||
{
|
||||
for (col = 0; col < glyph->stride; col++)
|
||||
{
|
||||
/* Transfer the packed bytes into the buffer */
|
||||
|
||||
*ptr++ = pixel;
|
||||
}
|
||||
}
|
||||
|
||||
#elif CONFIG_EXAMPLES_NX_BPP == 24
|
||||
# error "Additional logic is needed here for 24bpp support"
|
||||
|
||||
#else /* CONFIG_EXAMPLES_NX_BPP = {8,16,32} */
|
||||
|
||||
ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap;
|
||||
for (row = 0; row < glyph->height; row++)
|
||||
{
|
||||
/* Just copy the color value into the glyph memory */
|
||||
|
||||
for (col = 0; col < glyph->width; col++)
|
||||
{
|
||||
*ptr++ = st->color[0];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Then render the glyph into the allocated memory */
|
||||
|
||||
ret = RENDERER((FAR nxgl_mxpixel_t*)glyph->bitmap,
|
||||
glyph->height, glyph->width, glyph->stride,
|
||||
bm, CONFIG_EXAMPLES_NX_FONTCOLOR);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* Actually, the RENDERER never returns a failure */
|
||||
|
||||
message("nxeg_renderglyph: RENDERER failed\n");
|
||||
free(glyph->bitmap);
|
||||
glyph->bitmap = NULL;
|
||||
glyph = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Make it permanent */
|
||||
|
||||
st->nglyphs++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return glyph;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_addspace
|
||||
****************************************************************************/
|
||||
|
||||
static inline FAR const struct nxeg_glyph_s *
|
||||
nxeg_addspace(FAR struct nxeg_state_s *st, uint8_t ch)
|
||||
{
|
||||
FAR struct nxeg_glyph_s *glyph = NULL;
|
||||
|
||||
/* Make sure that there is room for another glyph */
|
||||
|
||||
if (st->nglyphs < NXTK_MAXKBDCHARS)
|
||||
{
|
||||
/* Allocate the NULL glyph */
|
||||
|
||||
glyph = &st->glyph[st->nglyphs];
|
||||
memset(glyph, 0, sizeof(struct nxeg_glyph_s));
|
||||
|
||||
glyph->code = ' ';
|
||||
glyph->width = st->spwidth;
|
||||
|
||||
st->nglyphs++;
|
||||
}
|
||||
return glyph;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_findglyph
|
||||
****************************************************************************/
|
||||
|
||||
static FAR const struct nxeg_glyph_s *
|
||||
nxeg_findglyph(FAR struct nxeg_state_s *st, uint8_t ch)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* First, try to find the glyph in the cache of pre-rendered glyphs */
|
||||
|
||||
for (i = 0; i < st->nglyphs; i++)
|
||||
{
|
||||
if (st->glyph[i].code == ch)
|
||||
{
|
||||
return &st->glyph[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_getglyph
|
||||
****************************************************************************/
|
||||
|
||||
static FAR const struct nxeg_glyph_s *
|
||||
nxeg_getglyph(FAR struct nxeg_state_s *st, uint8_t ch)
|
||||
{
|
||||
FAR const struct nxeg_glyph_s *glyph;
|
||||
FAR const struct nx_fontbitmap_s *bm;
|
||||
|
||||
/* First, try to find the glyph in the cache of pre-rendered glyphs */
|
||||
|
||||
glyph = nxeg_findglyph(st, ch);
|
||||
if (!glyph)
|
||||
{
|
||||
/* No, it is not cached... Does the code map to a glyph? */
|
||||
|
||||
bm = nxf_getbitmap(g_fonthandle, ch);
|
||||
if (!bm)
|
||||
{
|
||||
/* No, there is no glyph for this code. Use space */
|
||||
|
||||
glyph = nxeg_findglyph(st, ' ');
|
||||
if (!glyph)
|
||||
{
|
||||
/* There isn't fake glyph for ' ' yet... create one */
|
||||
|
||||
glyph = nxeg_addspace(st, ' ');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
glyph = nxeg_renderglyph(st, bm, ch);
|
||||
}
|
||||
}
|
||||
return glyph;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_addchar
|
||||
****************************************************************************/
|
||||
|
||||
static FAR const struct nxeg_bitmap_s *
|
||||
nxeg_addchar(FAR struct nxeg_state_s *st, uint8_t ch)
|
||||
{
|
||||
FAR struct nxeg_bitmap_s *bm = NULL;
|
||||
FAR struct nxeg_bitmap_s *bmleft;
|
||||
nxgl_coord_t leftx;
|
||||
|
||||
/* Is there space for another character on the display? */
|
||||
|
||||
if (st->nchars < NXTK_MAXKBDCHARS)
|
||||
{
|
||||
/* Yes, setup the bitmap */
|
||||
|
||||
bm = &st->bm[st->nchars];
|
||||
|
||||
/* Find the matching glyph */
|
||||
|
||||
bm->glyph = nxeg_getglyph(st, ch);
|
||||
if (!bm->glyph)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Set up the bounds for the bitmap */
|
||||
|
||||
if (st->nchars <= 0)
|
||||
{
|
||||
/* The first character is one space from the left */
|
||||
|
||||
leftx = st->spwidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Otherwise, it is to the left of the preceding char */
|
||||
|
||||
bmleft = &st->bm[st->nchars-1];
|
||||
leftx = bmleft->bounds.pt2.x + 1;
|
||||
}
|
||||
|
||||
bm->bounds.pt1.x = leftx;
|
||||
bm->bounds.pt1.y = 2;
|
||||
bm->bounds.pt2.x = leftx + bm->glyph->width - 1;
|
||||
bm->bounds.pt2.y = 2 + bm->glyph->height - 1;
|
||||
|
||||
st->nchars++;
|
||||
}
|
||||
return bm;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_addchars
|
||||
****************************************************************************/
|
||||
|
||||
static inline void nxeg_addchars(NXWINDOW hwnd, FAR struct nxeg_state_s *st,
|
||||
uint8_t nch, FAR const uint8_t *ch)
|
||||
{
|
||||
FAR const struct nxeg_bitmap_s *bm;
|
||||
|
||||
while (nch--)
|
||||
{
|
||||
bm = nxeg_addchar(st, *ch++);
|
||||
if (bm)
|
||||
{
|
||||
nxeg_fillchar(hwnd, &bm->bounds, bm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_kbdin
|
||||
****************************************************************************/
|
||||
|
||||
void nxeg_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
|
||||
FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
message("nxeg_kbdin%d: hwnd=%p nch=%d\n", st->wnum, hwnd, nch);
|
||||
nxeg_addchars(hwnd, st, nch, ch);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_tbkbdin
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
void nxeg_tbkbdin(NXWINDOW hwnd, uint8_t nch, const uint8_t *ch, FAR void *arg)
|
||||
{
|
||||
FAR struct nxeg_state_s *st = (FAR struct nxeg_state_s *)arg;
|
||||
message("nxeg_tbkbdin: ERROR -- toolbar should not received keyboard input\n");
|
||||
message("nxeg_tbkbdin%d: hwnd=%p nch=%d\n", st->wnum, hwnd, nch);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_filltext
|
||||
****************************************************************************/
|
||||
|
||||
void nxeg_filltext(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
FAR struct nxeg_state_s *st)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Fill each character on the display (Only the characters within rect
|
||||
* will actually be redrawn).
|
||||
*/
|
||||
|
||||
for (i = 0; i < st->nchars; i++)
|
||||
{
|
||||
nxeg_fillchar(hwnd, rect, &st->bm[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NX_KBD */
|
||||
@@ -0,0 +1,900 @@
|
||||
/****************************************************************************
|
||||
* examples/nx/nx_main.c
|
||||
*
|
||||
* Copyright (C) 2008-2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <sched.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#ifdef CONFIG_NX_LCDDRIVER
|
||||
# include <nuttx/lcd/lcd.h>
|
||||
#else
|
||||
# include <nuttx/fb.h>
|
||||
#endif
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxtk.h>
|
||||
#include <nuttx/nx/nxfonts.h>
|
||||
|
||||
#include "nx_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
/* If not specified, assume that the hardware supports one video plane */
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_VPLANE
|
||||
# define CONFIG_EXAMPLES_NX_VPLANE 0
|
||||
#endif
|
||||
|
||||
/* If not specified, assume that the hardware supports one LCD device */
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_DEVNO
|
||||
# define CONFIG_EXAMPLES_NX_DEVNO 0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static int g_exitcode = NXEXIT_SUCCESS;
|
||||
|
||||
static struct nxeg_state_s g_wstate[2];
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
static const uint8_t g_kbdmsg1[] = "NuttX is cool!";
|
||||
static const uint8_t g_kbdmsg2[] = "NuttX is fun!";
|
||||
#endif
|
||||
|
||||
/* The font handle */
|
||||
|
||||
NXHANDLE g_fonthandle;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* The connecton handler */
|
||||
|
||||
NXHANDLE g_hnx = NULL;
|
||||
|
||||
/* The screen resolution */
|
||||
|
||||
nxgl_coord_t g_xres;
|
||||
nxgl_coord_t g_yres;
|
||||
|
||||
bool b_haveresolution = false;
|
||||
#ifdef CONFIG_NX_MULTIUSER
|
||||
bool g_connected = false;
|
||||
#endif
|
||||
sem_t g_semevent = {0};
|
||||
|
||||
/* Colors used to fill window 1 & 2 */
|
||||
|
||||
nxgl_mxpixel_t g_color1[CONFIG_NX_NPLANES];
|
||||
nxgl_mxpixel_t g_color2[CONFIG_NX_NPLANES];
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
nxgl_mxpixel_t g_tbcolor[CONFIG_NX_NPLANES];
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_drivemouse
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX_MOUSE
|
||||
static void nxeg_drivemouse(void)
|
||||
{
|
||||
nxgl_coord_t x;
|
||||
nxgl_coord_t y;
|
||||
nxgl_coord_t xstep = g_xres / 8;
|
||||
nxgl_coord_t ystep = g_yres / 8;
|
||||
|
||||
for (x = 0; x < g_xres; x += xstep)
|
||||
{
|
||||
for (y = 0; y < g_yres; y += ystep)
|
||||
{
|
||||
message("nxeg_drivemouse: Mouse left button at (%d,%d)\n", x, y);
|
||||
(void)nx_mousein(g_hnx, x, y, NX_MOUSE_LEFTBUTTON);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_initstate
|
||||
****************************************************************************/
|
||||
|
||||
static void nxeg_initstate(FAR struct nxeg_state_s *st, int wnum,
|
||||
nxgl_mxpixel_t color)
|
||||
{
|
||||
#ifdef CONFIG_NX_KBD
|
||||
FAR const struct nx_font_s *fontset;
|
||||
#endif
|
||||
|
||||
/* Initialize the window number (used for debug output only) and color
|
||||
* (used for redrawing the window)
|
||||
*/
|
||||
|
||||
st->wnum = wnum;
|
||||
st->color[0] = color;
|
||||
|
||||
/* Get information about the font set being used and save this in the
|
||||
* state structure
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
fontset = nxf_getfontset(g_fonthandle);
|
||||
st->nchars = 0;
|
||||
st->nglyphs = 0;
|
||||
st->height = fontset->mxheight;
|
||||
st->width = fontset->mxwidth;
|
||||
st->spwidth = fontset->spwidth;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_freestate
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static void nxeg_freestate(FAR struct nxeg_state_s *st)
|
||||
{
|
||||
#ifdef CONFIG_NX_KBD
|
||||
int i;
|
||||
|
||||
if (st)
|
||||
{
|
||||
for (i = 0; i < st->nglyphs; i++)
|
||||
{
|
||||
if (st->glyph[i].bitmap)
|
||||
{
|
||||
free(st->glyph[i].bitmap);
|
||||
}
|
||||
st->glyph[i].bitmap = NULL;
|
||||
}
|
||||
st->nchars = 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_openwindow
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static inline NXEGWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb,
|
||||
FAR struct nxeg_state_s *state)
|
||||
{
|
||||
NXEGWINDOW hwnd;
|
||||
|
||||
hwnd = nx_openwindow(g_hnx, cb, (FAR void *)state);
|
||||
if (!hwnd)
|
||||
{
|
||||
message("nxeg_openwindow: nx_openwindow failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXOPENWINDOW;
|
||||
}
|
||||
return hwnd;
|
||||
}
|
||||
#else
|
||||
static inline NXEGWINDOW nxeg_openwindow(FAR const struct nx_callback_s *cb,
|
||||
FAR struct nxeg_state_s *state)
|
||||
{
|
||||
NXEGWINDOW hwnd;
|
||||
|
||||
hwnd = nxtk_openwindow(g_hnx, cb, (FAR void *)state);
|
||||
if (!hwnd)
|
||||
{
|
||||
message("nxeg_openwindow: nxtk_openwindow failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXOPENWINDOW;
|
||||
}
|
||||
return hwnd;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_closewindow
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static inline int nxeg_closewindow(NXEGWINDOW hwnd, FAR struct nxeg_state_s *state)
|
||||
{
|
||||
int ret = nx_closewindow(hwnd);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_closewindow: nx_closewindow failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXCLOSEWINDOW;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
static inline int nxeg_closewindow(NXEGWINDOW hwnd, FAR struct nxeg_state_s *state)
|
||||
{
|
||||
int ret = nxtk_closewindow(hwnd);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_closewindow: nxtk_closewindow failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXCLOSEWINDOW;
|
||||
}
|
||||
nxeg_freestate(state);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_setsize
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static inline int nxeg_setsize(NXEGWINDOW hwnd, FAR struct nxgl_size_s *size)
|
||||
{
|
||||
int ret = nx_setsize(hwnd, size);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_setsize: nx_setsize failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXSETSIZE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
static inline int nxeg_setsize(NXEGWINDOW hwnd, FAR struct nxgl_size_s *size)
|
||||
{
|
||||
int ret = nxtk_setsize(hwnd, size);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_setsize: nxtk_setsize failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXSETSIZE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_setposition
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static inline int nxeg_setposition(NXEGWINDOW hwnd, FAR struct nxgl_point_s *pos)
|
||||
{
|
||||
int ret = nx_setposition(hwnd, pos);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_setposition: nx_setposition failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXSETPOSITION;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
static inline int nxeg_setposition(NXEGWINDOW hwnd, FAR struct nxgl_point_s *pos)
|
||||
{
|
||||
int ret = nxtk_setposition(hwnd, pos);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_setposition: nxtk_setposition failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXSETPOSITION;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeq_opentoolbar
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static inline int nxeq_opentoolbar(NXEGWINDOW hwnd, nxgl_coord_t height,
|
||||
FAR const struct nx_callback_s *cb,
|
||||
FAR struct nxeg_state_s *state)
|
||||
{
|
||||
int ret;
|
||||
ret = nxtk_opentoolbar(hwnd, height, cb, (FAR void *)state);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeq_opentoolbar: nxtk_opentoolbar failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXOPENTOOLBAR;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_lower
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static inline int nxeg_lower(NXEGWINDOW hwnd)
|
||||
{
|
||||
int ret = nx_lower(hwnd);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_lower: nx_lower failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXLOWER;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
static inline int nxeg_lower(NXEGWINDOW hwnd)
|
||||
{
|
||||
int ret = nxtk_lower(hwnd);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_lower: nxtk_lower failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXLOWER;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_raise
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
static inline int nxeg_raise(NXEGWINDOW hwnd)
|
||||
{
|
||||
int ret = nx_raise(hwnd);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_raise: nx_raise failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXRAISE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
static inline int nxeg_raise(NXEGWINDOW hwnd)
|
||||
{
|
||||
int ret = nxtk_raise(hwnd);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_raise: nxtk_raise failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXRAISE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_suinitialize
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NX_MULTIUSER
|
||||
static inline int nxeg_suinitialize(void)
|
||||
{
|
||||
FAR NX_DRIVERTYPE *dev;
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NX_EXTERNINIT)
|
||||
/* Use external graphics driver initialization */
|
||||
|
||||
message("nxeg_initialize: Initializing external graphics device\n");
|
||||
dev = up_nxdrvinit(CONFIG_EXAMPLES_NX_DEVNO);
|
||||
if (!dev)
|
||||
{
|
||||
message("nxeg_initialize: up_nxdrvinit failed, devno=%d\n", CONFIG_EXAMPLES_NX_DEVNO);
|
||||
g_exitcode = NXEXIT_EXTINITIALIZE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_NX_LCDDRIVER)
|
||||
int ret;
|
||||
|
||||
/* Initialize the LCD device */
|
||||
|
||||
message("nxeg_initialize: Initializing LCD\n");
|
||||
ret = up_lcdinitialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_initialize: up_lcdinitialize failed: %d\n", -ret);
|
||||
g_exitcode = NXEXIT_LCDINITIALIZE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Get the device instance */
|
||||
|
||||
dev = up_lcdgetdev(CONFIG_EXAMPLES_NX_DEVNO);
|
||||
if (!dev)
|
||||
{
|
||||
message("nxeg_initialize: up_lcdgetdev failed, devno=%d\n", CONFIG_EXAMPLES_NX_DEVNO);
|
||||
g_exitcode = NXEXIT_LCDGETDEV;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Turn the LCD on at 75% power */
|
||||
|
||||
(void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
|
||||
#else
|
||||
int ret;
|
||||
|
||||
/* Initialize the frame buffer device */
|
||||
|
||||
message("nxeg_initialize: Initializing framebuffer\n");
|
||||
ret = up_fbinitialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_initialize: up_fbinitialize failed: %d\n", -ret);
|
||||
g_exitcode = NXEXIT_FBINITIALIZE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
dev = up_fbgetvplane(CONFIG_EXAMPLES_NX_VPLANE);
|
||||
if (!dev)
|
||||
{
|
||||
message("nxeg_initialize: up_fbgetvplane failed, vplane=%d\n", CONFIG_EXAMPLES_NX_VPLANE);
|
||||
g_exitcode = NXEXIT_FBGETVPLANE;
|
||||
return ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Then open NX */
|
||||
|
||||
message("nxeg_initialize: Open NX\n");
|
||||
g_hnx = nx_open(dev);
|
||||
if (!g_hnx)
|
||||
{
|
||||
message("nxeg_suinitialize: nx_open failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXOPEN;
|
||||
return ERROR;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_initialize
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX_MULTIUSER
|
||||
static inline int nxeg_muinitialize(void)
|
||||
{
|
||||
struct sched_param param;
|
||||
pthread_t thread;
|
||||
pid_t servrid;
|
||||
int ret;
|
||||
|
||||
/* Set the client task priority */
|
||||
|
||||
param.sched_priority = CONFIG_EXAMPLES_NX_CLIENTPRIO;
|
||||
ret = sched_setparam(0, ¶m);
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nxeg_initialize: sched_setparam failed: %d\n" , ret);
|
||||
g_exitcode = NXEXIT_SCHEDSETPARAM;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Start the server task */
|
||||
|
||||
message("nxeg_initialize: Starting nx_servertask task\n");
|
||||
servrid = task_create("NX Server", CONFIG_EXAMPLES_NX_SERVERPRIO,
|
||||
CONFIG_EXAMPLES_NX_STACKSIZE, nx_servertask, NULL);
|
||||
if (servrid < 0)
|
||||
{
|
||||
message("nxeg_initialize: Failed to create nx_servertask task: %d\n", errno);
|
||||
g_exitcode = NXEXIT_TASKCREATE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Wait a bit to let the server get started */
|
||||
|
||||
sleep(1);
|
||||
|
||||
/* Connect to the server */
|
||||
|
||||
g_hnx = nx_connect();
|
||||
if (g_hnx)
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
(void)pthread_attr_init(&attr);
|
||||
param.sched_priority = CONFIG_EXAMPLES_NX_LISTENERPRIO;
|
||||
(void)pthread_attr_setschedparam(&attr, ¶m);
|
||||
(void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NX_STACKSIZE);
|
||||
|
||||
ret = pthread_create(&thread, &attr, nx_listenerthread, NULL);
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("nxeg_initialize: pthread_create failed: %d\n", ret);
|
||||
g_exitcode = NXEXIT_PTHREADCREATE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Don't return until we are connected to the server */
|
||||
|
||||
while (!g_connected)
|
||||
{
|
||||
/* Wait for the listener thread to wake us up when we really
|
||||
* are connected.
|
||||
*/
|
||||
|
||||
(void)sem_wait(&g_semevent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
message("nxeg_initialize: nx_connect failed: %d\n", errno);
|
||||
g_exitcode = NXEXIT_NXCONNECT;
|
||||
return ERROR;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxeg_initialize
|
||||
****************************************************************************/
|
||||
|
||||
static int nxeg_initialize(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Initialize window colors */
|
||||
|
||||
for (i = 0; i < CONFIG_NX_NPLANES; i++)
|
||||
{
|
||||
g_color1[i] = CONFIG_EXAMPLES_NX_COLOR1;
|
||||
g_color2[i] = CONFIG_EXAMPLES_NX_COLOR2;
|
||||
#ifndef CONFIG_EXAMPLES_NX_RAWWINDOWS
|
||||
g_tbcolor[i] = CONFIG_EXAMPLES_NX_TBCOLOR;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NX_MULTIUSER
|
||||
return nxeg_muinitialize();
|
||||
#else
|
||||
return nxeg_suinitialize();
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nx_main
|
||||
****************************************************************************/
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/****************************************************************************
|
||||
* examples/nx/nx_server.c
|
||||
*
|
||||
* Copyright (C) 2008-2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sched.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/nx/nx.h>
|
||||
|
||||
#ifdef CONFIG_NX_LCDDRIVER
|
||||
# include <nuttx/lcd/lcd.h>
|
||||
#else
|
||||
# include <nuttx/fb.h>
|
||||
#endif
|
||||
|
||||
#include "nx_internal.h"
|
||||
|
||||
#ifdef CONFIG_NX_MULTIUSER
|
||||
|
||||
/****************************************************************************
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nx_servertask
|
||||
****************************************************************************/
|
||||
|
||||
int nx_servertask(int argc, char *argv[])
|
||||
{
|
||||
FAR NX_DRIVERTYPE *dev;
|
||||
int ret;
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NX_EXTERNINIT)
|
||||
/* Use external graphics driver initialization */
|
||||
|
||||
message("nxeg_initialize: Initializing external graphics device\n");
|
||||
dev = up_nxdrvinit(CONFIG_EXAMPLES_NX_DEVNO);
|
||||
if (!dev)
|
||||
{
|
||||
message("nxeg_initialize: up_nxdrvinit failed, devno=%d\n", CONFIG_EXAMPLES_NX_DEVNO);
|
||||
g_exitcode = NXEXIT_EXTINITIALIZE;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_NX_LCDDRIVER)
|
||||
/* Initialize the LCD device */
|
||||
|
||||
message("nx_servertask: Initializing LCD\n");
|
||||
ret = up_lcdinitialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nx_servertask: up_lcdinitialize failed: %d\n", -ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Get the device instance */
|
||||
|
||||
dev = up_lcdgetdev(CONFIG_EXAMPLES_NX_DEVNO);
|
||||
if (!dev)
|
||||
{
|
||||
message("nx_servertask: up_lcdgetdev failed, devno=%d\n", CONFIG_EXAMPLES_NX_DEVNO);
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* Turn the LCD on at 75% power */
|
||||
|
||||
(void)dev->setpower(dev, ((3*CONFIG_LCD_MAXPOWER + 3)/4));
|
||||
#else
|
||||
/* Initialize the frame buffer device */
|
||||
|
||||
message("nx_servertask: Initializing framebuffer\n");
|
||||
ret = up_fbinitialize();
|
||||
if (ret < 0)
|
||||
{
|
||||
message("nx_servertask: up_fbinitialize failed: %d\n", -ret);
|
||||
return 1;
|
||||
}
|
||||
|
||||
dev = up_fbgetvplane(CONFIG_EXAMPLES_NX_VPLANE);
|
||||
if (!dev)
|
||||
{
|
||||
message("nx_servertask: up_fbgetvplane failed, vplane=%d\n", CONFIG_EXAMPLES_NX_VPLANE);
|
||||
return 2;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Then start the server */
|
||||
|
||||
ret = nx_run(dev);
|
||||
message("nx_servertask: nx_run returned: %d\n", errno);
|
||||
return 3;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NX_MULTIUSER */
|
||||
Reference in New Issue
Block a user