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
This commit is contained in:
parent
13c18011c7
commit
155e2c9b0a
@ -163,6 +163,7 @@
|
|||||||
|
|
||||||
/* Notify various examples that we have Buttons */
|
/* Notify various examples that we have Buttons */
|
||||||
#define PLATFORM_HAS_BUTTON 1
|
#define PLATFORM_HAS_BUTTON 1
|
||||||
|
#define PLATFORM_SUPPORTS_BUTTON_HAL 1
|
||||||
/** @} */
|
/** @} */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -128,6 +128,7 @@
|
|||||||
#define BUTTON_USER_VECTOR GPIO_C_IRQn
|
#define BUTTON_USER_VECTOR GPIO_C_IRQn
|
||||||
/* Notify various examples that we have Buttons */
|
/* Notify various examples that we have Buttons */
|
||||||
#define PLATFORM_HAS_BUTTON 1
|
#define PLATFORM_HAS_BUTTON 1
|
||||||
|
#define PLATFORM_SUPPORTS_BUTTON_HAL 1
|
||||||
/** @} */
|
/** @} */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
|
|
||||||
/* Notify various examples that we have Buttons */
|
/* Notify various examples that we have Buttons */
|
||||||
#define PLATFORM_HAS_BUTTON 1
|
#define PLATFORM_HAS_BUTTON 1
|
||||||
|
#define PLATFORM_SUPPORTS_BUTTON_HAL 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Override button symbols from dev/button-sensor.h, for the examples that
|
* Override button symbols from dev/button-sensor.h, for the examples that
|
||||||
|
@ -86,6 +86,8 @@
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* board.h assumes that basic configuration is done */
|
/* board.h assumes that basic configuration is done */
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
|
#define PLATFORM_SUPPORTS_BUTTON_HAL PLATFORM_HAS_BUTTON
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* \name Radio Configuration
|
* \name Radio Configuration
|
||||||
|
@ -43,7 +43,11 @@
|
|||||||
#include "contiki-net.h"
|
#include "contiki-net.h"
|
||||||
#include "coap-engine.h"
|
#include "coap-engine.h"
|
||||||
#include "coap-blocking-api.h"
|
#include "coap-blocking-api.h"
|
||||||
|
#if PLATFORM_SUPPORTS_BUTTON_HAL
|
||||||
|
#include "dev/button-hal.h"
|
||||||
|
#else
|
||||||
#include "dev/button-sensor.h"
|
#include "dev/button-sensor.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Log configuration */
|
/* Log configuration */
|
||||||
#include "coap-log.h"
|
#include "coap-log.h"
|
||||||
@ -94,9 +98,11 @@ PROCESS_THREAD(er_example_client, ev, data)
|
|||||||
etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND);
|
etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND);
|
||||||
|
|
||||||
#if PLATFORM_HAS_BUTTON
|
#if PLATFORM_HAS_BUTTON
|
||||||
|
#if !PLATFORM_SUPPORTS_BUTTON_HAL
|
||||||
SENSORS_ACTIVATE(button_sensor);
|
SENSORS_ACTIVATE(button_sensor);
|
||||||
printf("Press a button to request %s\n", service_urls[uri_switch]);
|
|
||||||
#endif
|
#endif
|
||||||
|
printf("Press a button to request %s\n", service_urls[uri_switch]);
|
||||||
|
#endif /* PLATFORM_HAS_BUTTON */
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
PROCESS_YIELD();
|
PROCESS_YIELD();
|
||||||
@ -122,7 +128,11 @@ PROCESS_THREAD(er_example_client, ev, data)
|
|||||||
etimer_reset(&et);
|
etimer_reset(&et);
|
||||||
|
|
||||||
#if PLATFORM_HAS_BUTTON
|
#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) {
|
} else if(ev == sensors_event && data == &button_sensor) {
|
||||||
|
#endif
|
||||||
|
|
||||||
/* send a request to notify the end of the process */
|
/* 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");
|
printf("\n--Done--\n");
|
||||||
|
|
||||||
uri_switch = (uri_switch + 1) % NUMBER_OF_URLS;
|
uri_switch = (uri_switch + 1) % NUMBER_OF_URLS;
|
||||||
#endif
|
#endif /* PLATFORM_HAS_BUTTON */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +42,11 @@
|
|||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "contiki-net.h"
|
#include "contiki-net.h"
|
||||||
#include "coap-engine.h"
|
#include "coap-engine.h"
|
||||||
|
#if PLATFORM_SUPPORTS_BUTTON_HAL
|
||||||
|
#include "dev/button-hal.h"
|
||||||
|
#else
|
||||||
#include "dev/button-sensor.h"
|
#include "dev/button-sensor.h"
|
||||||
|
#endif
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
#define DEBUG 0
|
#define DEBUG 0
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@ -147,9 +150,12 @@ PROCESS_THREAD(er_example_observe_client, ev, data)
|
|||||||
/* init timer and button (if available) */
|
/* init timer and button (if available) */
|
||||||
etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND);
|
etimer_set(&et, TOGGLE_INTERVAL * CLOCK_SECOND);
|
||||||
#if PLATFORM_HAS_BUTTON
|
#if PLATFORM_HAS_BUTTON
|
||||||
|
#if !PLATFORM_SUPPORTS_BUTTON_HAL
|
||||||
SENSORS_ACTIVATE(button_sensor);
|
SENSORS_ACTIVATE(button_sensor);
|
||||||
printf("Press a button to start/stop observation of remote resource\n");
|
|
||||||
#endif
|
#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 */
|
/* toggle observation every time the timer elapses or the button is pressed */
|
||||||
while(1) {
|
while(1) {
|
||||||
PROCESS_YIELD();
|
PROCESS_YIELD();
|
||||||
@ -159,11 +165,15 @@ PROCESS_THREAD(er_example_observe_client, ev, data)
|
|||||||
printf("\n--Done--\n");
|
printf("\n--Done--\n");
|
||||||
etimer_reset(&et);
|
etimer_reset(&et);
|
||||||
#if PLATFORM_HAS_BUTTON
|
#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) {
|
} else if(ev == sensors_event && data == &button_sensor) {
|
||||||
|
#endif
|
||||||
printf("--Toggle tutton--\n");
|
printf("--Toggle tutton--\n");
|
||||||
toggle_observation();
|
toggle_observation();
|
||||||
printf("\n--Done--\n");
|
printf("\n--Done--\n");
|
||||||
#endif
|
#endif /* PLATFORM_HAS_BUTTON */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PROCESS_END();
|
PROCESS_END();
|
||||||
|
@ -42,7 +42,9 @@
|
|||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "coap-engine.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"
|
#include "dev/button-sensor.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -165,7 +167,11 @@ PROCESS_THREAD(er_example_server, ev, data)
|
|||||||
while(1) {
|
while(1) {
|
||||||
PROCESS_WAIT_EVENT();
|
PROCESS_WAIT_EVENT();
|
||||||
#if PLATFORM_HAS_BUTTON
|
#if PLATFORM_HAS_BUTTON
|
||||||
|
#if PLATFORM_SUPPORTS_BUTTON_HAL
|
||||||
|
if(ev == button_hal_release_event) {
|
||||||
|
#else
|
||||||
if(ev == sensors_event && data == &button_sensor) {
|
if(ev == sensors_event && data == &button_sensor) {
|
||||||
|
#endif
|
||||||
PRINTF("*******BUTTON*******\n");
|
PRINTF("*******BUTTON*******\n");
|
||||||
|
|
||||||
/* Call the event_handler for this application-specific event. */
|
/* Call the event_handler for this application-specific event. */
|
||||||
|
@ -63,13 +63,12 @@
|
|||||||
#define IPSO_INPUT_SENSOR_TYPE 5751
|
#define IPSO_INPUT_SENSOR_TYPE 5751
|
||||||
|
|
||||||
#if PLATFORM_HAS_BUTTON
|
#if PLATFORM_HAS_BUTTON
|
||||||
#include "dev/button-sensor.h"
|
#if PLATFORM_SUPPORTS_BUTTON_HAL
|
||||||
|
#include "dev/button-hal.h"
|
||||||
#if BOARD_SENSORTAG
|
|
||||||
#include "sensortag/button-sensor.h"
|
|
||||||
#define IPSO_BUTTON_SENSOR button_left_sensor
|
|
||||||
#else
|
#else
|
||||||
|
#include "dev/button-sensor.h"
|
||||||
#define IPSO_BUTTON_SENSOR button_sensor
|
#define IPSO_BUTTON_SENSOR button_sensor
|
||||||
|
static struct etimer timer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
PROCESS(ipso_button_process, "ipso-button");
|
PROCESS(ipso_button_process, "ipso-button");
|
||||||
@ -168,18 +167,26 @@ ipso_button_init(void)
|
|||||||
#if PLATFORM_HAS_BUTTON
|
#if PLATFORM_HAS_BUTTON
|
||||||
PROCESS_THREAD(ipso_button_process, ev, data)
|
PROCESS_THREAD(ipso_button_process, ev, data)
|
||||||
{
|
{
|
||||||
static struct etimer timer;
|
|
||||||
int32_t time;
|
|
||||||
|
|
||||||
PROCESS_BEGIN();
|
PROCESS_BEGIN();
|
||||||
|
|
||||||
|
#if !PLATFORM_SUPPORTS_BUTTON_HAL
|
||||||
SENSORS_ACTIVATE(IPSO_BUTTON_SENSOR);
|
SENSORS_ACTIVATE(IPSO_BUTTON_SENSOR);
|
||||||
|
#endif
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
PROCESS_WAIT_EVENT();
|
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(ev == sensors_event && data == &IPSO_BUTTON_SENSOR) {
|
||||||
if(!input_state) {
|
if(!input_state) {
|
||||||
|
int32_t time;
|
||||||
input_state = 1;
|
input_state = 1;
|
||||||
counter++;
|
counter++;
|
||||||
if((edge_selection & 2) != 0) {
|
if((edge_selection & 2) != 0) {
|
||||||
@ -206,6 +213,7 @@ PROCESS_THREAD(ipso_button_process, ev, data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
PROCESS_END();
|
PROCESS_END();
|
||||||
|
@ -37,7 +37,11 @@
|
|||||||
|
|
||||||
#include "contiki.h"
|
#include "contiki.h"
|
||||||
#include "net/routing/routing.h"
|
#include "net/routing/routing.h"
|
||||||
|
#if PLATFORM_SUPPORTS_BUTTON_HAL
|
||||||
|
#include "dev/button-hal.h"
|
||||||
|
#else
|
||||||
#include "dev/button-sensor.h"
|
#include "dev/button-sensor.h"
|
||||||
|
#endif
|
||||||
#include "dev/slip.h"
|
#include "dev/slip.h"
|
||||||
#include "rpl-border-router.h"
|
#include "rpl-border-router.h"
|
||||||
|
|
||||||
@ -68,7 +72,9 @@ PROCESS_THREAD(border_router_process, ev, data)
|
|||||||
|
|
||||||
PROCESS_PAUSE();
|
PROCESS_PAUSE();
|
||||||
|
|
||||||
|
#if !PLATFORM_SUPPORTS_BUTTON_HAL
|
||||||
SENSORS_ACTIVATE(button_sensor);
|
SENSORS_ACTIVATE(button_sensor);
|
||||||
|
#endif
|
||||||
|
|
||||||
LOG_INFO("RPL-Border router started\n");
|
LOG_INFO("RPL-Border router started\n");
|
||||||
|
|
||||||
@ -86,7 +92,11 @@ PROCESS_THREAD(border_router_process, ev, data)
|
|||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
PROCESS_YIELD();
|
PROCESS_YIELD();
|
||||||
|
#if PLATFORM_SUPPORTS_BUTTON_HAL
|
||||||
|
if(ev == button_hal_release_event) {
|
||||||
|
#else
|
||||||
if(ev == sensors_event && data == &button_sensor) {
|
if(ev == sensors_event && data == &button_sensor) {
|
||||||
|
#endif
|
||||||
LOG_INFO("Initiating global repair\n");
|
LOG_INFO("Initiating global repair\n");
|
||||||
NETSTACK_ROUTING.global_repair("Button press");
|
NETSTACK_ROUTING.global_repair("Button press");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user