Button test can now be built as an NSH command
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4091 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
514525e3fe
commit
d336bb2958
@ -127,6 +127,9 @@
|
||||
|
||||
6.11 2011-11-12 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
(No major changes from 6.10)
|
||||
(No major changes from 6.10)
|
||||
|
||||
6.12 2011-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/buttons: The button test can now be executed as an NSH
|
||||
built in command.
|
||||
|
@ -56,12 +56,18 @@ endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# Buttons built-in application info
|
||||
|
||||
APPNAME = buttons
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
STACKSIZE = 2048
|
||||
|
||||
# Common build
|
||||
|
||||
VPATH =
|
||||
|
||||
all: .built
|
||||
.PHONY: clean depend distclean
|
||||
.PHONY: context clean depend distclean
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
@ -75,7 +81,13 @@ $(COBJS): %$(OBJEXT): %.c
|
||||
done ; )
|
||||
@touch .built
|
||||
|
||||
context:
|
||||
.context:
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||
@touch $@
|
||||
endif
|
||||
|
||||
context: .context
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) $(ROOTDEPPATH) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <debug.h>
|
||||
|
||||
@ -129,6 +130,16 @@
|
||||
#define NUM_BUTTONS (MAX_BUTTON - MIN_BUTTON + 1)
|
||||
#define BUTTON_INDEX(b) ((b)-MIN_BUTTON)
|
||||
|
||||
/* Is this being built as an NSH built-in application? */
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
# define MAIN_NAME buttons_main
|
||||
# define MAIN_STRING "buttons_main: "
|
||||
#else
|
||||
# define MAIN_NAME user_start
|
||||
# define MAIN_STRING "user_start: "
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@ -254,8 +265,14 @@ static const struct button_info_s g_buttoninfo[NUM_BUTTONS] =
|
||||
|
||||
static uint8_t g_oldset;
|
||||
|
||||
/* Used to limit the number of button presses */
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
static volatile long g_nbuttons;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static void show_buttons(uint8_t oldset, uint8_t newset)
|
||||
@ -263,6 +280,17 @@ static void show_buttons(uint8_t oldset, uint8_t newset)
|
||||
uint8_t chgset = oldset ^ newset;
|
||||
int i;
|
||||
|
||||
/* Update the count of button presses shown */
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
if ((chgset & newset) != 0)
|
||||
{
|
||||
g_nbuttons++;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Show each button state change */
|
||||
|
||||
for (i = MIN_BUTTON; i <= MAX_BUTTON; i++)
|
||||
{
|
||||
uint8_t mask = (1 << i);
|
||||
@ -295,7 +323,7 @@ static void button_handler(int id, int irq)
|
||||
{
|
||||
uint8_t newset = up_buttons();
|
||||
|
||||
lib_lowprintf("IRQ:%d Button %d:%s IRQ:%d SET:%02x:\n",
|
||||
lib_lowprintf("IRQ:%d Button %d:%s SET:%02x:\n",
|
||||
irq, id, g_buttoninfo[BUTTON_INDEX(id)].name, newset);
|
||||
show_buttons(g_oldset, newset);
|
||||
g_oldset = newset;
|
||||
@ -367,15 +395,33 @@ static int button7_handler(int irq, FAR void *context)
|
||||
#endif /* CONFIG_ARCH_IRQBUTTONS */
|
||||
|
||||
/****************************************************************************
|
||||
* user_start
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
int user_start(int argc, char *argv[])
|
||||
/****************************************************************************
|
||||
* user_start/buttons_main
|
||||
****************************************************************************/
|
||||
|
||||
int MAIN_NAME(int argc, char *argv[])
|
||||
{
|
||||
uint8_t newset;
|
||||
irqstate_t flags;
|
||||
int i;
|
||||
|
||||
/* If this example is configured as an NX add-on, then limit the number of
|
||||
* samples that we collect before returning. Otherwise, we never return
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
long maxbuttons = 1;
|
||||
g_nbuttons = 0;
|
||||
if (argc > 1)
|
||||
{
|
||||
maxbuttons = strtol(argv[1], NULL, 10);
|
||||
}
|
||||
lib_lowprintf("maxbuttons: %d\n", maxbuttons);
|
||||
#endif
|
||||
|
||||
/* Register to recieve button interrupts */
|
||||
|
||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
||||
@ -408,7 +454,11 @@ int user_start(int argc, char *argv[])
|
||||
/* Poll button state */
|
||||
|
||||
g_oldset = up_buttons();
|
||||
#ifdef CONFIG_NSH_BUILTIN_APPS
|
||||
while (g_nbuttons < maxbuttons)
|
||||
#else
|
||||
for (;;)
|
||||
#endif
|
||||
{
|
||||
/* Get the set of pressed and release buttons. */
|
||||
|
||||
@ -440,6 +490,16 @@ int user_start(int argc, char *argv[])
|
||||
|
||||
usleep(150000); /* 150 Milliseconds */
|
||||
}
|
||||
|
||||
/* Un-register button handlers */
|
||||
|
||||
#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_NSH_BUILTIN_APPS)
|
||||
for (i = CONFIG_EXAMPLE_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLE_IRQBUTTONS_MAX; i++)
|
||||
{
|
||||
(void)up_irqbutton(i, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ endif
|
||||
|
||||
ROOTDEPPATH = --dep-path .
|
||||
|
||||
# NXHELLO built-in application info
|
||||
# Touchscreen built-in application info
|
||||
|
||||
APPNAME = tc
|
||||
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||
|
Loading…
x
Reference in New Issue
Block a user