group light and leds together; use PLATFORM_HAS defines

This commit is contained in:
Mariano Alvira 2011-05-27 11:00:24 -04:00
parent 77ec0bfa0f
commit 97f70a2334

View file

@ -5,12 +5,18 @@
#include "contiki-net.h"
#include "rest.h"
#if defined (CONTIKI_TARGET_SKY) /* Any other targets will be added here (&& defined (OTHER))*/
#if defined (PLATFROM_HAS_LIGHT)
#include "dev/light-sensor.h"
#endif
#if defined (PLATFORM_HAS_BATT)
#include "dev/battery-sensor.h"
#endif
#if defined (PLATFORM_HAS_SHT11)
#include "dev/sht11-sensor.h"
#endif
#if defined (PLATFORM_HAS_LEDS)
#include "dev/leds.h"
#endif /*defined (CONTIKI_TARGET_SKY)*/
#endif
#define DEBUG 1
#if DEBUG
@ -48,14 +54,44 @@ discover_handler(REQUEST* request, RESPONSE* response)
char temp[100];
int index = 0;
index += sprintf(temp + index, "%s,", "</helloworld>;n=\"HelloWorld\"");
#if defined (PLATFORM_HAS_LEDS)
index += sprintf(temp + index, "%s,", "</led>;n=\"LedControl\"");
#endif
#if defined (PLATFORM_HAS_LIGHT)
index += sprintf(temp + index, "%s", "</light>;n=\"Light\"");
#endif
rest_set_response_payload(response, (uint8_t*)temp, strlen(temp));
rest_set_header_content_type(response, APPLICATION_LINK_FORMAT);
}
#if defined (CONTIKI_TARGET_SKY)
#if defined (PLATFORM_HAS_LIGHT)
uint16_t light_photosynthetic;
uint16_t light_solar;
void
read_light_sensor(uint16_t* light_1, uint16_t* light_2)
{
*light_1 = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
*light_2 = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);
}
/*A simple getter example. Returns the reading from light sensor with a simple etag*/
RESOURCE(light, METHOD_GET, "light");
void
light_handler(REQUEST* request, RESPONSE* response)
{
read_light_sensor(&light_photosynthetic, &light_solar);
sprintf(temp,"%u;%u", light_photosynthetic, light_solar);
char etag[4] = "ABCD";
rest_set_header_content_type(response, TEXT_PLAIN);
rest_set_header_etag(response, etag, sizeof(etag));
rest_set_response_payload(response, temp, strlen(temp));
}
#endif /*PLATFORM_HAS_LIGHT*/
#if defined (PLATFORM_HAS_LEDS)
/*A simple actuator example, depending on the color query parameter and post variable mode, corresponding led is activated or deactivated*/
RESOURCE(led, METHOD_POST | METHOD_PUT , "led");
@ -102,33 +138,6 @@ led_handler(REQUEST* request, RESPONSE* response)
}
}
uint16_t light_photosynthetic;
uint16_t light_solar;
void
read_light_sensor(uint16_t* light_1, uint16_t* light_2)
{
*light_1 = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
*light_2 = light_sensor.value(LIGHT_SENSOR_TOTAL_SOLAR);
}
/*A simple getter example. Returns the reading from light sensor with a simple etag*/
RESOURCE(light, METHOD_GET, "light");
void
light_handler(REQUEST* request, RESPONSE* response)
{
#ifdef CONTIKI_TARGET_SKY
read_light_sensor(&light_photosynthetic, &light_solar);
sprintf(temp,"%u;%u", light_photosynthetic, light_solar);
#else /*CONTIKI_TARGET_SKY*/
sprintf(temp,"%d.%d", 0, 0);
#endif /*CONTIKI_TARGET_SKY*/
char etag[4] = "ABCD";
rest_set_header_content_type(response, TEXT_PLAIN);
rest_set_header_etag(response, etag, sizeof(etag));
rest_set_response_payload(response, temp, strlen(temp));
}
/*A simple actuator example. Toggles the red led*/
RESOURCE(toggle, METHOD_GET | METHOD_PUT | METHOD_POST, "toggle");
@ -137,7 +146,7 @@ toggle_handler(REQUEST* request, RESPONSE* response)
{
leds_toggle(LEDS_RED);
}
#endif /*defined (CONTIKI_TARGET_SKY)*/
#endif /*defined (CONTIKI_HAS_LEDS)*/
PROCESS(rest_server_example, "Rest Server Example");
@ -155,12 +164,14 @@ PROCESS_THREAD(rest_server_example, ev, data)
rest_init();
#if defined (CONTIKI_TARGET_SKY)
#if defined (PLATFORM_HAS_LIGHT)
SENSORS_ACTIVATE(light_sensor);
rest_activate_resource(&resource_led);
rest_activate_resource(&resource_light);
#endif
#if defined (PLATFORM_HAS_LEDS)
rest_activate_resource(&resource_led);
rest_activate_resource(&resource_toggle);
#endif /*defined (CONTIKI_TARGET_SKY)*/
#endif /*defined (PLATFORM_HAS_LEDS)*/
rest_activate_resource(&resource_helloworld);
rest_activate_resource(&resource_discover);