simplified led resource to one led actuator

This commit is contained in:
Harald Pichler 2014-03-05 14:34:58 +01:00
parent 425f348daa
commit 4760891bb4
2 changed files with 15 additions and 30 deletions

View file

@ -96,7 +96,7 @@ Appendix A. Profile example
/* Define which resources to include to meet memory constraints. */ /* Define which resources to include to meet memory constraints. */
#define REST_RES_INFO 1 #define REST_RES_INFO 1
#define REST_RES_EVENT 1 #define REST_RES_EVENT 1
#define REST_RES_LEDS 1 #define REST_RES_LED 1
#define REST_RES_TOGGLE 1 #define REST_RES_TOGGLE 1
#define REST_RES_BATTERY 1 #define REST_RES_BATTERY 1
@ -105,7 +105,7 @@ Appendix A. Profile example
#if defined (PLATFORM_HAS_BUTTON) #if defined (PLATFORM_HAS_BUTTON)
#include "dev/button-sensor.h" #include "dev/button-sensor.h"
#endif #endif
#if defined (PLATFORM_HAS_LEDS) #if defined (PLATFORM_HAS_LED)
#include "dev/leds.h" #include "dev/leds.h"
#endif #endif
#if defined (PLATFORM_HAS_BATTERY) #if defined (PLATFORM_HAS_BATTERY)
@ -144,7 +144,7 @@ Appendix A. Profile example
* Resources are defined by the RESOURCE macro. * Resources are defined by the RESOURCE macro.
* Signature: resource name, the RESTful methods it handles, and its URI path (omitting the leading slash). * Signature: resource name, the RESTful methods it handles, and its URI path (omitting the leading slash).
*/ */
RESOURCE(info, METHOD_GET, "info", "title=\"Info\";rt=\"simple.dev.n""); RESOURCE(info, METHOD_GET, "info", "title=\"Info\";rt=\"simple.dev.n\"");
/* /*
* A handler function named [resource name]_handler must be implemented for each RESOURCE. * A handler function named [resource name]_handler must be implemented for each RESOURCE.
@ -217,36 +217,21 @@ event_event_handler(resource_t *r)
/******************************************************************************/ /******************************************************************************/
#if defined (PLATFORM_HAS_LEDS) #if defined (PLATFORM_HAS_LED)
/******************************************************************************/ /******************************************************************************/
#if REST_RES_LEDS #if REST_RES_LED
/*A simple actuator example, depending on the color query parameter and post variable mode, corresponding led is activated or deactivated*/ /*A simple actuator example, depending on the color query parameter and post variable mode, corresponding led is activated or deactivated*/
RESOURCE(leds, METHOD_POST | METHOD_PUT , "a/leds", "title=\"LEDs: ?color=r|g|b, POST/PUT mode=on|off\";rt=\"Control\""); RESOURCE(led, METHOD_POST | METHOD_PUT , "a/led", "title=\"LED: POST/PUT mode=on|off\";rt=\"simple.act.led\"");
void void
leds_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) led_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
{ {
size_t len = 0; size_t len = 0;
const char *color = NULL;
const char *mode = NULL; const char *mode = NULL;
uint8_t led = 0; uint8_t led = 0;
int success = 1; int success = 1;
if ((len=REST.get_query_variable(request, "color", &color))) {
PRINTF("color %.*s\n", len, color);
if (strncmp(color, "r", len)==0) {
led = LEDS_RED; led = LEDS_RED;
} else if(strncmp(color,"g", len)==0) {
led = LEDS_GREEN;
} else if (strncmp(color,"b", len)==0) {
led = LEDS_BLUE;
} else {
success = 0;
}
} else {
success = 0;
}
if (success && (len=REST.get_post_variable(request, "mode", &mode))) { if (success && (len=REST.get_post_variable(request, "mode", &mode))) {
PRINTF("mode %s\n", mode); PRINTF("mode %s\n", mode);
@ -278,7 +263,7 @@ toggle_handler(void* request, void* response, uint8_t *buffer, uint16_t preferre
leds_toggle(LEDS_RED); leds_toggle(LEDS_RED);
} }
#endif #endif
#endif /* PLATFORM_HAS_LEDS */ #endif /* PLATFORM_HAS_LED */
/******************************************************************************/ /******************************************************************************/
#if REST_RES_BATTERY && defined (PLATFORM_HAS_BATTERY) #if REST_RES_BATTERY && defined (PLATFORM_HAS_BATTERY)
@ -318,7 +303,7 @@ battery_handler(void* request, void* response, uint8_t *buffer, uint16_t preferr
void void
hw_init() hw_init()
{ {
#if defined (PLATFORM_HAS_LEDS) #if defined (PLATFORM_HAS_LED)
leds_off(LEDS_RED); leds_off(LEDS_RED);
#endif #endif
} }
@ -357,14 +342,14 @@ PROCESS_THREAD(rest_server_example, ev, data)
rest_activate_event_resource(&resource_event); rest_activate_event_resource(&resource_event);
SENSORS_ACTIVATE(button_sensor); SENSORS_ACTIVATE(button_sensor);
#endif #endif
#if defined (PLATFORM_HAS_LEDS) #if defined (PLATFORM_HAS_LED)
#if REST_RES_LEDS #if REST_RES_LED
rest_activate_resource(&resource_leds); rest_activate_resource(&resource_led);
#endif #endif
#if REST_RES_TOGGLE #if REST_RES_TOGGLE
rest_activate_resource(&resource_toggle); rest_activate_resource(&resource_toggle);
#endif #endif
#endif /* PLATFORM_HAS_LEDS */ #endif /* PLATFORM_HAS_LED */
#if defined (PLATFORM_HAS_BATTERY) && REST_RES_BATTERY #if defined (PLATFORM_HAS_BATTERY) && REST_RES_BATTERY
SENSORS_ACTIVATE(battery_sensor); SENSORS_ACTIVATE(battery_sensor);
rest_activate_resource(&resource_battery); rest_activate_resource(&resource_battery);

View file

@ -32,7 +32,7 @@
#ifndef PROJECT_ERBIUM_CONF_H_ #ifndef PROJECT_ERBIUM_CONF_H_
#define PROJECT_ERBIUM_CONF_H_ #define PROJECT_ERBIUM_CONF_H_
#define PLATFORM_HAS_LEDS 1 #define PLATFORM_HAS_LED 1
#define PLATFORM_HAS_BUTTON 1 #define PLATFORM_HAS_BUTTON 1
#define PLATFORM_HAS_TEMPERATURE 1 #define PLATFORM_HAS_TEMPERATURE 1
#define PLATFORM_HAS_BATTERY 1 #define PLATFORM_HAS_BATTERY 1