added activation of button sensor and activation and deactivation / toggle of light sensor

This commit is contained in:
joxe 2010-02-02 21:17:32 +00:00
parent e21c1a39d3
commit e198b4508b

View file

@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* $Id: test-button.c,v 1.3 2010/02/01 17:40:33 nifi Exp $
* $Id: test-button.c,v 1.4 2010/02/02 21:17:32 joxe Exp $
*/
/**
@ -38,6 +38,7 @@
* Adam Dunkels <adam@sics.se>
*/
#include <stdio.h>
#include "contiki.h"
#include "dev/button-sensor.h"
#include "dev/light-sensor.h"
@ -48,17 +49,25 @@
PROCESS(test_button_process, "Test button");
AUTOSTART_PROCESSES(&test_button_process);
/*---------------------------------------------------------------------------*/
static uint8_t active;
PROCESS_THREAD(test_button_process, ev, data)
{
PROCESS_BEGIN();
SENSORS_ACTIVATE(light_sensor);
SENSORS_ACTIVATE(button_sensor);
while(1) {
PROCESS_WAIT_EVENT_UNTIL(ev == sensors_event &&
data == &button_sensor);
leds_toggle(LEDS_ALL);
printf("Light: %d\n", light_sensor.value(0));
if (!active) {
/* activate light sensor */
SENSORS_ACTIVATE(light_sensor);
printf("Light: %d\n", light_sensor.value(0));
} else {
/* deactivate light sensor */
printf("Light: %d\n", light_sensor.value(0));
SENSORS_DEACTIVATE(light_sensor);
}
leds_toggle(LEDS_ALL);
}
PROCESS_END();