diff --git a/examples/osd/opentrigger-board/resources/res-rgb.c b/examples/osd/opentrigger-board/resources/res-rgb.c index 8ff074c68..68e34993d 100644 --- a/examples/osd/opentrigger-board/resources/res-rgb.c +++ b/examples/osd/opentrigger-board/resources/res-rgb.c @@ -40,6 +40,7 @@ #include #include "rest-engine.h" +#include "generic_resource.h" #include "Arduino.h" #include "sketch.h" @@ -117,3 +118,32 @@ res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t pr REST.set_response_status(response, REST.status.BAD_REQUEST); } } + +#pragma GCC diagnostic ignored "-Wwrite-strings" +GENERIC_RESOURCE + ( red + , RED_LED + , s + , 1 + , color_from_string + , color_to_string + ); + +GENERIC_RESOURCE + ( green + , GREEN_LED + , s + , 1 + , color_from_string + , color_to_string + ); + +GENERIC_RESOURCE + ( blue + , BLUE_LED + , s + , 1 + , color_from_string + , color_to_string + ); +#pragma GCC diagnostic pop diff --git a/examples/osd/opentrigger-board/sketch.h b/examples/osd/opentrigger-board/sketch.h index 5616a1651..065d302d3 100644 --- a/examples/osd/opentrigger-board/sketch.h +++ b/examples/osd/opentrigger-board/sketch.h @@ -2,8 +2,15 @@ #define __SKETCH_h__ #ifdef __cplusplus -extern "C" +extern "C" { #endif + +size_t color_to_string (const char *name, const char *uri, char *buf, size_t bsize); +int color_from_string (const char *name, const char *uri, const char *s); int color_rgb_from_string (const char *r, const char *g, const char *b); +#ifdef __cplusplus +} +#endif + #endif diff --git a/examples/osd/opentrigger-board/sketch.pde b/examples/osd/opentrigger-board/sketch.pde index a4b1d3767..d6bb0c754 100755 --- a/examples/osd/opentrigger-board/sketch.pde +++ b/examples/osd/opentrigger-board/sketch.pde @@ -18,12 +18,16 @@ extern "C" { #include "net/netstack.h" #include "dev/button-sensor.h" #include "ChainableLED.h" +#include "sketch.h" } extern resource_t res_led, res_bled, res_rgb, + res_red, + res_green, + res_blue, res_battery, res_cputemp, res_event, @@ -63,13 +67,13 @@ name_to_offset (const char * name) return offset; } -static size_t +extern "C" size_t color_to_string (const char *name, const char *uri, char *buf, size_t bsize) { return snprintf (buf, bsize, "%d", color_rgb [name_to_offset (name)]); } -int +extern "C" int color_from_string (const char *name, const char *uri, const char *s) { color_rgb [name_to_offset (name)] = atoi (s); @@ -87,34 +91,6 @@ color_rgb_from_string (const char *r, const char *g, const char *b) return 0; } -#pragma GCC diagnostic ignored "-Wwrite-strings" -GENERIC_RESOURCE - ( red - , RED_LED - , s - , 1 - , color_from_string - , color_to_string - ); - -GENERIC_RESOURCE - ( green - , GREEN_LED - , s - , 1 - , color_from_string - , color_to_string - ); - -GENERIC_RESOURCE - ( blue - , BLUE_LED - , s - , 1 - , color_from_string - , color_to_string - ); -#pragma GCC diagnostic pop void setup (void) {