From cf40f59843cdc010a5cf205a87cd5ce042acf855 Mon Sep 17 00:00:00 2001 From: Harald Pichler Date: Mon, 15 Aug 2016 20:22:49 +0200 Subject: [PATCH] add pin status --- cpu/avr/dev/button-sensor.c | 6 ++++-- examples/osd/triggerbaord/project-conf.h | 12 +++--------- examples/osd/triggerbaord/resources/res-event.c | 17 +++++++++++++++-- platform/osd-merkur-256/contiki-conf.h | 3 +++ 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/cpu/avr/dev/button-sensor.c b/cpu/avr/dev/button-sensor.c index 067df7246..cb50259ba 100644 --- a/cpu/avr/dev/button-sensor.c +++ b/cpu/avr/dev/button-sensor.c @@ -11,6 +11,7 @@ const struct sensors_sensor button_sensor; static struct timer debouncetimer; static int status(int type); static int enabled = 0; +volatile static int bstate; struct sensors_sensor *sensors[1]; unsigned char sensors_flags[1]; @@ -28,6 +29,7 @@ ISR(INT4_vect) if(timer_expired(&debouncetimer)) { // led1_on(); timer_set(&debouncetimer, CLOCK_SECOND / 8); + bstate = (PINE & _BV(PE4) ? 0 : 1); sensors_changed(&button_sensor); // led1_off(); } @@ -39,9 +41,9 @@ ISR(INT4_vect) static int value(int type) { - return (PINE & _BV(PE4) ? 0 : 1) || !timer_expired(&debouncetimer); + //return (PINE & _BV(PE4) ? 0 : 1) || !timer_expired(&debouncetimer); - //return 0; + return bstate; } static int diff --git a/examples/osd/triggerbaord/project-conf.h b/examples/osd/triggerbaord/project-conf.h index 510c66786..a0808564f 100644 --- a/examples/osd/triggerbaord/project-conf.h +++ b/examples/osd/triggerbaord/project-conf.h @@ -51,8 +51,8 @@ //#define NETSTACK_CONF_RDC nullrdc_driver /* Increase rpl-border-router IP-buffer when using more than 64. */ -#undef REST_MAX_CHUNK_SIZE -#define REST_MAX_CHUNK_SIZE 64 +//#undef REST_MAX_CHUNK_SIZE +//#define REST_MAX_CHUNK_SIZE 64 /* Estimate your header size, especially when using Proxy-Uri. */ /* @@ -68,7 +68,7 @@ /* Multiplies with chunk size, be aware of memory constraints. */ #undef COAP_MAX_OPEN_TRANSACTIONS -#define COAP_MAX_OPEN_TRANSACTIONS 4 +#define COAP_MAX_OPEN_TRANSACTIONS 8 /* Must be <= open transaction number, default is COAP_MAX_OPEN_TRANSACTIONS-1. */ /* @@ -82,10 +82,4 @@ #define COAP_LINK_FORMAT_FILTERING 0 */ - - - - - - #endif /* PROJECT_RPL_WEB_CONF_H_ */ diff --git a/examples/osd/triggerbaord/resources/res-event.c b/examples/osd/triggerbaord/resources/res-event.c index 7524d2ad2..8bc68102d 100644 --- a/examples/osd/triggerbaord/resources/res-event.c +++ b/examples/osd/triggerbaord/resources/res-event.c @@ -39,6 +39,7 @@ #include #include "rest-engine.h" #include "er-coap.h" +#include "dev/button-sensor.h" #define DEBUG 0 #if DEBUG @@ -76,8 +77,20 @@ static int32_t event_counter = 0; static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) { - REST.set_header_content_type(response, REST.type.TEXT_PLAIN); - REST.set_response_payload(response, buffer, snprintf((char *)buffer, preferred_size, "EVENT %lu", event_counter)); + int buttonstate = button_sensor.value(0); + + unsigned int accept = -1; + REST.get_header_accept(request, &accept); + if(accept == -1 || accept == REST.type.TEXT_PLAIN) { + REST.set_header_content_type(response, REST.type.TEXT_PLAIN); + REST.set_response_payload(response, buffer, snprintf((char *)buffer, preferred_size, "EVENT %lu STATE %d", event_counter, buttonstate)); + } else if(accept == REST.type.APPLICATION_JSON) { + REST.set_header_content_type(response, REST.type.APPLICATION_JSON); + REST.set_response_payload(response, buffer, snprintf((char *)buffer, preferred_size, "{'EVENT':%lu ,'STATE': %d}", event_counter, buttonstate)); + } else { + REST.set_response_status(response, REST.status.NOT_ACCEPTABLE); + REST.set_response_payload(response, buffer, snprintf((char *)buffer, preferred_size, "Supporting content-types text/plain and application/json")); + } /* A post_handler that handles subscriptions/observing will be called for periodic resources by the framework. */ } diff --git a/platform/osd-merkur-256/contiki-conf.h b/platform/osd-merkur-256/contiki-conf.h index fb8cf3178..519d86d86 100644 --- a/platform/osd-merkur-256/contiki-conf.h +++ b/platform/osd-merkur-256/contiki-conf.h @@ -174,6 +174,8 @@ typedef unsigned short uip_stats_t; #define NETSTACK_CONF_RDC sicslowmac_driver #define NETSTACK_CONF_FRAMER framer_802154 #define NETSTACK_CONF_RADIO rf230_driver +/* CCA theshold energy -91 to -61 dBm (default -77). Set this smaller than the $ */ +#define RF230_CONF_CCA_THRES -85 /* AUTOACK receive mode gives better rssi measurements, even if ACK is never requested */ #define RF230_CONF_AUTOACK 1 /* Request 802.15.4 ACK on all packets sent (else autoretry). This is primarily for testing. */ @@ -228,6 +230,7 @@ typedef unsigned short uip_stats_t; #define CONTIKIMAC_CONF_WITH_PHASE_OPTIMIZATION 0 #define CONTIKIMAC_CONF_COMPOWER 1 #define RIMESTATS_CONF_ENABLED 0 +#define WITH_FAST_SLEEP 0 #if NETSTACK_CONF_WITH_IPV6 #define NETSTACK_CONF_FRAMER framer_802154