Merged in webbbn/apps/xbox_one_controller (pull request #68)
Adds a test program for the XBox One controller driver (xbc_test). Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
commit
3b5302e6ec
11
examples/xbc_test/.gitignore
vendored
Normal file
11
examples/xbc_test/.gitignore
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
/Make.dep
|
||||
/.depend
|
||||
/.built
|
||||
/*.asm
|
||||
/*.obj
|
||||
/*.rel
|
||||
/*.lst
|
||||
/*.sym
|
||||
/*.adb
|
||||
/*.lib
|
||||
/*.src
|
36
examples/xbc_test/Kconfig
Normal file
36
examples/xbc_test/Kconfig
Normal file
@ -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
|
42
examples/xbc_test/Make.defs
Normal file
42
examples/xbc_test/Make.defs
Normal file
@ -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 <gnutt@nuttx.org>
|
||||
#
|
||||
# Copyright (C) 2017 Brian Webb. All rights reserved.
|
||||
# Author: Brian Webb <webbbn@gmail.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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_XBC_TEST),y)
|
||||
CONFIGURED_APPS += examples/xbc_test
|
||||
endif
|
59
examples/xbc_test/Makefile
Normal file
59
examples/xbc_test/Makefile
Normal file
@ -0,0 +1,59 @@
|
||||
############################################################################
|
||||
# apps/examples/hello/Makefile
|
||||
#
|
||||
# Copyright (C) 2008, 2010-2013 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Copyright (C) 2017 Brian Webb. All rights reserved.
|
||||
# Author: Brian Webb <webbbn@gmail.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.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
-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
|
157
examples/xbc_test/xbc_test_main.c
Normal file
157
examples/xbc_test/xbc_test_main.c
Normal file
@ -0,0 +1,157 @@
|
||||
/****************************************************************************
|
||||
* examples/xbc_test/xbc_test_main.c
|
||||
*
|
||||
* Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Copyright (C) 2017 Brian Webb. All rights reserved.
|
||||
* Author: Brian Webb <webbbn@gmail.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/ioctl.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/input/xbox-controller.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user