add leds and battery

This commit is contained in:
Harald Pichler 2014-12-09 14:36:06 +01:00
parent a4b1e0138a
commit 248a1e3882
3 changed files with 26 additions and 12 deletions

View file

@ -73,17 +73,18 @@ extern resource_t
res_sub, res_sub,
res_b1_sep_b2; res_b1_sep_b2;
#if PLATFORM_HAS_LEDS #if PLATFORM_HAS_LEDS
#include "dev/leds.h"
extern resource_t res_leds, res_toggle; extern resource_t res_leds, res_toggle;
#endif #endif
#if PLATFORM_HAS_LIGHT #if PLATFORM_HAS_LIGHT
#include "dev/light-sensor.h" #include "dev/light-sensor.h"
extern resource_t res_light; extern resource_t res_light;
#endif #endif
/*
#if PLATFORM_HAS_BATTERY #if PLATFORM_HAS_BATTERY
#include "dev/battery-sensor.h" #include "dev/battery-sensor.h"
extern resource_t res_battery; extern resource_t res_battery;
#endif #endif
/*
#if PLATFORM_HAS_RADIO #if PLATFORM_HAS_RADIO
#include "dev/radio-sensor.h" #include "dev/radio-sensor.h"
extern resource_t res_radio; extern resource_t res_radio;
@ -94,6 +95,14 @@ extern resource_t res_sht11;
#endif #endif
*/ */
void
hw_init()
{
#if defined (PLATFORM_HAS_LEDS)
leds_off(LEDS_RED);
#endif
}
PROCESS(er_example_server, "Erbium Example Server"); PROCESS(er_example_server, "Erbium Example Server");
AUTOSTART_PROCESSES(&er_example_server); AUTOSTART_PROCESSES(&er_example_server);
@ -117,6 +126,7 @@ PROCESS_THREAD(er_example_server, ev, data)
PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN); PRINTF("IP+UDP header: %u\n", UIP_IPUDPH_LEN);
PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE); PRINTF("REST max chunk: %u\n", REST_MAX_CHUNK_SIZE);
hw_init();
/* Initialize the REST engine. */ /* Initialize the REST engine. */
rest_init_engine(); rest_init_engine();
@ -130,28 +140,29 @@ PROCESS_THREAD(er_example_server, ev, data)
/* rest_activate_resource(&res_chunks, "test/chunks"); */ /* rest_activate_resource(&res_chunks, "test/chunks"); */
/* rest_activate_resource(&res_separate, "test/separate"); */ /* rest_activate_resource(&res_separate, "test/separate"); */
rest_activate_resource(&res_push, "test/push"); rest_activate_resource(&res_push, "test/push");
/* rest_activate_resource(&res_event, "sensors/button"); */ /* rest_activate_resource(&res_event, "s/button"); */
/* rest_activate_resource(&res_sub, "test/sub"); */ /* rest_activate_resource(&res_sub, "test/sub"); */
/* rest_activate_resource(&res_b1_sep_b2, "test/b1sepb2"); */ /* rest_activate_resource(&res_b1_sep_b2, "test/b1sepb2"); */
#if PLATFORM_HAS_LEDS #if PLATFORM_HAS_LEDS
/* rest_activate_resource(&res_leds, "actuators/leds"); */ /* rest_activate_resource(&res_leds, "a/leds"); */
rest_activate_resource(&res_toggle, "actuators/toggle"); rest_activate_resource(&res_toggle, "a/toggle");
#endif #endif
#if PLATFORM_HAS_LIGHT #if PLATFORM_HAS_LIGHT
rest_activate_resource(&res_light, "sensors/light"); rest_activate_resource(&res_light, "s/light");
SENSORS_ACTIVATE(light_sensor); SENSORS_ACTIVATE(light_sensor);
#endif #endif
/*
#if PLATFORM_HAS_BATTERY #if PLATFORM_HAS_BATTERY
rest_activate_resource(&res_battery, "sensors/battery"); rest_activate_resource(&res_battery, "s/battery");
SENSORS_ACTIVATE(battery_sensor); SENSORS_ACTIVATE(battery_sensor);
#endif #endif
/*
#if PLATFORM_HAS_RADIO #if PLATFORM_HAS_RADIO
rest_activate_resource(&res_radio, "sensors/radio"); rest_activate_resource(&res_radio, "s/radio");
SENSORS_ACTIVATE(radio_sensor); SENSORS_ACTIVATE(radio_sensor);
#endif #endif
#if PLATFORM_HAS_SHT11 #if PLATFORM_HAS_SHT11
rest_activate_resource(&res_sht11, "sensors/sht11"); rest_activate_resource(&res_sht11, "s/sht11");
SENSORS_ACTIVATE(sht11_sensor); SENSORS_ACTIVATE(sht11_sensor);
#endif #endif
*/ */

View file

@ -39,6 +39,9 @@
#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_BATTERY 1
/* Custom channel and PAN ID configuration for your project. */ /* Custom channel and PAN ID configuration for your project. */
/* /*
#undef RF_CHANNEL #undef RF_CHANNEL

View file

@ -64,12 +64,12 @@ res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferr
if(accept == -1 || accept == REST.type.TEXT_PLAIN) { if(accept == -1 || accept == REST.type.TEXT_PLAIN) {
REST.set_header_content_type(response, REST.type.TEXT_PLAIN); REST.set_header_content_type(response, REST.type.TEXT_PLAIN);
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", battery); snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d.%02d", battery/1000, battery % 1000);
REST.set_response_payload(response, (uint8_t *)buffer, strlen((char *)buffer)); REST.set_response_payload(response, buffer, strlen((char *)buffer));
} else if(accept == REST.type.APPLICATION_JSON) { } else if(accept == REST.type.APPLICATION_JSON) {
REST.set_header_content_type(response, REST.type.APPLICATION_JSON); REST.set_header_content_type(response, REST.type.APPLICATION_JSON);
snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'battery':%d}", battery); snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'battery':%d.%02d}", battery/1000, battery % 1000);
REST.set_response_payload(response, buffer, strlen((char *)buffer)); REST.set_response_payload(response, buffer, strlen((char *)buffer));
} else { } else {