void stm32_pm_buttons(void) { /* Initialize the button GPIOs */ board_button_initialize(); #ifdef CONFIG_ARCH_IRQBUTTONS (void)board_button_irq(0, button_handler, NULL); #endif }
void stm32_pm_buttons(void) { /* Initialize the button GPIOs */ board_button_initialize(); #ifdef CONFIG_ARCH_IRQBUTTONS xcpt_t oldhandler = board_button_irq(0, button_handler); if (oldhandler != NULL) { lowsyslog(LOG_WARNING, "WARNING: oldhandler:%p is not NULL! " "Button events may be lost or aliased!\n", oldhandler); } #endif }
void up_pmbuttons(void) { /* Initialize the button GPIOs */ board_button_initialize(); #ifdef CONFIG_ARCH_IRQBUTTONS int i; for (i = CONFIG_PM_IRQBUTTONS_MIN; i <= CONFIG_PM_IRQBUTTONS_MAX; i++) { xcpt_t oldhandler = board_button_irq(i, g_buttonhandlers[BUTTON_INDEX(i)]); if (oldhandler != NULL) { lowsyslog(LOG_WARNING, "WARNING: oldhandler:%p is not NULL! " "Button events may be lost or aliased!\n", oldhandler); } } #endif }
int buttons_main(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); } lowsyslog("maxbuttons: %d\n", maxbuttons); #endif /* Initialize the button GPIOs */ board_button_initialize(); /* Register to recieve button interrupts */ #ifdef CONFIG_ARCH_IRQBUTTONS for (i = CONFIG_EXAMPLES_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLES_IRQBUTTONS_MAX; i++) { xcpt_t oldhandler = board_button_irq(i, g_buttoninfo[BUTTON_INDEX(i)].handler); /* Use lowsyslog() for compatibility with interrrupt handler output. */ lowsyslog("Attached handler at %p to button %d [%s], oldhandler:%p\n", g_buttoninfo[BUTTON_INDEX(i)].handler, i, g_buttoninfo[BUTTON_INDEX(i)].name, oldhandler); /* Some hardware multiplexes different GPIO button sources to the same * physical interrupt. If we register multiple such multiplexed button * interrupts, then the second registration will overwrite the first. In * this case, the first button interrupts may be aliased to the second * interrupt handler (or worse, could be lost). */ if (oldhandler != NULL) { lowsyslog("WARNING: oldhandler:%p is not NULL! " "Button events may be lost or aliased!\n", oldhandler); } } #endif /* Poll button state */ g_oldset = board_buttons(); #ifdef CONFIG_NSH_BUILTIN_APPS while (g_nbuttons < maxbuttons) #else for (;;) #endif { /* Get the set of pressed and release buttons. */ newset = board_buttons(); /* Any changes from the last sample? */ if (newset != g_oldset) { /* Disable interrupts so that output here will not collide with * output from an interrupt handler. */ flags = irqsave(); /* Use lowsyslog() for compatibility with interrrupt handler * output. */ lowsyslog("POLL SET:%02x:\n", newset); show_buttons(g_oldset, newset); g_oldset = newset; irqrestore(flags); } /* Sleep a little... but not long. This will determine how fast we * poll for button changes. */ usleep(150000); /* 150 Milliseconds */ } /* Un-register button handlers */ #if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_NSH_BUILTIN_APPS) for (i = CONFIG_EXAMPLES_IRQBUTTONS_MIN; i <= CONFIG_EXAMPLES_IRQBUTTONS_MAX; i++) { (void)board_button_irq(i, NULL); } #endif return 0; }
static int gsensor_daemon(int argc, char *argv[]){ g_gsensor_started = true; struct adc_msg_s sample[CONFIG_MYAPPS_GSENSOR_GROUPSIZE]; size_t readsize; ssize_t nbytes; int errval = 0; int ret; int i,j; int am_channel,am_data; /* Check if we have initialized */ if (!g_adcstate.initialized) { /* Initialization of the ADC hardware is performed by logic external to * this test. */ printf("adc_main here: Initializing external ADC device\n"); ret = board_gsensoradc_setup(); if (ret < 0) { printf("adc_main here: boardctl failed: %d\n", errno); errval = 1; goto errout; } /* Set the default values */ adc_devpath(&g_adcstate, CONFIG_MYAPPS_GSENSOR_DEVPATH); #if CONFIG_MYAPPS_GSENSOR_NSAMPLES > 0 g_adcstate.count = CONFIG_MYAPPS_GSENSOR_NSAMPLES; #else g_adcstate.count = 1; #endif g_adcstate.initialized = true; } /* 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 */ #if defined(CONFIG_NSH_BUILTIN_APPS) || CONFIG_MYAPPS_GSENSOR_NSAMPLES > 0 printf("adc_main: g_adcstate.count: %d\n", g_adcstate.count); #endif /* Open the ADC device for reading */ printf("adc_main: Hardware initialized. Opening the ADC device: %s\n", g_adcstate.devpath); fd = open(g_adcstate.devpath, O_RDONLY); if (fd < 0) { printf("adc_main: open %s failed: %d\n", g_adcstate.devpath, errno); errval = 2; goto errout; } fp = fopen("/sdcard/TEST.txt", "w"); if (fp < 0) { printf("error opening TEST.TXT"); return 1; } board_button_initialize(); xcpt_t oldhandler = board_button_irq(0, button_handler); /* Use lowsyslog() for compatibility with interrupt handler output. */ lowsyslog(LOG_INFO, "Attached handler at %p to button 0 [User button], oldhandler:%p\n", button_handler, oldhandler); /* Now loop the appropriate number of times, displaying the collected * ADC samples. */ /* #if defined(CONFIG_NSH_BUILTIN_APPS) for (; g_adcstate.count > 0; g_adcstate.count--) #elif CONFIG_MYAPPS_GSENSOR_NSAMPLES > 0 for (g_adcstate.count = 0; g_adcstate.count < CONFIG_MYAPPS_GSENSOR_NSAMPLES; g_adcstate.count++) #else for (;;) #endif*/ while(cont_gsensor) { /* Flush any output before the loop entered or from the previous pass * through the loop. */ //fflush(stdout); printf("\nSample number %d\n",++j); fprintf(fp,"\nSample number %d\n",j); #ifdef CONFIG_MYAPPS_GSENSOR_SWTRIG /* Issue the software trigger to start ADC conversion */ ret = ioctl(fd, ANIOC_TRIGGER, 0); if (ret < 0) { int errcode = errno; printf("adc_main: ANIOC_TRIGGER ioctl failed: %d\n", errcode); } #endif /* Read up to CONFIG_MYAPPS_ADC_GROUPSIZE samples */ readsize = CONFIG_MYAPPS_GSENSOR_GROUPSIZE * sizeof(struct adc_msg_s); nbytes = read(fd, sample, readsize); /* Handle unexpected return values */ if (nbytes < 0) { errval = errno; if (errval != EINTR) { printf("adc_main: read %s failed: %d\n", g_adcstate.devpath, errval); errval = 3; goto errout_with_dev; } printf("adc_main: Interrupted read...\n"); } else if (nbytes == 0) { printf("adc_main: No data read, Ignoring\n"); } /* Print the sample data on successful return */ else { int nsamples = nbytes / sizeof(struct adc_msg_s); if (nsamples * sizeof(struct adc_msg_s) != nbytes) { printf("adc_main: read size=%ld is not a multiple of sample size=%d, Ignoring\n", (long)nbytes, sizeof(struct adc_msg_s)); } else { printf("Sample:\n"); for (i = 0; i < nsamples; i++) { am_channel = sample[i].am_channel; am_data = sample[i].am_data; printf("%d: channel: %d value: %d\n", i+1,am_channel , am_data); fprintf(fp,"%d: channel: %d value: %d\n", i+1, am_channel, am_data); if(am_data >3500){ printf("Environment in channel %d too dry\n",am_channel); }else if(am_data <1000){ printf("Environment in channel %d too wet\n",am_channel); }else{ printf("Environment in channel %d is perfect\n",am_channel); } fflush(fp); } } } usleep(150000); } (void)board_button_irq(0, NULL); fclose(fp); close(fd); task_delete(g_gsensor_pid); /* Error exits */ errout_with_dev: (void)board_button_irq(0, NULL); fclose(fp); close(fd); task_delete(g_gsensor_pid); errout: printf("Terminating!\n"); fflush(stdout); task_delete(g_gsensor_pid); }