From 0ad3b3c03b2f360e685db2c35872d90e32617935 Mon Sep 17 00:00:00 2001 From: Brian Webb Date: Fri, 17 Mar 2017 20:37:45 -0700 Subject: [PATCH] Adds a test program for the XBox One controller driver (xbc_test). --- examples/xbc_test/.gitignore | 11 +++ examples/xbc_test/Kconfig | 36 +++++++ examples/xbc_test/Make.defs | 42 ++++++++ examples/xbc_test/Makefile | 59 +++++++++++ examples/xbc_test/xbc_test_main.c | 157 ++++++++++++++++++++++++++++++ 5 files changed, 305 insertions(+) create mode 100644 examples/xbc_test/.gitignore create mode 100644 examples/xbc_test/Kconfig create mode 100644 examples/xbc_test/Make.defs create mode 100644 examples/xbc_test/Makefile create mode 100644 examples/xbc_test/xbc_test_main.c diff --git a/examples/xbc_test/.gitignore b/examples/xbc_test/.gitignore new file mode 100644 index 000000000..fa1ec7579 --- /dev/null +++ b/examples/xbc_test/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.obj +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src diff --git a/examples/xbc_test/Kconfig b/examples/xbc_test/Kconfig new file mode 100644 index 000000000..9aa0d573d --- /dev/null +++ b/examples/xbc_test/Kconfig @@ -0,0 +1,36 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config EXAMPLES_XBC_TEST + bool "XBox Controller Test example" + default n + ---help--- + Enable the XBox Controller Test example + +if EXAMPLES_XBC_TEST + +config EXAMPLES_XBC_TEST_PROGNAME + string "Program name" + default "xbc_test" + depends on BUILD_KERNEL + ---help--- + This is the name of the program that will be use when the NSH ELF + program is installed. + +config EXAMPLES_XBC_DEVNAME + string "XBox Controller Device Name" + default "/dev/xboxa" + ---help--- + Name of XBox controller device to be used. Default: "/dev/xboxa" + +config EXAMPLES_XBC_TEST_PRIORITY + int "Xbc_test task priority" + default 100 + +config EXAMPLES_XBC_TEST_STACKSIZE + int "XBox Controller Test stack size" + default 2048 + +endif diff --git a/examples/xbc_test/Make.defs b/examples/xbc_test/Make.defs new file mode 100644 index 000000000..18dbf308a --- /dev/null +++ b/examples/xbc_test/Make.defs @@ -0,0 +1,42 @@ +############################################################################ +# apps/examples/xbc_test/Make.defs +# Adds selected applications to apps/ build +# +# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Copyright (C) 2017 Brian Webb. All rights reserved. +# Author: Brian Webb +# +# 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_XBC_TEST),y) +CONFIGURED_APPS += examples/xbc_test +endif diff --git a/examples/xbc_test/Makefile b/examples/xbc_test/Makefile new file mode 100644 index 000000000..16be17d3d --- /dev/null +++ b/examples/xbc_test/Makefile @@ -0,0 +1,59 @@ +############################################################################ +# apps/examples/hello/Makefile +# +# Copyright (C) 2008, 2010-2013 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt +# +# Copyright (C) 2017 Brian Webb. All rights reserved. +# Author: Brian Webb +# +# 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 + +# XBox controller driver test built-in application info + +CONFIG_EXAMPLES_XBC_TEST_PRIORITY ?= SCHED_PRIORITY_DEFAULT +CONFIG_EXAMPLES_XBC_TEST_STACKSIZE ?= 2048 + +APPNAME = xbc_test +PRIORITY = $(CONFIG_EXAMPLES_XBC_TEST_PRIORITY) +STACKSIZE = $(CONFIG_EXAMPLES_XBC_TEST_STACKSIZE) + +# Xbc_Test, World! Example + +ASRCS = +CSRCS = +MAINSRC = xbc_test_main.c + +CONFIG_EXAMPLES_XBC_TEST_PROGNAME ?= xbc_test$(EXEEXT) +PROGNAME = $(CONFIG_EXAMPLES_XBC_TEST_PROGNAME) + +include $(APPDIR)/Application.mk diff --git a/examples/xbc_test/xbc_test_main.c b/examples/xbc_test/xbc_test_main.c new file mode 100644 index 000000000..c4d36e038 --- /dev/null +++ b/examples/xbc_test/xbc_test_main.c @@ -0,0 +1,157 @@ +/**************************************************************************** + * examples/xbc_test/xbc_test_main.c + * + * Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Copyright (C) 2017 Brian Webb. All rights reserved. + * Author: Brian Webb + * + * 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 + +#include +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ +/* Configuration ************************************************************/ + +/* Sanity checking */ + +#ifndef CONFIG_USBHOST +# error "CONFIG_USBHOST is not defined" +#endif + +#ifdef CONFIG_USBHOST_INT_DISABLE +# error "Interrupt endpoints are disabled (CONFIG_USBHOST_INT_DISABLE)" +#endif + +#ifndef CONFIG_NFILE_DESCRIPTORS +# error "CONFIG_NFILE_DESCRIPTORS > 0 needed" +#endif + +/* Provide some default values for other configuration settings */ + +#ifndef CONFIG_EXAMPLES_XBC_DEVNAME +# define CONFIG_EXAMPLES_XBC_DEVNAME "/dev/xboxa" +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * hello_main + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int xbc_test_main(int argc, char *argv[]) +#endif +{ + char buffer[256]; + ssize_t nbytes; + int fd; + + /* Eventually logic here will open the controller device and perform the + * controller test. + */ + + for (;;) + { + /* Open the controller device. Loop until the device is successfully + * opened. + */ + + do + { + printf("Opening device %s\n", CONFIG_EXAMPLES_XBC_DEVNAME); + fd = open(CONFIG_EXAMPLES_XBC_DEVNAME, O_RDONLY); + if (fd < 0) + { + printf("Failed: %d\n", errno); + fflush(stdout); + sleep(3); + } + } + while (fd < 0); + + printf("Device %s opened\n", CONFIG_EXAMPLES_XBC_DEVNAME); + fflush(stdout); + + /* Loop until there is a read failure (or EOF?) */ + + do + { + /* Read a buffer of data */ + + nbytes = read(fd, buffer, 256); + if (nbytes > 0) + { + /* On success, echo the buffer to stdout */ + + printf("%d bytes read\n", nbytes); + if (nbytes == sizeof(struct xbox_controller_buttonstate_s)) + { + struct xbox_controller_buttonstate_s *rpt = (struct xbox_controller_buttonstate_s*)buffer; + printf("guide: %d sync: %d start: %d back: %d a: %d b: %d x: %d y: %d\n", + rpt->guide, rpt->sync, rpt->start, rpt->back, rpt->a, rpt->b, rpt->x, rpt->y); + printf("dpad_u: %d d: %d l: %d r: %d bump_l: %d r: %d stick_l: %d r: %d\n", + rpt->dpad_up, rpt->dpad_down, rpt->dpad_left, rpt->dpad_right, + rpt->bumper_left, rpt->bumper_right, rpt->stick_click_left, rpt->stick_click_right); + printf("stick_left_x: %d y: %d right_x: %d y: %d trigger_l: %d r: %d\n", + rpt->stick_left_x, rpt->stick_left_y, rpt->stick_right_x, rpt->stick_right_y, + rpt->trigger_left, rpt->trigger_right); + } + } + } + while (nbytes > 0); + + printf("Closing device %s: %d\n", CONFIG_EXAMPLES_XBC_DEVNAME, (int)nbytes); + fflush(stdout); + close(fd); + break; + } + + return 0; +}