From 155e2c9b0af9087424688aa1d55542179afeba20 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sun, 5 Nov 2017 22:38:45 +0000 Subject: [PATCH] Support both old and new button API in common examples This change is temporary so travis can pass until all platforms have been migrated to the new API --- arch/platform/cc2538dk/dev/board.h | 1 + arch/platform/openmote-cc2538/board.h | 1 + arch/platform/srf06-cc26xx/contiki-conf.h | 1 + arch/platform/zoul/contiki-conf.h | 2 ++ examples/coap/coap-example-client.c | 14 +++++++++-- examples/coap/coap-example-observe-client.c | 16 ++++++++++--- examples/coap/coap-example-server.c | 8 ++++++- os/services/ipso-objects/ipso-button.c | 24 ++++++++++++------- .../embedded/border-router-embedded.c | 10 ++++++++ 9 files changed, 63 insertions(+), 14 deletions(-) diff --git a/arch/platform/cc2538dk/dev/board.h b/arch/platform/cc2538dk/dev/board.h index 0b2a4cd09..80f036fd7 100644 --- a/arch/platform/cc2538dk/dev/board.h +++ b/arch/platform/cc2538dk/dev/board.h @@ -163,6 +163,7 @@ /* Notify various examples that we have Buttons */ #define PLATFORM_HAS_BUTTON 1 +#define PLATFORM_SUPPORTS_BUTTON_HAL 1 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/openmote-cc2538/board.h b/arch/platform/openmote-cc2538/board.h index f7fbfc6c2..abb89b8e2 100644 --- a/arch/platform/openmote-cc2538/board.h +++ b/arch/platform/openmote-cc2538/board.h @@ -128,6 +128,7 @@ #define BUTTON_USER_VECTOR GPIO_C_IRQn /* Notify various examples that we have Buttons */ #define PLATFORM_HAS_BUTTON 1 +#define PLATFORM_SUPPORTS_BUTTON_HAL 1 /** @} */ /*---------------------------------------------------------------------------*/ /** diff --git a/arch/platform/srf06-cc26xx/contiki-conf.h b/arch/platform/srf06-cc26xx/contiki-conf.h index d0e10f5db..4a1470b40 100644 --- a/arch/platform/srf06-cc26xx/contiki-conf.h +++ b/arch/platform/srf06-cc26xx/contiki-conf.h @@ -59,6 +59,7 @@ /* Notify various examples that we have Buttons */ #define PLATFORM_HAS_BUTTON 1 +#define PLATFORM_SUPPORTS_BUTTON_HAL 1 /* * Override button symbols from dev/button-sensor.h, for the examples that diff --git a/arch/platform/zoul/contiki-conf.h b/arch/platform/zoul/contiki-conf.h index b1f1664b9..098c37404 100644 --- a/arch/platform/zoul/contiki-conf.h +++ b/arch/platform/zoul/contiki-conf.h @@ -86,6 +86,8 @@ /*---------------------------------------------------------------------------*/ /* board.h assumes that basic configuration is done */ #include "board.h" + +#define PLATFORM_SUPPORTS_BUTTON_HAL PLATFORM_HAS_BUTTON /*---------------------------------------------------------------------------*/ /** * \name Radio Configuration diff --git a/examples/coap/coap-example-client.c b/examples/coap/coap-example-client.c index e17a0ffde..27efbbf6e 100644 --- a/examples/coap/coap-example-client.c +++ b/examples/coap/coap-example-client.c @@ -43,7 +43,11 @@ #include "contiki-net.h" #include "coap-engine.h" #include "coap-blocking-api.h" +#if PLATFORM_SUPPORTS_BUTTON_HAL +#include "dev/button-hal.h" +#else #include "dev/button-sensor.h" +#endif /* Log configuration */ #include "coap-log.h" @@ -94,9 +98,11 @@ PROCESS_THREAD(er_example_client, ev, data) etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND); #if PLATFORM_HAS_BUTTON +#if !PLATFORM_SUPPORTS_BUTTON_HAL SENSORS_ACTIVATE(button_sensor); - printf("Press a button to request %s\n", service_urls[uri_switch]); #endif + printf("Press a button to request %s\n", service_urls[uri_switch]); +#endif /* PLATFORM_HAS_BUTTON */ while(1) { PROCESS_YIELD(); @@ -122,7 +128,11 @@ PROCESS_THREAD(er_example_client, ev, data) etimer_reset(&et); #if PLATFORM_HAS_BUTTON +#if PLATFORM_SUPPORTS_BUTTON_HAL + } else if(ev == button_hal_release_event) { +#else } else if(ev == sensors_event && data == &button_sensor) { +#endif /* send a request to notify the end of the process */ @@ -140,7 +150,7 @@ PROCESS_THREAD(er_example_client, ev, data) printf("\n--Done--\n"); uri_switch = (uri_switch + 1) % NUMBER_OF_URLS; -#endif +#endif /* PLATFORM_HAS_BUTTON */ } } diff --git a/examples/coap/coap-example-observe-client.c b/examples/coap/coap-example-observe-client.c index 611658e69..1dbed0bd4 100644 --- a/examples/coap/coap-example-observe-client.c +++ b/examples/coap/coap-example-observe-client.c @@ -42,8 +42,11 @@ #include "contiki.h" #include "contiki-net.h" #include "coap-engine.h" +#if PLATFORM_SUPPORTS_BUTTON_HAL +#include "dev/button-hal.h" +#else #include "dev/button-sensor.h" - +#endif /*----------------------------------------------------------------------------*/ #define DEBUG 0 #if DEBUG @@ -147,9 +150,12 @@ PROCESS_THREAD(er_example_observe_client, ev, data) /* init timer and button (if available) */ etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND); #if PLATFORM_HAS_BUTTON +#if !PLATFORM_SUPPORTS_BUTTON_HAL SENSORS_ACTIVATE(button_sensor); - printf("Press a button to start/stop observation of remote resource\n"); #endif + printf("Press a button to start/stop observation of remote resource\n"); +#endif /* PLATFORM_HAS_BUTTON */ + /* toggle observation every time the timer elapses or the button is pressed */ while(1) { PROCESS_YIELD(); @@ -159,11 +165,15 @@ PROCESS_THREAD(er_example_observe_client, ev, data) printf("\n--Done--\n"); etimer_reset(&et); #if PLATFORM_HAS_BUTTON +#if PLATFORM_SUPPORTS_BUTTON_HAL + } else if(ev == button_hal_release_event) { +#else } else if(ev == sensors_event && data == &button_sensor) { +#endif printf("--Toggle tutton--\n"); toggle_observation(); printf("\n--Done--\n"); -#endif +#endif /* PLATFORM_HAS_BUTTON */ } } PROCESS_END(); diff --git a/examples/coap/coap-example-server.c b/examples/coap/coap-example-server.c index 3cbcbc746..41ea53744 100644 --- a/examples/coap/coap-example-server.c +++ b/examples/coap/coap-example-server.c @@ -42,7 +42,9 @@ #include "contiki.h" #include "coap-engine.h" -#if PLATFORM_HAS_BUTTON +#if PLATFORM_SUPPORTS_BUTTON_HAL +#include "dev/button-hal.h" +#else #include "dev/button-sensor.h" #endif @@ -165,7 +167,11 @@ PROCESS_THREAD(er_example_server, ev, data) while(1) { PROCESS_WAIT_EVENT(); #if PLATFORM_HAS_BUTTON +#if PLATFORM_SUPPORTS_BUTTON_HAL + if(ev == button_hal_release_event) { +#else if(ev == sensors_event && data == &button_sensor) { +#endif PRINTF("*******BUTTON*******\n"); /* Call the event_handler for this application-specific event. */ diff --git a/os/services/ipso-objects/ipso-button.c b/os/services/ipso-objects/ipso-button.c index 1f3cb2d9b..b0069c0aa 100644 --- a/os/services/ipso-objects/ipso-button.c +++ b/os/services/ipso-objects/ipso-button.c @@ -63,13 +63,12 @@ #define IPSO_INPUT_SENSOR_TYPE 5751 #if PLATFORM_HAS_BUTTON -#include "dev/button-sensor.h" - -#if BOARD_SENSORTAG -#include "sensortag/button-sensor.h" -#define IPSO_BUTTON_SENSOR button_left_sensor +#if PLATFORM_SUPPORTS_BUTTON_HAL +#include "dev/button-hal.h" #else +#include "dev/button-sensor.h" #define IPSO_BUTTON_SENSOR button_sensor +static struct etimer timer; #endif PROCESS(ipso_button_process, "ipso-button"); @@ -168,18 +167,26 @@ ipso_button_init(void) #if PLATFORM_HAS_BUTTON PROCESS_THREAD(ipso_button_process, ev, data) { - static struct etimer timer; - int32_t time; - PROCESS_BEGIN(); +#if !PLATFORM_SUPPORTS_BUTTON_HAL SENSORS_ACTIVATE(IPSO_BUTTON_SENSOR); +#endif while(1) { PROCESS_WAIT_EVENT(); +#if PLATFORM_SUPPORTS_BUTTON_HAL + /* ToDo */ + if(ev == button_hal_release_event) { + lwm2m_notify_object_observers(®_object, IPSO_INPUT_STATE); + } else if(ev == button_hal_periodic_event) { + lwm2m_notify_object_observers(®_object, IPSO_INPUT_COUNTER); + } +#else if(ev == sensors_event && data == &IPSO_BUTTON_SENSOR) { if(!input_state) { + int32_t time; input_state = 1; counter++; if((edge_selection & 2) != 0) { @@ -206,6 +213,7 @@ PROCESS_THREAD(ipso_button_process, ev, data) } } } +#endif } PROCESS_END(); diff --git a/os/services/rpl-border-router/embedded/border-router-embedded.c b/os/services/rpl-border-router/embedded/border-router-embedded.c index 884f60a97..6b565a7ff 100644 --- a/os/services/rpl-border-router/embedded/border-router-embedded.c +++ b/os/services/rpl-border-router/embedded/border-router-embedded.c @@ -37,7 +37,11 @@ #include "contiki.h" #include "net/routing/routing.h" +#if PLATFORM_SUPPORTS_BUTTON_HAL +#include "dev/button-hal.h" +#else #include "dev/button-sensor.h" +#endif #include "dev/slip.h" #include "rpl-border-router.h" @@ -68,7 +72,9 @@ PROCESS_THREAD(border_router_process, ev, data) PROCESS_PAUSE(); +#if !PLATFORM_SUPPORTS_BUTTON_HAL SENSORS_ACTIVATE(button_sensor); +#endif LOG_INFO("RPL-Border router started\n"); @@ -86,7 +92,11 @@ PROCESS_THREAD(border_router_process, ev, data) while(1) { PROCESS_YIELD(); +#if PLATFORM_SUPPORTS_BUTTON_HAL + if(ev == button_hal_release_event) { +#else if(ev == sensors_event && data == &button_sensor) { +#endif LOG_INFO("Initiating global repair\n"); NETSTACK_ROUTING.global_repair("Button press"); }