From 474dc33e122195f62e598a7e020c722b9009a2b4 Mon Sep 17 00:00:00 2001 From: George Oikonomou Date: Sat, 18 Mar 2017 14:36:18 +0000 Subject: [PATCH] Wrap web demo ADC functionality inside #if blocks --- .../cc26xx/cc26xx-web-demo/cc26xx-web-demo.c | 19 ++++++++++++++++--- examples/cc26xx/cc26xx-web-demo/coap-server.c | 9 ++++++++- .../cc26xx-web-demo/resources/res-sensors.c | 17 ++++++++++------- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/examples/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c b/examples/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c index 02af7f946..1b80801a6 100644 --- a/examples/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c +++ b/examples/cc26xx/cc26xx-web-demo/cc26xx-web-demo.c @@ -61,7 +61,6 @@ /*---------------------------------------------------------------------------*/ PROCESS_NAME(cetic_6lbr_client_process); PROCESS(cc26xx_web_demo_process, "CC26XX Web Demo"); -PROCESS(adc_process, "ADC process"); /*---------------------------------------------------------------------------*/ /* * Update sensor readings in a staggered fashion every SENSOR_READING_PERIOD @@ -88,9 +87,13 @@ static struct uip_icmp6_echo_reply_notification echo_reply_notification; static struct etimer echo_request_timer; int def_rt_rssi = 0; #endif +/*---------------------------------------------------------------------------*/ +#if CC26XX_WEB_DEMO_ADC_DEMO +PROCESS(adc_process, "ADC process"); static uint16_t single_adc_sample; - +static struct etimer et_adc; +#endif /*---------------------------------------------------------------------------*/ process_event_t cc26xx_web_demo_publish_event; process_event_t cc26xx_web_demo_config_loaded_event; @@ -117,9 +120,12 @@ DEMO_SENSOR(batmon_temp, CC26XX_WEB_DEMO_SENSOR_BATMON_TEMP, DEMO_SENSOR(batmon_volt, CC26XX_WEB_DEMO_SENSOR_BATMON_VOLT, "Battery Volt", "battery-volt", "batmon_volt", CC26XX_WEB_DEMO_UNIT_VOLT); + +#if CC26XX_WEB_DEMO_ADC_DEMO DEMO_SENSOR(adc_dio23, CC26XX_WEB_DEMO_SENSOR_ADC_DIO23, "ADC DIO23", "adc-dio23", "adc_dio23", CC26XX_WEB_DEMO_UNIT_VOLT); +#endif /* Sensortag sensors */ #if BOARD_SENSORTAG @@ -477,6 +483,7 @@ get_batmon_reading(void *data) ctimer_set(&batmon_timer, next, get_batmon_reading, NULL); } /*---------------------------------------------------------------------------*/ +#if CC26XX_WEB_DEMO_ADC_DEMO static void get_adc_reading(void *data) { @@ -490,6 +497,7 @@ get_adc_reading(void *data) snprintf(buf, CC26XX_WEB_DEMO_CONVERTED_LEN, "%d", (value * 4300) >> 12); } } +#endif /*---------------------------------------------------------------------------*/ #if BOARD_SENSORTAG /*---------------------------------------------------------------------------*/ @@ -849,7 +857,11 @@ init_sensors(void) list_add(sensor_list, &batmon_temp_reading); list_add(sensor_list, &batmon_volt_reading); + +#if CC26XX_WEB_DEMO_ADC_DEMO list_add(sensor_list, &adc_dio23_reading); +#endif + SENSORS_ACTIVATE(batmon_sensor); #if BOARD_SENSORTAG @@ -997,10 +1009,10 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data) PROCESS_END(); } +#if CC26XX_WEB_DEMO_ADC_DEMO PROCESS_THREAD(adc_process, ev, data) { PROCESS_BEGIN(); - static struct etimer et_adc; etimer_set(&et_adc, CLOCK_SECOND * 5); while(1) { PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et_adc)); @@ -1037,6 +1049,7 @@ PROCESS_THREAD(adc_process, ev, data) } PROCESS_END(); } +#endif /*---------------------------------------------------------------------------*/ /** * @} diff --git a/examples/cc26xx/cc26xx-web-demo/coap-server.c b/examples/cc26xx/cc26xx-web-demo/coap-server.c index 957e8adae..8897eb23f 100644 --- a/examples/cc26xx/cc26xx-web-demo/coap-server.c +++ b/examples/cc26xx/cc26xx-web-demo/coap-server.c @@ -40,6 +40,7 @@ #include "rest-engine.h" #include "board-peripherals.h" #include "rf-core/rf-ble.h" +#include "cc26xx-web-demo.h" #include #include @@ -50,7 +51,6 @@ extern resource_t res_leds; extern resource_t res_batmon_temp; extern resource_t res_batmon_volt; -extern resource_t res_adc_dio23; extern resource_t res_device_sw; extern resource_t res_device_hw; @@ -86,6 +86,10 @@ extern resource_t res_mpu_gyro_z; extern resource_t res_toggle_orange; extern resource_t res_toggle_yellow; #endif + +#if CC26XX_WEB_DEMO_ADC_DEMO +extern resource_t res_adc_dio23; +#endif /*---------------------------------------------------------------------------*/ const char *coap_server_not_found_msg = "Resource not found"; const char *coap_server_supported_msg = "Supported:" @@ -134,7 +138,10 @@ PROCESS_THREAD(coap_server_process, ev, data) rest_activate_resource(&res_batmon_temp, "sen/batmon/temp"); rest_activate_resource(&res_batmon_volt, "sen/batmon/voltage"); + +#if CC26XX_WEB_DEMO_ADC_DEMO rest_activate_resource(&res_adc_dio23, "sen/adc/dio23"); +#endif rest_activate_resource(&res_device_hw, "dev/mdl/hw"); rest_activate_resource(&res_device_sw, "dev/mdl/sw"); diff --git a/examples/cc26xx/cc26xx-web-demo/resources/res-sensors.c b/examples/cc26xx/cc26xx-web-demo/resources/res-sensors.c index f5cfad79e..f3fd7bd26 100644 --- a/examples/cc26xx/cc26xx-web-demo/resources/res-sensors.c +++ b/examples/cc26xx/cc26xx-web-demo/resources/res-sensors.c @@ -111,6 +111,14 @@ res_get_handler_batmon_volt(void *request, void *response, uint8_t *buffer, buffer, preferred_size, offset); } /*---------------------------------------------------------------------------*/ +RESOURCE(res_batmon_temp, "title=\"Battery Temp\";rt=\"C\"", + res_get_handler_batmon_temp, NULL, NULL, NULL); +/*---------------------------------------------------------------------------*/ +RESOURCE(res_batmon_volt, "title=\"Battery Voltage\";rt=\"mV\"", + res_get_handler_batmon_volt, NULL, NULL, NULL); +/*---------------------------------------------------------------------------*/ +#if CC26XX_WEB_DEMO_ADC_DEMO +/*---------------------------------------------------------------------------*/ static void res_get_handler_adc_dio23(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) @@ -119,16 +127,11 @@ res_get_handler_adc_dio23(void *request, void *response, uint8_t *buffer, buffer, preferred_size, offset); } /*---------------------------------------------------------------------------*/ -RESOURCE(res_batmon_temp, "title=\"Battery Temp\";rt=\"C\"", - res_get_handler_batmon_temp, NULL, NULL, NULL); -/*---------------------------------------------------------------------------*/ -RESOURCE(res_batmon_volt, "title=\"Battery Voltage\";rt=\"mV\"", - res_get_handler_batmon_volt, NULL, NULL, NULL); -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ RESOURCE(res_adc_dio23, "title=\"ADC DIO23\";rt=\"mV\"", res_get_handler_adc_dio23, NULL, NULL, NULL); /*---------------------------------------------------------------------------*/ +#endif +/*---------------------------------------------------------------------------*/ #if BOARD_SENSORTAG /*---------------------------------------------------------------------------*/ /* MPU resources and handler: Accelerometer and Gyro */