apps/examples/nxdemo: Add nxdemo application
This commit is contained in:
parent
529cde02a2
commit
9298bafa82
11
examples/nxdemo/.gitignore
vendored
Normal file
11
examples/nxdemo/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
74
examples/nxdemo/Kconfig
Normal file
74
examples/nxdemo/Kconfig
Normal file
@ -0,0 +1,74 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see the file kconfig-language.txt in the NuttX tools repository.
|
||||
#
|
||||
|
||||
config EXAMPLES_NXDEMO
|
||||
bool "NX Demo \"Graphic test\" example"
|
||||
default n
|
||||
---help---
|
||||
Enable the NX graphics \"Demo Test\" example
|
||||
|
||||
if EXAMPLES_NXDEMO
|
||||
|
||||
config EXAMPLES_NXDEMO_VPLANE
|
||||
int "Video Plane"
|
||||
default 0
|
||||
---help---
|
||||
The plane to select from the framebuffer driver for use in the test.
|
||||
Default: 0
|
||||
|
||||
config EXAMPLES_NXDEMO_DEVNO
|
||||
int "Video Device Number"
|
||||
default 0
|
||||
---help---
|
||||
The LCD device to select from the LCD driver for use in the test:
|
||||
Default: 0
|
||||
|
||||
config EXAMPLES_NXDEMO_BPP
|
||||
int "Bits-Per-Pixel"
|
||||
default 1
|
||||
---help---
|
||||
Pixels per pixel to use. Valid options include 1, 2, 4, 8, 16, 24,
|
||||
and 32. Default is 32.
|
||||
|
||||
|
||||
comment "Example Color Configuration"
|
||||
|
||||
config EXAMPLES_NXDEMO_DEFAULT_COLORS
|
||||
bool "Use Default Colors"
|
||||
default y
|
||||
|
||||
if !EXAMPLES_NXDEMO_DEFAULT_COLORS
|
||||
|
||||
config EXAMPLES_NXDEMO_BGCOLOR
|
||||
hex "Background color"
|
||||
default 0x0
|
||||
---help---
|
||||
The color of the background. Default depends on config
|
||||
EXAMPLES_NXDEMO_BPP.
|
||||
|
||||
endif
|
||||
|
||||
config EXAMPLES_NXDEMO_EXTERNINIT
|
||||
bool "External Device Initialization"
|
||||
default n
|
||||
depends on LIB_BOARDCTL
|
||||
select BOARDCTL_GRAPHICS
|
||||
---help---
|
||||
The driver for the graphics device on this platform requires some
|
||||
unusual initialization. This is the case, for example, for SPI LCD/OLED
|
||||
devices. If this configuration is selected, then the platform code
|
||||
must provide an LCD initialization function with a prototype like:
|
||||
|
||||
#ifdef CONFIG_NX_LCDDRIVER
|
||||
FAR struct lcd_dev_s *board_graphics_setup(unsigned int devno);
|
||||
#else
|
||||
FAR struct fb_vtable_s *board_graphics_setup(unsigned int devno);
|
||||
#endif
|
||||
|
||||
and must also define: CONFIG_LIB_BOARDCTL=y and
|
||||
CONFIG_BOARDCTL_GRAPHICS=y so that the boardctl() interface
|
||||
will be available in order to access this function.
|
||||
|
||||
endif
|
39
examples/nxdemo/Make.defs
Normal file
39
examples/nxdemo/Make.defs
Normal file
@ -0,0 +1,39 @@
|
||||
############################################################################
|
||||
# apps/examples/nxhello/Make.defs
|
||||
# Adds selected applications to apps/ build
|
||||
#
|
||||
# Copyright (C) 2018 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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_NXDEMO),y)
|
||||
CONFIGURED_APPS += examples/nxdemo
|
||||
endif
|
56
examples/nxdemo/Makefile
Normal file
56
examples/nxdemo/Makefile
Normal file
@ -0,0 +1,56 @@
|
||||
############################################################################
|
||||
# apps/examples/nxdemo/Makefile
|
||||
#
|
||||
# Copyright (C) 2018 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)/Make.defs
|
||||
|
||||
# NuttX NX Graphics Example.
|
||||
|
||||
ASRCS =
|
||||
CSRCS = nxdemo_bkgd.c nxdemo_listener.c
|
||||
MAINSRC = nxdemo_main.c
|
||||
|
||||
CONFIG_EXAMPLES_NXDEMO_PROGNAME ?= nxdemo$(EXEEXT)
|
||||
PROGNAME = $(CONFIG_EXAMPLES_NXDEMO_PROGNAME)
|
||||
|
||||
# NXDEMO built-in application info
|
||||
|
||||
CONFIG_EXAMPLES_NXDEMO_STACKSIZE ?= 2048
|
||||
CONFIG_EXAMPLES_NXDEMO_PRIORITY ?= 100
|
||||
|
||||
APPNAME = nxdemo
|
||||
PRIORITY = $(CONFIG_EXAMPLES_NXDEMO_PRIORITY)
|
||||
STACKSIZE = $(CONFIG_EXAMPLES_NXDEMO_STACKSIZE)
|
||||
|
||||
include $(APPDIR)/Application.mk
|
94
examples/nxdemo/images.h
Normal file
94
examples/nxdemo/images.h
Normal file
@ -0,0 +1,94 @@
|
||||
/****************************************************************************
|
||||
* examples/nxdemo/nxdemo.h
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Cherciu Mihail <m_cherciu@yahoo.com>
|
||||
*
|
||||
* 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 __APPS_EXAMPLES_NXDEMO_IMAGES_H
|
||||
#define __APPS_EXAMPLES_NXDEMO_IMAGES_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
static uint8_t nuttxlogo[] =
|
||||
{
|
||||
0x00, 0x00, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x06, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x0d, 0xf0,
|
||||
0x00, 0x00, 0x00, 0x00, 0x1b, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x37, 0xf8, 0x00, 0x00, 0x00, 0x00,
|
||||
0x6f, 0xfe, 0x01, 0xc0, 0x03, 0xc0, 0xdc, 0x7f, 0x02, 0x20, 0x04, 0x21, 0xb8, 0x3f, 0x06, 0x10,
|
||||
0x04, 0x13, 0x78, 0x3f, 0xcc, 0x10, 0x04, 0x1e, 0xf8, 0x1f, 0xe8, 0x10, 0x04, 0x0d, 0xf8, 0x1f,
|
||||
0xf0, 0x20, 0x04, 0x0f, 0xf8, 0x0f, 0xf0, 0x20, 0x04, 0x07, 0xf8, 0x0f, 0xe0, 0x40, 0x04, 0x07,
|
||||
0xf8, 0x07, 0xc0, 0x40, 0x04, 0x03, 0xf8, 0x07, 0xc0, 0x80, 0x04, 0x03, 0xf8, 0x03, 0x81, 0x00,
|
||||
0x04, 0x01, 0xf8, 0x03, 0x83, 0x80, 0x04, 0x01, 0xf8, 0x01, 0x03, 0xc0, 0x0c, 0x00, 0xf8, 0x01,
|
||||
0x07, 0xe0, 0x1c, 0x00, 0xf8, 0x00, 0x07, 0xf0, 0x34, 0x00, 0x78, 0x20, 0x0f, 0xf8, 0x6c, 0x00,
|
||||
0x78, 0x20, 0x0f, 0xfc, 0xdc, 0x10, 0x38, 0x30, 0x1f, 0xfe, 0xbc, 0x10, 0x38, 0x30, 0x1f, 0xff,
|
||||
0xfc, 0x18, 0x18, 0x30, 0x3f, 0xff, 0xfc, 0x18, 0x18, 0x30, 0x1f, 0xfd, 0x3c, 0x1c, 0x08, 0x20,
|
||||
0x1f, 0xfb, 0x3c, 0x1c, 0x08, 0x20, 0x0f, 0xf6, 0x1c, 0x1e, 0x00, 0x00, 0x0f, 0xec, 0x04, 0x1e,
|
||||
0x00, 0x00, 0x07, 0xd8, 0x04, 0x1f, 0x00, 0x01, 0x07, 0xb0, 0x04, 0x1f, 0x00, 0x01, 0x03, 0x60,
|
||||
0x04, 0x1f, 0x80, 0x03, 0x82, 0xc0, 0x04, 0x1f, 0x80, 0x07, 0x81, 0x80, 0x04, 0x1f, 0xc0, 0x07,
|
||||
0xc0, 0x80, 0x04, 0x1f, 0xc0, 0x07, 0xe0, 0x40, 0x04, 0x1f, 0xe0, 0x0f, 0xc0, 0x40, 0x04, 0x1f,
|
||||
0xe0, 0x0f, 0xb0, 0x20, 0x04, 0x13, 0xf0, 0x1f, 0x68, 0x10, 0x04, 0x13, 0xf0, 0x3e, 0xcc, 0x10,
|
||||
0x04, 0x11, 0xf8, 0x3d, 0x82, 0x10, 0x02, 0x20, 0x78, 0x3b, 0x02, 0x20, 0x01, 0xc0, 0x7e, 0xf6,
|
||||
0x01, 0xc0, 0x00, 0x00, 0x3f, 0xec, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xd8, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0f, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x07, 0x60, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x00, 0x00
|
||||
|
||||
};
|
||||
|
||||
static uint8_t demo[] =
|
||||
{
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00, 0x03, 0xf0, 0x00, 0x03, 0xf8, 0x00, 0x03, 0xfc,
|
||||
0x00, 0x03, 0xfe, 0x00, 0x03, 0xfe, 0x00, 0x03, 0xff, 0x00, 0x03, 0xff, 0x80, 0x03, 0xff, 0xc0,
|
||||
0x03, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xff, 0x80, 0x03, 0xff, 0x80, 0x03, 0xff, 0x00, 0x03,
|
||||
0xfe, 0x00, 0x03, 0xfc, 0x00, 0x03, 0xf8, 0x00, 0x03, 0xf8, 0x00, 0x03, 0xf0, 0x00, 0x03, 0xe0,
|
||||
0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
||||
};
|
||||
|
||||
static uint8_t battery [] =
|
||||
{
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xfc, 0x10, 0x00, 0x04, 0x37, 0x77,
|
||||
0x74, 0x37, 0x77, 0x74, 0x37, 0x77, 0x74, 0x37, 0x77, 0x74, 0x10, 0x00, 0x04, 0x0f, 0xff, 0xfc,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __APPS_EXAMPLES_NXDEMO_IMAGES_H */
|
230
examples/nxdemo/nxdemo.h
Normal file
230
examples/nxdemo/nxdemo.h
Normal file
@ -0,0 +1,230 @@
|
||||
/****************************************************************************
|
||||
* examples/nxdemo/nxdemo.h
|
||||
*
|
||||
* Copyright (C) 2018 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 __APPS_EXAMPLES_NXDEMO_NXDEMO_H
|
||||
#define __APPS_EXAMPLES_NXDEMO_NXDEMO_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxglib.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_NX
|
||||
# error "NX is not enabled (CONFIG_NX)"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NXDEMO_VPLANE
|
||||
# define CONFIG_EXAMPLES_NXDEMO_VPLANE 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NXDEMO_BPP
|
||||
# define CONFIG_EXAMPLES_NXDEMO_BPP 32
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NXDEMO_BGCOLOR
|
||||
# if CONFIG_EXAMPLES_NXDEMO_BPP == 24 || CONFIG_EXAMPLES_NXDEMO_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NXDEMO_BGCOLOR 0x007b68ee
|
||||
# elif CONFIG_EXAMPLES_NXDEMO_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NXDEMO_BGCOLOR 0x7b5d
|
||||
# elif CONFIG_EXAMPLES_NXDEMO_BPP < 8
|
||||
# define CONFIG_EXAMPLES_NXDEMO_BGCOLOR 0x00
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NXDEMO_BGCOLOR ' '
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR
|
||||
# if CONFIG_EXAMPLES_NXDEMO_BPP == 24 || CONFIG_EXAMPLES_NXDEMO_BPP == 32
|
||||
# define CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR 0xFFFFFFFF
|
||||
# elif CONFIG_EXAMPLES_NXDEMO_BPP == 16
|
||||
# define CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR 0xFFFF
|
||||
# elif CONFIG_EXAMPLES_NXDEMO_BPP < 8
|
||||
# define CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR 0xFF
|
||||
# else
|
||||
# define CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR 'F'
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* Multi-user NX support */
|
||||
|
||||
#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_NXDEMO_LISTENER_STACKSIZE
|
||||
# define CONFIG_EXAMPLES_NXDEMO_LISTENER_STACKSIZE 2048
|
||||
#endif
|
||||
#ifndef CONFIG_EXAMPLES_NXDEMO_LISTENERPRIO
|
||||
# define CONFIG_EXAMPLES_NXDEMO_LISTENERPRIO 100
|
||||
#endif
|
||||
#ifndef CONFIG_EXAMPLES_NXDEMO_CLIENTPRIO
|
||||
# define CONFIG_EXAMPLES_NXDEMO_CLIENTPRIO 100
|
||||
#endif
|
||||
#ifndef CONFIG_EXAMPLES_NXDEMO_SERVERPRIO
|
||||
# define CONFIG_EXAMPLES_NXDEMO_SERVERPRIO 120
|
||||
#endif
|
||||
#ifndef CONFIG_EXAMPLES_NXDEMO_NOTIFYSIGNO
|
||||
# define CONFIG_EXAMPLES_NXDEMO_NOTIFYSIGNO 4
|
||||
#endif
|
||||
|
||||
/* Image Information ********************************************************/
|
||||
|
||||
#define IMAGE_HEIGHT 160 /* Number of rows in the raw image */
|
||||
#define IMAGE_WIDTH 160 /* Number of columns in the raw image */
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_XSCALEp5)
|
||||
# define SCALED_WIDTH 80 /* Number of columns in the scaled image */
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_XSCALE1p5)
|
||||
# define SCALED_WIDTH 240 /* Number of columns in the scaled image */
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_XSCALE2p0)
|
||||
# define SCALED_WIDTH 320 /* Number of columns in the scaled image */
|
||||
#else
|
||||
# define SCALED_WIDTH 160 /* Number of columns in the scaled image */
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_NXIMAGE_YSCALEp5)
|
||||
# define SCALED_HEIGHT 80 /* Number of rows in the scaled image */
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE1p5)
|
||||
# define SCALED_HEIGHT 240 /* Number of rows in the scaled image */
|
||||
#elif defined(CONFIG_EXAMPLES_NXIMAGE_YSCALE2p0)
|
||||
# define SCALED_HEIGHT 320 /* Number of rows in the scaled image */
|
||||
#else
|
||||
# define SCALED_HEIGHT 160 /* Number of rows in the scaled image */
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
enum exitcode_e
|
||||
{
|
||||
NXEXIT_SUCCESS = 0,
|
||||
NXEXIT_EXTINITIALIZE,
|
||||
NXEXIT_FBINITIALIZE,
|
||||
NXEXIT_FBGETVPLANE,
|
||||
NXEXIT_LCDINITIALIZE,
|
||||
NXEXIT_LCDGETDEV,
|
||||
NXEXIT_NXOPEN,
|
||||
NXEXIT_FONTOPEN,
|
||||
NXEXIT_NXREQUESTBKGD,
|
||||
NXEXIT_NXSETBGCOLOR
|
||||
};
|
||||
|
||||
/* Describes one cached glyph bitmap */
|
||||
|
||||
struct nxdemo_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) */
|
||||
uint8_t usecnt; /* Use count */
|
||||
FAR uint8_t *bitmap; /* Allocated bitmap memory */
|
||||
};
|
||||
|
||||
/* Describes on character on the display */
|
||||
|
||||
struct nxdemo_bitmap_s
|
||||
{
|
||||
uint8_t code; /* Character code */
|
||||
uint8_t flags; /* See BMFLAGS_* */
|
||||
struct nxgl_point_s pos; /* Character position */
|
||||
};
|
||||
|
||||
struct nxdemo_data_s
|
||||
{
|
||||
/* The NX handles */
|
||||
|
||||
NXHANDLE hnx;
|
||||
NXHANDLE hbkgd;
|
||||
bool connected;
|
||||
|
||||
/* The screen resolution */
|
||||
|
||||
nxgl_coord_t xres;
|
||||
nxgl_coord_t yres;
|
||||
|
||||
volatile bool havepos;
|
||||
sem_t eventsem;
|
||||
volatile int code;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* NXDEMO state data */
|
||||
|
||||
extern struct nxdemo_data_s g_nxdemo;
|
||||
|
||||
/* NX callback vtables */
|
||||
|
||||
extern const struct nx_callback_s g_nxdemocb;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/* NX server/listener thread */
|
||||
|
||||
FAR void *nxdemo_listener(FAR void *arg);
|
||||
|
||||
/* Background window interfaces */
|
||||
|
||||
void nxdemo_hello(NXWINDOW hwnd);
|
||||
|
||||
#endif /* __APPS_EXAMPLES_NXDEMO_NXDEMO_H */
|
529
examples/nxdemo/nxdemo_bkgd.c
Normal file
529
examples/nxdemo/nxdemo_bkgd.c
Normal file
@ -0,0 +1,529 @@
|
||||
/****************************************************************************
|
||||
* examples/nxdemo/nxdemo_bkgd.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
* Cherciu Mihail <m_cherciu@yahoo.com>
|
||||
*
|
||||
* 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 <string.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxglib.h>
|
||||
#include <nuttx/nx/nxfonts.h>
|
||||
|
||||
#include "nxdemo.h"
|
||||
#include "images.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor 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_NXDEMO_BPP == 1
|
||||
# define RENDERER nxf_convert_1bpp
|
||||
#elif CONFIG_EXAMPLES_NXDEMO_BPP == 2
|
||||
# define RENDERER nxf_convert_2bpp
|
||||
#elif CONFIG_EXAMPLES_NXDEMO_BPP == 4
|
||||
# define RENDERER nxf_convert_4bpp
|
||||
#elif CONFIG_EXAMPLES_NXDEMO_BPP == 8
|
||||
# define RENDERER nxf_convert_8bpp
|
||||
#elif CONFIG_EXAMPLES_NXDEMO_BPP == 16
|
||||
# define RENDERER nxf_convert_16bpp
|
||||
#elif CONFIG_EXAMPLES_NXDEMO_BPP == 24
|
||||
# define RENDERER nxf_convert_24bpp
|
||||
#elif CONFIG_EXAMPLES_NXDEMO_BPP == 32
|
||||
# define RENDERER nxf_convert_32bpp
|
||||
#else
|
||||
# error "Unsupported CONFIG_EXAMPLES_NXDEMO_BPP"
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a, b) (a < b ? a : b)
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a, b) (a > b ? a : b)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void nxdemo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
bool morem, FAR void *arg);
|
||||
static void nxdemo_position(NXWINDOW 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_XYINPUT
|
||||
static void nxdemo_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
static void nxdemo_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
|
||||
FAR void *arg);
|
||||
#endif
|
||||
|
||||
static void nxdemo_demo_1(NXWINDOW hwnd);
|
||||
static void nxdemo_demo_2(NXWINDOW hwnd);
|
||||
static void nxdemo_demo_3(NXWINDOW hwnd);
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/* Background window call table */
|
||||
|
||||
const struct nx_callback_s g_nxdemocb =
|
||||
{
|
||||
nxdemo_redraw, /* redraw */
|
||||
nxdemo_position /* position */
|
||||
#ifdef CONFIG_NX_XYINPUT
|
||||
,
|
||||
nxdemo_mousein /* mousein */
|
||||
#endif
|
||||
#ifdef CONFIG_NX_KBD
|
||||
,
|
||||
nxdemo_kbdin /* my kbdin */
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_redraw
|
||||
****************************************************************************/
|
||||
|
||||
static void nxdemo_redraw(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect,
|
||||
bool more, FAR void *arg)
|
||||
{
|
||||
ginfo("hwnd=%p rect={(%d,%d),(%d,%d)} more=%s\n",
|
||||
hwnd, rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y,
|
||||
more ? "true" : "false");
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_position
|
||||
****************************************************************************/
|
||||
|
||||
static void nxdemo_position(NXWINDOW 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)
|
||||
{
|
||||
/* Report the position */
|
||||
|
||||
ginfo("hwnd=%p size=(%d,%d) pos=(%d,%d) bounds={(%d,%d),(%d,%d)}\n",
|
||||
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 (!g_nxdemo.havepos)
|
||||
{
|
||||
/* Save the background window handle */
|
||||
|
||||
g_nxdemo.hbkgd = hwnd;
|
||||
|
||||
/* Save the window limits */
|
||||
|
||||
g_nxdemo.xres = bounds->pt2.x + 1;
|
||||
g_nxdemo.yres = bounds->pt2.y + 1;
|
||||
|
||||
g_nxdemo.havepos = true;
|
||||
sem_post(&g_nxdemo.eventsem);
|
||||
ginfo("Have xres=%d yres=%d\n", g_nxdemo.xres, g_nxdemo.yres);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_mousein
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX_XYINPUT
|
||||
static void nxdemo_mousein(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos,
|
||||
uint8_t buttons, FAR void *arg)
|
||||
{
|
||||
printf("nxdemo_mousein: hwnd=%p pos=(%d,%d) button=%02x\n",
|
||||
hwnd, pos->x, pos->y, buttons);
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_kbdin
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX_KBD
|
||||
static void nxdemo_kbdin(NXWINDOW hwnd, uint8_t nch, FAR const uint8_t *ch,
|
||||
FAR void *arg)
|
||||
{
|
||||
ginfo("hwnd=%p nch=%d\n", hwnd, nch);
|
||||
|
||||
/* In this example, there is no keyboard so a keyboard event is not
|
||||
* expected.
|
||||
*/
|
||||
|
||||
printf("nxdemo_kbdin: Unexpected keyboard callback\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_demo_1
|
||||
****************************************************************************/
|
||||
|
||||
static void nxdemo_demo_1(NXWINDOW hwnd)
|
||||
{
|
||||
struct nxgl_point_s center;
|
||||
nxgl_mxpixel_t color[CONFIG_NX_NPLANES];
|
||||
nxgl_coord_t circle_radius = 0;
|
||||
bool direction_x = false;
|
||||
bool direction_y = false;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
circle_radius = 3;
|
||||
i = 0;
|
||||
center.x = center.y = circle_radius * 2;
|
||||
|
||||
while (i < 270)
|
||||
{
|
||||
if (direction_x == false)
|
||||
{
|
||||
center.x++;
|
||||
}
|
||||
else
|
||||
{
|
||||
center.x--;
|
||||
}
|
||||
|
||||
if (center.x >= g_nxdemo.xres - circle_radius)
|
||||
{
|
||||
direction_x = true;
|
||||
}
|
||||
else if (center.x <= circle_radius)
|
||||
{
|
||||
direction_x = false;
|
||||
}
|
||||
|
||||
if (direction_y == false)
|
||||
{
|
||||
center.y++;
|
||||
}
|
||||
else
|
||||
{
|
||||
center.y--;
|
||||
}
|
||||
|
||||
if (center.y >= g_nxdemo.yres - circle_radius)
|
||||
{
|
||||
direction_y = true;
|
||||
}
|
||||
else if (center.y <= circle_radius)
|
||||
{
|
||||
direction_y = false;
|
||||
}
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR;
|
||||
ret = nx_drawcircle((NXWINDOW)hwnd, ¢er, circle_radius, 1, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawcircle failed: %d\n", ret);
|
||||
}
|
||||
|
||||
usleep(30000);
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_BGCOLOR;
|
||||
ret = nx_drawcircle((NXWINDOW)hwnd, ¢er, circle_radius, 1, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawcircle failed: %d\n", ret);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
center.x = g_nxdemo.xres >> 1;
|
||||
center.y = g_nxdemo.yres >> 1;
|
||||
|
||||
for (i = 0; i<MIN(g_nxdemo.xres, g_nxdemo.yres)>> 1; i++)
|
||||
{
|
||||
circle_radius = i;
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR;
|
||||
ret = nx_fillcircle((NXWINDOW)hwnd, ¢er, circle_radius, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawcircle failed: %d\n", ret);
|
||||
}
|
||||
|
||||
usleep(100000);
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_BGCOLOR;
|
||||
ret = nx_fillcircle((NXWINDOW)hwnd, ¢er, circle_radius, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawcircle failed: %d\n", ret);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = MIN(g_nxdemo.xres, g_nxdemo.yres) >> 1; i > 1; i--)
|
||||
{
|
||||
circle_radius = i;
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR;
|
||||
ret = nx_fillcircle((NXWINDOW)hwnd, ¢er, circle_radius, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawcircle failed: %d\n", ret);
|
||||
}
|
||||
|
||||
usleep(100000);
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_BGCOLOR;
|
||||
ret = nx_fillcircle((NXWINDOW)hwnd, ¢er, circle_radius, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawcircle failed: %d\n", ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_demo_2
|
||||
****************************************************************************/
|
||||
|
||||
static void nxdemo_demo_2(NXWINDOW hwnd)
|
||||
{
|
||||
struct nxgl_point_s center;
|
||||
struct nxgl_rect_s rect;
|
||||
nxgl_mxpixel_t color[CONFIG_NX_NPLANES];
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
center.x = g_nxdemo.xres >> 1;
|
||||
center.y = g_nxdemo.yres >> 1;
|
||||
|
||||
for (i = 0; i<MIN(g_nxdemo.xres, g_nxdemo.yres)>> 1; i++)
|
||||
{
|
||||
rect.pt1.x = center.x - i;
|
||||
rect.pt1.y = center.y - i;
|
||||
rect.pt2.x = center.x + i;
|
||||
rect.pt2.y = center.y + i;
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR;
|
||||
ret = nx_fill((NXWINDOW)hwnd, &rect, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawcircle failed: %d\n", ret);
|
||||
}
|
||||
|
||||
usleep(100000);
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_BGCOLOR;
|
||||
ret = nx_fill((NXWINDOW)hwnd, &rect, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawcircle failed: %d\n", ret);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = MIN(g_nxdemo.xres, g_nxdemo.yres) >> 1; i > 1; i--)
|
||||
{
|
||||
|
||||
rect.pt1.x = center.x - i;
|
||||
rect.pt1.y = center.y - i;
|
||||
rect.pt2.x = center.x + i;
|
||||
rect.pt2.y = center.y + i;
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR;
|
||||
ret = nx_fill((NXWINDOW)hwnd, &rect, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawcircle failed: %d\n", ret);
|
||||
}
|
||||
|
||||
usleep(100000);
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_BGCOLOR;
|
||||
ret = nx_fill((NXWINDOW)hwnd, &rect, color);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawcircle failed: %d\n", ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_demo_3
|
||||
****************************************************************************/
|
||||
|
||||
static void nxdemo_demo_3(NXWINDOW hwnd)
|
||||
{
|
||||
struct nxgl_vector_s vect;
|
||||
nxgl_mxpixel_t color[CONFIG_NX_NPLANES];
|
||||
nxgl_coord_t line_width = 2;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < g_nxdemo.yres; i++)
|
||||
{
|
||||
vect.pt1.x = 0;
|
||||
vect.pt1.y = i;
|
||||
vect.pt2.x = g_nxdemo.xres;
|
||||
vect.pt2.y = i;
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR;
|
||||
ret = nx_drawline((NXWINDOW)hwnd,
|
||||
&vect,
|
||||
line_width,
|
||||
color, NX_LINECAP_NONE);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawline failed: %d\n", ret);
|
||||
}
|
||||
|
||||
usleep(50000);
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_BGCOLOR;
|
||||
ret = nx_drawline((NXWINDOW)hwnd,
|
||||
&vect,
|
||||
line_width,
|
||||
color, NX_LINECAP_NONE);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawline failed: %d\n", ret);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < g_nxdemo.xres; i++)
|
||||
{
|
||||
vect.pt1.x = i;
|
||||
vect.pt1.y = 0;
|
||||
vect.pt2.x = i;
|
||||
vect.pt2.y = g_nxdemo.yres;
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_DRAWCOLOR;
|
||||
ret = nx_drawline((NXWINDOW)hwnd,
|
||||
&vect,
|
||||
line_width,
|
||||
color, NX_LINECAP_NONE);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawline failed: %d\n", ret);
|
||||
}
|
||||
|
||||
usleep(50000);
|
||||
|
||||
color[0] = CONFIG_EXAMPLES_NXDEMO_BGCOLOR;
|
||||
ret = nx_drawline((NXWINDOW)hwnd,
|
||||
&vect,
|
||||
line_width,
|
||||
color, NX_LINECAP_NONE);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_drawline failed: %d\n", ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_demo_4
|
||||
****************************************************************************/
|
||||
|
||||
static void nxdemo_demo_4(NXWINDOW hwnd)
|
||||
{
|
||||
struct nxgl_point_s origin;
|
||||
struct nxgl_rect_s rect;
|
||||
FAR const void *src[CONFIG_NX_NPLANES];
|
||||
int ret;
|
||||
|
||||
rect.pt1.x = 0;
|
||||
rect.pt1.y = 0;
|
||||
rect.pt2.x = 23;
|
||||
rect.pt2.y = 23;
|
||||
|
||||
origin.x = 0;
|
||||
origin.y = 0;
|
||||
|
||||
src[0] = (FAR const void *)battery;
|
||||
|
||||
ret = nx_bitmap((NXWINDOW)hwnd,
|
||||
&rect,
|
||||
src,
|
||||
&origin,
|
||||
3);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxnxdemo: nx_bitmap failed: %d\n", ret);
|
||||
}
|
||||
|
||||
sleep(5);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_hello
|
||||
*
|
||||
* Description:
|
||||
* Demo displaying graphic on the screen
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void nxdemo_hello(NXWINDOW hwnd)
|
||||
{
|
||||
nxdemo_demo_1((NXWINDOW)hwnd);
|
||||
nxdemo_demo_2((NXWINDOW)hwnd);
|
||||
nxdemo_demo_3((NXWINDOW)hwnd);
|
||||
nxdemo_demo_4((NXWINDOW)hwnd);
|
||||
}
|
94
examples/nxdemo/nxdemo_listener.c
Normal file
94
examples/nxdemo/nxdemo_listener.c
Normal file
@ -0,0 +1,94 @@
|
||||
/****************************************************************************
|
||||
* examples/nxterm/nxdemo_listener.c
|
||||
*
|
||||
* Copyright (C) 2018 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 <errno.h>
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
|
||||
#include "nxdemo.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_listener
|
||||
****************************************************************************/
|
||||
|
||||
FAR void *nxdemo_listener(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_nxdemo.hnx);
|
||||
if (ret < 0)
|
||||
{
|
||||
/* An error occurred... assume that we have lost connection with
|
||||
* the server.
|
||||
*/
|
||||
|
||||
printf("nxdemo_listener: Lost server connection: %d\n", errno);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* If we received a message, we must be connected */
|
||||
|
||||
if (!g_nxdemo.connected)
|
||||
{
|
||||
g_nxdemo.connected = true;
|
||||
sem_post(&g_nxdemo.eventsem);
|
||||
printf("nxdemo_listener: Connected\n");
|
||||
}
|
||||
}
|
||||
}
|
262
examples/nxdemo/nxdemo_main.c
Normal file
262
examples/nxdemo/nxdemo_main.c
Normal file
@ -0,0 +1,262 @@
|
||||
/****************************************************************************
|
||||
* examples/nxdemo/nxdemo_main.c
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
* Cherciu Mihail <m_cherciu@yahoo.com>
|
||||
*
|
||||
* 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 <sys/boardctl.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <sched.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/board.h>
|
||||
|
||||
#ifdef CONFIG_NX_LCDDRIVER
|
||||
# include <nuttx/lcd/lcd.h>
|
||||
#else
|
||||
# include <nuttx/video/fb.h>
|
||||
# ifdef CONFIG_VNCSERVER
|
||||
# include <nuttx/video/vnc.h>
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <nuttx/nx/nx.h>
|
||||
#include <nuttx/nx/nxglib.h>
|
||||
#include <nuttx/nx/nxfonts.h>
|
||||
|
||||
#include "nxdemo.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
/* If not specified, assume that the hardware supports one video plane */
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NXDEMO_VPLANE
|
||||
# define CONFIG_EXAMPLES_NXDEMO_VPLANE 0
|
||||
#endif
|
||||
|
||||
/* If not specified, assume that the hardware supports one LCD device */
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_NXDEMO_DEVNO
|
||||
# define CONFIG_EXAMPLES_NXDEMO_DEVNO 0
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
struct nxdemo_data_s g_nxdemo =
|
||||
{
|
||||
NULL, /* hnx */
|
||||
NULL, /* hbkgd */
|
||||
false, /* connected */
|
||||
0, /* xres */
|
||||
0, /* yres */
|
||||
false, /* havpos */
|
||||
SEM_INITIALIZER(0), /* eventsem */
|
||||
NXEXIT_SUCCESS /* exit code */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_initialize
|
||||
****************************************************************************/
|
||||
|
||||
static inline int nxdemo_initialize(void)
|
||||
{
|
||||
struct sched_param param;
|
||||
pthread_t thread;
|
||||
int ret;
|
||||
|
||||
/* Set the client task priority */
|
||||
|
||||
param.sched_priority = CONFIG_EXAMPLES_NXDEMO_CLIENTPRIO;
|
||||
ret = sched_setparam(0, ¶m);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxdemo_initialize: sched_setparam failed: %d\n" , ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Start the NX server kernel thread */
|
||||
|
||||
ret = boardctl(BOARDIOC_NX_START, 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxdemo_initialize: Failed to start the NX server: %d\n", errno);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Connect to the server */
|
||||
|
||||
g_nxdemo.hnx = nx_connect();
|
||||
if (g_nxdemo.hnx)
|
||||
{
|
||||
pthread_attr_t attr;
|
||||
|
||||
#ifdef CONFIG_VNCSERVER
|
||||
/* Setup the VNC server to support keyboard/mouse inputs */
|
||||
|
||||
ret = vnc_default_fbinitialize(0, g_nxdemo.hnx);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("vnc_default_fbinitialize failed: %d\n", ret);
|
||||
nx_disconnect(g_nxdemo.hnx);
|
||||
return ERROR;
|
||||
}
|
||||
#endif
|
||||
/* 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_NXDEMO_LISTENERPRIO;
|
||||
(void)pthread_attr_setschedparam(&attr, ¶m);
|
||||
(void)pthread_attr_setstacksize(&attr, CONFIG_EXAMPLES_NXDEMO_LISTENER_STACKSIZE);
|
||||
|
||||
ret = pthread_create(&thread, &attr, nxdemo_listener, NULL);
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("nxdemo_initialize: pthread_create failed: %d\n", ret);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Don't return until we are connected to the server */
|
||||
|
||||
while (!g_nxdemo.connected)
|
||||
{
|
||||
/* Wait for the listener thread to wake us up when we really
|
||||
* are connected.
|
||||
*/
|
||||
|
||||
(void)sem_wait(&g_nxdemo.eventsem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("nxdemo_initialize: nx_connect failed: %d\n", errno);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxdemo_main
|
||||
*
|
||||
* Description:
|
||||
* Main entry pointer. Configures the basic display resources.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BUILD_KERNEL
|
||||
int main(int argc, FAR char *argv[])
|
||||
#else
|
||||
int nxdemo_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
nxgl_mxpixel_t color;
|
||||
int ret;
|
||||
|
||||
/* Initialize NX */
|
||||
|
||||
ret = nxdemo_initialize();
|
||||
printf("nxdemo_main: NX handle=%p\n", g_nxdemo.hnx);
|
||||
if (!g_nxdemo.hnx || ret < 0)
|
||||
{
|
||||
printf("nxdemo_main: Failed to get NX handle: %d\n", errno);
|
||||
g_nxdemo.code = NXEXIT_EXTINITIALIZE;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Get the background window */
|
||||
|
||||
ret = nx_requestbkgd(g_nxdemo.hnx, &g_nxdemocb, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("nxdemo_main: nx_setbgcolor failed: %d\n", errno);
|
||||
g_nxdemo.code = NXEXIT_NXREQUESTBKGD;
|
||||
goto errout_with_nx;
|
||||
}
|
||||
|
||||
/* Wait until we have the screen resolution. */
|
||||
|
||||
while (!g_nxdemo.havepos)
|
||||
{
|
||||
(void)sem_wait(&g_nxdemo.eventsem);
|
||||
}
|
||||
|
||||
printf("nxdemo_main: Screen resolution (%d,%d)\n",
|
||||
g_nxdemo.xres, g_nxdemo.yres);
|
||||
|
||||
nxdemo_hello(g_nxdemo.hbkgd);
|
||||
|
||||
/* Release background */
|
||||
|
||||
(void)nx_releasebkgd(g_nxdemo.hbkgd);
|
||||
|
||||
/* Close NX */
|
||||
|
||||
errout_with_nx:
|
||||
printf("nxdemo_main: Disconnect from the server\n");
|
||||
nx_disconnect(g_nxdemo.hnx);
|
||||
|
||||
errout:
|
||||
return g_nxdemo.code;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user