move res_red .. to resources folder

This commit is contained in:
Harald Pichler 2016-11-04 08:40:58 +01:00
parent d66e402cad
commit 646bb077ef
3 changed files with 44 additions and 31 deletions

View file

@ -40,6 +40,7 @@
#include <string.h> #include <string.h>
#include "rest-engine.h" #include "rest-engine.h"
#include "generic_resource.h"
#include "Arduino.h" #include "Arduino.h"
#include "sketch.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); 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

View file

@ -2,8 +2,15 @@
#define __SKETCH_h__ #define __SKETCH_h__
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C" {
#endif #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); int color_rgb_from_string (const char *r, const char *g, const char *b);
#ifdef __cplusplus
}
#endif
#endif #endif

View file

@ -18,12 +18,16 @@ extern "C" {
#include "net/netstack.h" #include "net/netstack.h"
#include "dev/button-sensor.h" #include "dev/button-sensor.h"
#include "ChainableLED.h" #include "ChainableLED.h"
#include "sketch.h"
} }
extern resource_t extern resource_t
res_led, res_led,
res_bled, res_bled,
res_rgb, res_rgb,
res_red,
res_green,
res_blue,
res_battery, res_battery,
res_cputemp, res_cputemp,
res_event, res_event,
@ -63,13 +67,13 @@ name_to_offset (const char * name)
return offset; return offset;
} }
static size_t extern "C" size_t
color_to_string (const char *name, const char *uri, char *buf, size_t bsize) 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)]); 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_from_string (const char *name, const char *uri, const char *s)
{ {
color_rgb [name_to_offset (name)] = atoi (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; 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) void setup (void)
{ {