Merge branch 'develop' into fix_observer
This commit is contained in:
commit
5e45ffc194
|
@ -40,9 +40,11 @@ LOWERCASE = -abcdefghijklmnopqrstuvwxyz/
|
|||
UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ_
|
||||
TARGET_UPPERCASE := ${strip ${shell echo $(TARGET) | sed y!$(LOWERCASE)!$(UPPERCASE)!}}
|
||||
CFLAGS += -DCONTIKI=1 -DCONTIKI_TARGET_$(TARGET_UPPERCASE)=1
|
||||
CFLAGS += -DCONTIKI_TARGET_STRING=\"$(TARGET)\"
|
||||
ifneq ($(BOARD),)
|
||||
TARGET_BOARD_UPPERCASE := ${strip ${shell echo $(BOARD) | sed y!$(LOWERCASE)!$(UPPERCASE)!}}
|
||||
CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1
|
||||
CFLAGS += -DCONTIKI_BOARD_STRING=\"$(BOARD)\"
|
||||
endif
|
||||
|
||||
MODULES += os os/sys os/dev os/lib os/services
|
||||
|
|
|
@ -87,6 +87,7 @@ gpio_hal_arch_pin_cfg_set(gpio_hal_pin_t pin, gpio_hal_pin_cfg_t cfg)
|
|||
GPIO_DISABLE_INTERRUPT(port_base, pin_mask);
|
||||
} else if(tmp == GPIO_HAL_PIN_CFG_INT_ENABLE) {
|
||||
GPIO_ENABLE_INTERRUPT(port_base, pin_mask);
|
||||
NVIC_EnableIRQ(port);
|
||||
}
|
||||
|
||||
GPIO_SOFTWARE_CONTROL(port_base, pin_mask);
|
||||
|
|
|
@ -55,8 +55,10 @@
|
|||
#define PIN_TO_PORT(pin) (pin >> 3)
|
||||
#define PIN_TO_PORT_BASE(pin) GPIO_PORT_TO_BASE(PIN_TO_PORT(pin))
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define gpio_hal_arch_interrupt_enable(p) \
|
||||
GPIO_ENABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8))
|
||||
#define gpio_hal_arch_interrupt_enable(p) do { \
|
||||
GPIO_ENABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8)); \
|
||||
NVIC_EnableIRQ(PIN_TO_PORT(p)); \
|
||||
} while(0);
|
||||
|
||||
#define gpio_hal_arch_interrupt_disable(p) \
|
||||
GPIO_DISABLE_INTERRUPT(PIN_TO_PORT_BASE(p), GPIO_PIN_MASK((p) % 8))
|
||||
|
|
|
@ -44,6 +44,9 @@
|
|||
#ifndef BATMON_SENSOR_H_
|
||||
#define BATMON_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BATMON_SENSOR_TYPE_TEMP 1
|
||||
#define BATMON_SENSOR_TYPE_VOLT 2
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -9,7 +9,7 @@ CONTIKI_TARGET_DIRS = . dev
|
|||
CONTIKI_TARGET_SOURCEFILES += leds-arch.c
|
||||
CONTIKI_TARGET_SOURCEFILES += platform.c
|
||||
CONTIKI_TARGET_SOURCEFILES += sensors.c smartrf-sensors.c
|
||||
CONTIKI_TARGET_SOURCEFILES += button-sensor.c als-sensor.c
|
||||
CONTIKI_TARGET_SOURCEFILES += board-buttons.c als-sensor.c
|
||||
|
||||
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup cc2538-smartrf
|
||||
* @{
|
||||
*
|
||||
* \defgroup cc2538-smartrf-buttons SmartRF06EB Buttons
|
||||
*
|
||||
* Generic module controlling buttons on the SmartRF06EB
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Defines SmartRF06EB buttons for use with the button HAL
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/button-hal.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
BUTTON_HAL_BUTTON(key_left, "Key Left", \
|
||||
GPIO_PORT_PIN_TO_GPIO_HAL_PIN(BUTTON_LEFT_PORT, BUTTON_LEFT_PIN), \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BUTTON_HAL_ID_BUTTON_ZERO, true);
|
||||
BUTTON_HAL_BUTTON(key_right, "Key Right", \
|
||||
GPIO_PORT_PIN_TO_GPIO_HAL_PIN(BUTTON_RIGHT_PORT, BUTTON_RIGHT_PIN), \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BUTTON_HAL_ID_BUTTON_ONE, true);
|
||||
BUTTON_HAL_BUTTON(key_up, "Key Up", \
|
||||
GPIO_PORT_PIN_TO_GPIO_HAL_PIN(BUTTON_UP_PORT, BUTTON_UP_PIN), \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BUTTON_HAL_ID_BUTTON_TWO, true);
|
||||
BUTTON_HAL_BUTTON(key_down, "Key Down", \
|
||||
GPIO_PORT_PIN_TO_GPIO_HAL_PIN(BUTTON_DOWN_PORT, BUTTON_DOWN_PIN), \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BUTTON_HAL_ID_BUTTON_THREE, true);
|
||||
BUTTON_HAL_BUTTON(key_select, "Key Select", \
|
||||
GPIO_PORT_PIN_TO_GPIO_HAL_PIN(BUTTON_SELECT_PORT, BUTTON_SELECT_PIN), \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BUTTON_HAL_ID_BUTTON_FOUR, true);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
BUTTON_HAL_BUTTONS(&key_left, &key_right, &key_up, &key_down, &key_select);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
|
@ -163,6 +163,7 @@
|
|||
|
||||
/* Notify various examples that we have Buttons */
|
||||
#define PLATFORM_HAS_BUTTON 1
|
||||
#define PLATFORM_SUPPORTS_BUTTON_HAL 1
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
|
|
@ -1,265 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup cc2538dk-button-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the SmartRF06EB buttons
|
||||
*/
|
||||
#include "contiki.h"
|
||||
#include "dev/nvic.h"
|
||||
#include "dev/ioc.h"
|
||||
#include "dev/gpio.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "sys/timer.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#define BUTTON_SELECT_PORT_BASE GPIO_PORT_TO_BASE(BUTTON_SELECT_PORT)
|
||||
#define BUTTON_SELECT_PIN_MASK GPIO_PIN_MASK(BUTTON_SELECT_PIN)
|
||||
|
||||
#define BUTTON_LEFT_PORT_BASE GPIO_PORT_TO_BASE(BUTTON_LEFT_PORT)
|
||||
#define BUTTON_LEFT_PIN_MASK GPIO_PIN_MASK(BUTTON_LEFT_PIN)
|
||||
|
||||
#define BUTTON_RIGHT_PORT_BASE GPIO_PORT_TO_BASE(BUTTON_RIGHT_PORT)
|
||||
#define BUTTON_RIGHT_PIN_MASK GPIO_PIN_MASK(BUTTON_RIGHT_PIN)
|
||||
|
||||
#define BUTTON_UP_PORT_BASE GPIO_PORT_TO_BASE(BUTTON_UP_PORT)
|
||||
#define BUTTON_UP_PIN_MASK GPIO_PIN_MASK(BUTTON_UP_PIN)
|
||||
|
||||
#define BUTTON_DOWN_PORT_BASE GPIO_PORT_TO_BASE(BUTTON_DOWN_PORT)
|
||||
#define BUTTON_DOWN_PIN_MASK GPIO_PIN_MASK(BUTTON_DOWN_PIN)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct timer debouncetimer;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Common initialiser for all buttons
|
||||
* \param port_base GPIO port's register offset
|
||||
* \param pin_mask Pin mask corresponding to the button's pin
|
||||
*/
|
||||
static void
|
||||
config(uint32_t port_base, uint32_t pin_mask)
|
||||
{
|
||||
/* Software controlled */
|
||||
GPIO_SOFTWARE_CONTROL(port_base, pin_mask);
|
||||
|
||||
/* Set pin to input */
|
||||
GPIO_SET_INPUT(port_base, pin_mask);
|
||||
|
||||
/* Enable edge detection */
|
||||
GPIO_DETECT_EDGE(port_base, pin_mask);
|
||||
|
||||
/* Single edge */
|
||||
GPIO_TRIGGER_SINGLE_EDGE(port_base, pin_mask);
|
||||
|
||||
/* Trigger interrupt on Falling edge */
|
||||
GPIO_DETECT_RISING(port_base, pin_mask);
|
||||
|
||||
GPIO_ENABLE_INTERRUPT(port_base, pin_mask);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
button_press_handler(gpio_hal_pin_mask_t pin_mask)
|
||||
{
|
||||
if(!timer_expired(&debouncetimer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&debouncetimer, CLOCK_SECOND / 8);
|
||||
|
||||
if(pin_mask &
|
||||
(gpio_hal_pin_to_mask(BUTTON_SELECT_PIN) << (BUTTON_SELECT_PORT << 3))) {
|
||||
sensors_changed(&button_select_sensor);
|
||||
} else if(pin_mask &
|
||||
(gpio_hal_pin_to_mask(BUTTON_LEFT_PIN) << (BUTTON_LEFT_PORT << 3))) {
|
||||
sensors_changed(&button_left_sensor);
|
||||
} else if(pin_mask &
|
||||
(gpio_hal_pin_to_mask(BUTTON_RIGHT_PIN) << (BUTTON_RIGHT_PORT << 3))) {
|
||||
sensors_changed(&button_right_sensor);
|
||||
} else if(pin_mask &
|
||||
(gpio_hal_pin_to_mask(BUTTON_UP_PIN) << (BUTTON_UP_PORT << 3))) {
|
||||
sensors_changed(&button_up_sensor);
|
||||
} else if(pin_mask &
|
||||
(gpio_hal_pin_to_mask(BUTTON_DOWN_PIN) << (BUTTON_DOWN_PORT << 3))) {
|
||||
sensors_changed(&button_down_sensor);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static gpio_hal_event_handler_t press_handler = {
|
||||
.next = NULL,
|
||||
.handler = button_press_handler,
|
||||
.pin_mask = 0,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
register_btn_callback(uint8_t port_num, uint8_t pin)
|
||||
{
|
||||
press_handler.pin_mask |=
|
||||
gpio_hal_pin_to_mask(pin) << (port_num << 3);
|
||||
|
||||
gpio_hal_register_handler(&press_handler);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Init function for the select button.
|
||||
*
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor api. The return value is also not required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type ignored
|
||||
* \param value ignored
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_select(int type, int value)
|
||||
{
|
||||
config(BUTTON_SELECT_PORT_BASE, BUTTON_SELECT_PIN_MASK);
|
||||
|
||||
ioc_set_over(BUTTON_SELECT_PORT, BUTTON_SELECT_PIN, IOC_OVERRIDE_PUE);
|
||||
|
||||
NVIC_EnableIRQ(BUTTON_SELECT_VECTOR);
|
||||
|
||||
register_btn_callback(BUTTON_SELECT_PORT, BUTTON_SELECT_PIN);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Init function for the left button.
|
||||
*
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor api. The return value is also not required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type ignored
|
||||
* \param value ignored
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_left(int type, int value)
|
||||
{
|
||||
config(BUTTON_LEFT_PORT_BASE, BUTTON_LEFT_PIN_MASK);
|
||||
|
||||
ioc_set_over(BUTTON_LEFT_PORT, BUTTON_LEFT_PIN, IOC_OVERRIDE_PUE);
|
||||
|
||||
NVIC_EnableIRQ(BUTTON_LEFT_VECTOR);
|
||||
|
||||
register_btn_callback(BUTTON_LEFT_PORT, BUTTON_LEFT_PIN);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Init function for the right button.
|
||||
*
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor api. The return value is also not required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type ignored
|
||||
* \param value ignored
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_right(int type, int value)
|
||||
{
|
||||
config(BUTTON_RIGHT_PORT_BASE, BUTTON_RIGHT_PIN_MASK);
|
||||
|
||||
ioc_set_over(BUTTON_RIGHT_PORT, BUTTON_RIGHT_PIN, IOC_OVERRIDE_PUE);
|
||||
|
||||
NVIC_EnableIRQ(BUTTON_RIGHT_VECTOR);
|
||||
|
||||
register_btn_callback(BUTTON_RIGHT_PORT, BUTTON_RIGHT_PIN);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Init function for the up button.
|
||||
*
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor api. The return value is also not required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type ignored
|
||||
* \param value ignored
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_up(int type, int value)
|
||||
{
|
||||
config(BUTTON_UP_PORT_BASE, BUTTON_UP_PIN_MASK);
|
||||
|
||||
ioc_set_over(BUTTON_UP_PORT, BUTTON_UP_PIN, IOC_OVERRIDE_PUE);
|
||||
|
||||
NVIC_EnableIRQ(BUTTON_UP_VECTOR);
|
||||
|
||||
register_btn_callback(BUTTON_UP_PORT, BUTTON_UP_PIN);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Init function for the down button.
|
||||
*
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor api. The return value is also not required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type ignored
|
||||
* \param value ignored
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_down(int type, int value)
|
||||
{
|
||||
config(BUTTON_DOWN_PORT_BASE, BUTTON_DOWN_PIN_MASK);
|
||||
|
||||
ioc_set_over(BUTTON_DOWN_PORT, BUTTON_DOWN_PIN, IOC_OVERRIDE_PUE);
|
||||
|
||||
NVIC_EnableIRQ(BUTTON_DOWN_VECTOR);
|
||||
|
||||
register_btn_callback(BUTTON_DOWN_PORT, BUTTON_DOWN_PIN);
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
button_sensor_init()
|
||||
{
|
||||
timer_set(&debouncetimer, 0);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_select_sensor, BUTTON_SENSOR, NULL, config_select, NULL);
|
||||
SENSORS_SENSOR(button_left_sensor, BUTTON_SENSOR, NULL, config_left, NULL);
|
||||
SENSORS_SENSOR(button_right_sensor, BUTTON_SENSOR, NULL, config_right, NULL);
|
||||
SENSORS_SENSOR(button_up_sensor, BUTTON_SENSOR, NULL, config_up, NULL);
|
||||
SENSORS_SENSOR(button_down_sensor, BUTTON_SENSOR, NULL, config_down, NULL);
|
||||
|
||||
/** @} */
|
|
@ -41,16 +41,13 @@
|
|||
* Implementation of a generic module controlling SmartRF06EB sensors
|
||||
*/
|
||||
#include "contiki.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/als-sensor.h"
|
||||
#include "dev/cc2538-sensors.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/** \brief Exports a global symbol to be used by the sensor API */
|
||||
SENSORS(&button_select_sensor, &button_left_sensor, &button_right_sensor,
|
||||
&button_up_sensor, &button_down_sensor, &als_sensor,
|
||||
&cc2538_temp_sensor, &vdd3_sensor);
|
||||
SENSORS(&als_sensor, &cc2538_temp_sensor, &vdd3_sensor);
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
|
|
@ -46,14 +46,15 @@
|
|||
#include "dev/adc.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/uart.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/serial-line.h"
|
||||
#include "dev/slip.h"
|
||||
#include "dev/cc2538-rf.h"
|
||||
#include "dev/udma.h"
|
||||
#include "dev/crypto.h"
|
||||
#include "dev/button-hal.h"
|
||||
#include "usb/usb-serial.h"
|
||||
#include "lib/random.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/mac/framer/frame802154.h"
|
||||
#include "net/linkaddr.h"
|
||||
|
@ -121,8 +122,6 @@ platform_init_stage_one(void)
|
|||
void
|
||||
platform_init_stage_two()
|
||||
{
|
||||
button_sensor_init();
|
||||
|
||||
/*
|
||||
* Character I/O Initialisation.
|
||||
* When the UART receives a character it will call serial_line_input_byte to
|
||||
|
@ -159,6 +158,8 @@ platform_init_stage_two()
|
|||
/* Populate linkaddr_node_addr */
|
||||
ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE);
|
||||
|
||||
button_hal_init();
|
||||
|
||||
INTERRUPTS_ENABLE();
|
||||
|
||||
fade(LEDS_GREEN);
|
||||
|
|
|
@ -32,5 +32,5 @@ $(CONTIKI_APP).cooja: $(JNILIB)
|
|||
|
||||
# Trickiness: GNU make matches this against the file base name.
|
||||
# Assume that the directory part is the standard location.
|
||||
mtype%.o: contiki-cooja-main.o | $(OBJECTDIR)
|
||||
mv contiki-cooja-main.o $@
|
||||
mtype%.o: platform.o | $(OBJECTDIR)
|
||||
mv platform.o $@
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
#include "subplatform-conf.h"
|
||||
#endif /* INCLUDE_SUBPLATFORM_CONF */
|
||||
|
||||
#define PLATFORM_CONF_PROVIDES_MAIN_LOOP 1
|
||||
|
||||
#define LOG_CONF_ENABLED 1
|
||||
|
||||
#define COOJA 1
|
||||
|
|
|
@ -45,7 +45,12 @@
|
|||
#include "sys/clock.h"
|
||||
#include "sys/etimer.h"
|
||||
#include "sys/cooja_mt.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Log configuration */
|
||||
#include "sys/log.h"
|
||||
#define LOG_MODULE "Cooja"
|
||||
#define LOG_LEVEL LOG_LEVEL_MAIN
|
||||
|
||||
#include "lib/random.h"
|
||||
#include "lib/simEnvChange.h"
|
||||
|
@ -71,7 +76,7 @@
|
|||
|
||||
/* JNI-defined functions, depends on the environment variable CLASSNAME */
|
||||
#ifndef CLASSNAME
|
||||
#error CLASSNAME is undefined, required by contiki-cooja-main.c
|
||||
#error CLASSNAME is undefined, required by platform.c
|
||||
#endif /* CLASSNAME */
|
||||
#define COOJA__QUOTEME(a,b,c) COOJA_QUOTEME(a,b,c)
|
||||
#define COOJA_QUOTEME(a,b,c) a##b##c
|
||||
|
@ -82,15 +87,14 @@
|
|||
#define Java_org_contikios_cooja_corecomm_CLASSNAME_tick COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_tick)
|
||||
#define Java_org_contikios_cooja_corecomm_CLASSNAME_setReferenceAddress COOJA__QUOTEME(COOJA_JNI_PATH,CLASSNAME,_setReferenceAddress)
|
||||
|
||||
#ifndef NETSTACK_CONF_WITH_IPV6
|
||||
#define NETSTACK_CONF_WITH_IPV6 0
|
||||
#endif
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
#include "net/ipv6/uip.h"
|
||||
#include "net/ipv6/uip-ds6.h"
|
||||
#define PRINT6ADDR(addr) printf("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x", ((uint8_t *)addr)[0], ((uint8_t *)addr)[1], ((uint8_t *)addr)[2], ((uint8_t *)addr)[3], ((uint8_t *)addr)[4], ((uint8_t *)addr)[5], ((uint8_t *)addr)[6], ((uint8_t *)addr)[7], ((uint8_t *)addr)[8], ((uint8_t *)addr)[9], ((uint8_t *)addr)[10], ((uint8_t *)addr)[11], ((uint8_t *)addr)[12], ((uint8_t *)addr)[13], ((uint8_t *)addr)[14], ((uint8_t *)addr)[15])
|
||||
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||
|
||||
/* The main function, implemented in contiki-main.c */
|
||||
int main(void);
|
||||
|
||||
/* Simulation mote interfaces */
|
||||
SIM_INTERFACE_NAME(moteid_interface);
|
||||
SIM_INTERFACE_NAME(vib_interface);
|
||||
|
@ -124,18 +128,6 @@ long referenceVar;
|
|||
static struct cooja_mt_thread rtimer_thread;
|
||||
static struct cooja_mt_thread process_run_thread;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
print_processes(struct process * const processes[])
|
||||
{
|
||||
/* const struct process * const * p = processes;*/
|
||||
printf("Starting");
|
||||
while(*processes != NULL) {
|
||||
printf(" '%s'", (*processes)->name);
|
||||
processes++;
|
||||
}
|
||||
putchar('\n');
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
rtimer_thread_loop(void *data)
|
||||
|
@ -168,120 +160,65 @@ set_lladdr(void)
|
|||
addr.u8[1] = node_id >> 8;
|
||||
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||
linkaddr_set_node_addr(&addr);
|
||||
|
||||
printf("Link-layer address ");
|
||||
log_lladdr(&addr);
|
||||
printf("\n");
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
contiki_init()
|
||||
platform_init_stage_one()
|
||||
{
|
||||
return;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
platform_init_stage_two()
|
||||
{
|
||||
/* Initialize random generator (moved to moteid.c) */
|
||||
|
||||
/* Start process handler */
|
||||
process_init();
|
||||
|
||||
|
||||
/* Start Contiki processes */
|
||||
|
||||
process_start(&etimer_process, NULL);
|
||||
process_start(&sensors_process, NULL);
|
||||
ctimer_init();
|
||||
|
||||
/* Print startup information */
|
||||
printf(CONTIKI_VERSION_STRING " started. ");
|
||||
if(node_id > 0) {
|
||||
printf("Node id is set to %u.\n", node_id);
|
||||
} else {
|
||||
printf("Node id is not set.\n");
|
||||
}
|
||||
|
||||
set_lladdr();
|
||||
{
|
||||
uint8_t longaddr[8];
|
||||
|
||||
memset(longaddr, 0, sizeof(longaddr));
|
||||
linkaddr_copy((linkaddr_t *)&longaddr, &linkaddr_node_addr);
|
||||
printf("MAC %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x ",
|
||||
longaddr[0], longaddr[1], longaddr[2], longaddr[3],
|
||||
longaddr[4], longaddr[5], longaddr[6], longaddr[7]);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
platform_init_stage_three()
|
||||
{
|
||||
if(node_id > 0) {
|
||||
LOG_INFO("Node id is set to %u.\n", node_id);
|
||||
} else {
|
||||
LOG_INFO("Node id is not set.\n");
|
||||
}
|
||||
|
||||
/* Initialize communication stack */
|
||||
netstack_init();
|
||||
printf("%s/%s\n",
|
||||
NETSTACK_NETWORK.name, NETSTACK_MAC.name);
|
||||
|
||||
#if NETSTACK_CONF_WITH_IPV6
|
||||
/* IPv6 CONFIGURATION */
|
||||
{
|
||||
int i;
|
||||
uip_ds6_addr_t *lladdr;
|
||||
uint8_t addr[sizeof(uip_lladdr.addr)];
|
||||
for(i = 0; i < sizeof(uip_lladdr.addr); i += 2) {
|
||||
addr[i + 1] = node_id & 0xff;
|
||||
addr[i + 0] = node_id >> 8;
|
||||
}
|
||||
linkaddr_copy((linkaddr_t *)addr, &linkaddr_node_addr);
|
||||
memcpy(&uip_lladdr.addr, addr, sizeof(uip_lladdr.addr));
|
||||
|
||||
process_start(&tcpip_process, NULL);
|
||||
|
||||
lladdr = uip_ds6_get_link_local(-1);
|
||||
printf("Tentative link-local IPv6 address ");
|
||||
log_6addr(lladdr != NULL ? &lladdr->ipaddr : NULL);
|
||||
printf("\n");
|
||||
}
|
||||
#endif /* NETSTACK_CONF_WITH_IPV6 */
|
||||
|
||||
/* Initialize eeprom */
|
||||
eeprom_init();
|
||||
|
||||
/* Start serial process */
|
||||
serial_line_init();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
platform_main_loop()
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
simProcessRunValue = process_run();
|
||||
while(simProcessRunValue-- > 0) {
|
||||
process_run();
|
||||
}
|
||||
simProcessRunValue = process_nevents();
|
||||
|
||||
#if BUILD_WITH_RPL_BORDER_ROUTER
|
||||
rpl_border_router_init();
|
||||
#endif /* BUILD_WITH_RPL_BORDER_ROUTER */
|
||||
#if BUILD_WITH_ORCHESTRA
|
||||
orchestra_init();
|
||||
#endif /* BUILD_WITH_ORCHESTRA */
|
||||
#if BUILD_WITH_SHELL
|
||||
serial_shell_init();
|
||||
#endif /* BUILD_WITH_SHELL */
|
||||
/* Check if we must stay awake */
|
||||
if(simDontFallAsleep) {
|
||||
simDontFallAsleep = 0;
|
||||
simProcessRunValue = 1;
|
||||
}
|
||||
|
||||
/* Start autostart processes (defined in Contiki application) */
|
||||
print_processes(autostart_processes);
|
||||
autostart_start(autostart_processes);
|
||||
/* Return to COOJA */
|
||||
cooja_mt_yield();
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
process_run_thread_loop(void *data)
|
||||
{
|
||||
/* Yield once during bootup */
|
||||
simProcessRunValue = 1;
|
||||
cooja_mt_yield();
|
||||
/* Yield once during bootup */
|
||||
simProcessRunValue = 1;
|
||||
cooja_mt_yield();
|
||||
|
||||
contiki_init();
|
||||
|
||||
while(1)
|
||||
{
|
||||
simProcessRunValue = process_run();
|
||||
while(simProcessRunValue-- > 0) {
|
||||
process_run();
|
||||
}
|
||||
simProcessRunValue = process_nevents();
|
||||
|
||||
/* Check if we must stay awake */
|
||||
if(simDontFallAsleep) {
|
||||
simDontFallAsleep=0;
|
||||
simProcessRunValue = 1;
|
||||
}
|
||||
|
||||
/* Return to COOJA */
|
||||
cooja_mt_yield();
|
||||
}
|
||||
/* Then call common Contiki-NG main function */
|
||||
main();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
|
@ -15,7 +15,7 @@ PLATFORM_ROOT_DIR = $(CONTIKI)/arch/platform/$(TARGET)
|
|||
|
||||
### Include
|
||||
CONTIKI_TARGET_SOURCEFILES += platform.c board.c
|
||||
CONTIKI_TARGET_SOURCEFILES += leds-arch.c button-sensor.c openmote-sensors.c
|
||||
CONTIKI_TARGET_SOURCEFILES += leds-arch.c board-buttons.c openmote-sensors.c
|
||||
CONTIKI_TARGET_SOURCEFILES += antenna.c adxl346.c max44009.c sht21.c tps62730.c
|
||||
|
||||
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
|
|
|
@ -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
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup openmote-cc2538
|
||||
* @{
|
||||
*
|
||||
* \defgroup openmote-cc2538-buttons OpenMote-CC2538 user button
|
||||
*
|
||||
* Generic module controlling the user button on the OpenMote-CC2538
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Defines the OpenMote-CC2538 user button for use with the button HAL
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/button-hal.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
BUTTON_HAL_BUTTON(button_user, "User button", \
|
||||
GPIO_PORT_PIN_TO_GPIO_HAL_PIN(BUTTON_USER_PORT, BUTTON_USER_PIN), \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BUTTON_HAL_ID_USER_BUTTON, true);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
BUTTON_HAL_BUTTONS(&button_user);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
|
@ -1,178 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup openmote-button-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for for the OpenMote-CC2538 user button
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/nvic.h"
|
||||
#include "dev/ioc.h"
|
||||
#include "dev/gpio.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "sys/timer.h"
|
||||
#include "sys/ctimer.h"
|
||||
#include "sys/process.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_USER_PORT_BASE GPIO_PORT_TO_BASE(BUTTON_USER_PORT)
|
||||
#define BUTTON_USER_PIN_MASK GPIO_PIN_MASK(BUTTON_USER_PIN)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBOUNCE_DURATION (CLOCK_SECOND >> 4)
|
||||
|
||||
static struct timer debouncetimer;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static clock_time_t press_duration = 0;
|
||||
static struct ctimer press_counter;
|
||||
static uint8_t press_event_counter;
|
||||
|
||||
process_event_t button_press_duration_exceeded;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
duration_exceeded_callback(void *data)
|
||||
{
|
||||
press_event_counter++;
|
||||
process_post(PROCESS_BROADCAST, button_press_duration_exceeded,
|
||||
&press_event_counter);
|
||||
ctimer_set(&press_counter, press_duration, duration_exceeded_callback,
|
||||
NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Retrieves the value of the button pin
|
||||
* \param type Returns the pin level or the counter of press duration events.
|
||||
* type == BUTTON_SENSOR_VALUE_TYPE_LEVEL or
|
||||
* type == BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION
|
||||
* respectively
|
||||
*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case BUTTON_SENSOR_VALUE_TYPE_LEVEL:
|
||||
return GPIO_READ_PIN(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
case BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION:
|
||||
return press_event_counter;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
button_press_handler(gpio_hal_pin_mask_t pin_mask)
|
||||
{
|
||||
if(!timer_expired(&debouncetimer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&debouncetimer, DEBOUNCE_DURATION);
|
||||
|
||||
if(press_duration) {
|
||||
press_event_counter = 0;
|
||||
if(value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) == BUTTON_SENSOR_PRESSED_LEVEL) {
|
||||
ctimer_set(&press_counter, press_duration, duration_exceeded_callback,
|
||||
NULL);
|
||||
} else {
|
||||
ctimer_stop(&press_counter);
|
||||
}
|
||||
}
|
||||
|
||||
sensors_changed(&button_sensor);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static gpio_hal_event_handler_t press_handler = {
|
||||
.next = NULL,
|
||||
.handler = button_press_handler,
|
||||
.pin_mask = gpio_hal_pin_to_mask(BUTTON_USER_PIN) << (BUTTON_USER_PORT << 3),
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Init function for the User button.
|
||||
* \param type SENSORS_ACTIVE: Activate / Deactivate the sensor (value == 1
|
||||
* or 0 respectively)
|
||||
*
|
||||
* \param value Depends on the value of the type argument
|
||||
* \return Depends on the value of the type argument
|
||||
*/
|
||||
static int
|
||||
config_user(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
button_press_duration_exceeded = process_alloc_event();
|
||||
|
||||
/* Software controlled */
|
||||
GPIO_SOFTWARE_CONTROL(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
|
||||
/* Set pin to input */
|
||||
GPIO_SET_INPUT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
|
||||
/* Enable edge detection */
|
||||
GPIO_DETECT_EDGE(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
|
||||
/* Both Edges */
|
||||
GPIO_TRIGGER_BOTH_EDGES(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
|
||||
ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE);
|
||||
|
||||
gpio_hal_register_handler(&press_handler);
|
||||
break;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
GPIO_ENABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
NVIC_EnableIRQ(BUTTON_USER_VECTOR);
|
||||
} else {
|
||||
GPIO_DISABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
NVIC_DisableIRQ(BUTTON_USER_VECTOR);
|
||||
}
|
||||
return value;
|
||||
case BUTTON_SENSOR_CONFIG_TYPE_INTERVAL:
|
||||
press_duration = (clock_time_t)value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, value, config_user, NULL);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -52,7 +52,7 @@
|
|||
/**
|
||||
* \brief Exports a global symbol to be used by the sensor API
|
||||
*/
|
||||
SENSORS(&button_sensor, &cc2538_temp_sensor);
|
||||
SENSORS(&cc2538_temp_sensor);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
|
|
|
@ -49,7 +49,6 @@
|
|||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/cc2538-sensors.h"
|
||||
#include "dev/button-sensor.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* OPENMOTE_SENSORS_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -55,8 +55,10 @@
|
|||
#include "dev/cc2538-rf.h"
|
||||
#include "dev/udma.h"
|
||||
#include "dev/crypto.h"
|
||||
#include "dev/button-hal.h"
|
||||
#include "usb/usb-serial.h"
|
||||
#include "lib/random.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/mac/framer/frame802154.h"
|
||||
#include "net/linkaddr.h"
|
||||
|
@ -157,6 +159,8 @@ platform_init_stage_two()
|
|||
/* Populate linkaddr_node_addr */
|
||||
ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE);
|
||||
|
||||
button_hal_init();
|
||||
|
||||
INTERRUPTS_ENABLE();
|
||||
|
||||
fade(LEDS_BLUE);
|
||||
|
@ -175,8 +179,6 @@ platform_init_stage_three()
|
|||
|
||||
process_start(&sensors_process, NULL);
|
||||
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
|
||||
fade(LEDS_GREEN);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -2,7 +2,7 @@ CFLAGS += -DBOARD_LAUNCHPAD=1
|
|||
|
||||
CONTIKI_TARGET_DIRS += launchpad common
|
||||
|
||||
BOARD_SOURCEFILES += board.c launchpad-sensors.c button-sensor.c xmem.c
|
||||
BOARD_SOURCEFILES += board.c board-buttons.c xmem.c
|
||||
BOARD_SOURCEFILES += ext-flash.c board-spi.c
|
||||
|
||||
### Signal that we can be programmed with cc2538-bsl
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup launchpad-cc26xx-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Defines CC13xx/CC26xx Launchpad buttons for use with the button HAL
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/button-hal.h"
|
||||
|
||||
#include "ti-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
BUTTON_HAL_BUTTON(key_left, "Key Left", BOARD_IOID_KEY_LEFT, \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BOARD_BUTTON_HAL_INDEX_KEY_LEFT, \
|
||||
true);
|
||||
|
||||
BUTTON_HAL_BUTTON(key_right, "Key Right", BOARD_IOID_KEY_RIGHT, \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BOARD_BUTTON_HAL_INDEX_KEY_RIGHT, \
|
||||
true);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
BUTTON_HAL_BUTTONS(&key_left, &key_right);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -48,6 +48,8 @@
|
|||
/*---------------------------------------------------------------------------*/
|
||||
#include "ext-flash.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BOARD_CONF_HAS_SENSORS 0
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BOARD_PERIPHERALS_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "lpm.h"
|
||||
#include "ti-lib.h"
|
||||
#include "board-peripherals.h"
|
||||
|
|
|
@ -1,225 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup launchpad-button-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for LaunchPad buttons
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "launchpad/button-sensor.h"
|
||||
#include "gpio-hal.h"
|
||||
#include "sys/timer.h"
|
||||
#include "lpm.h"
|
||||
|
||||
#include "ti-lib.h"
|
||||
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN
|
||||
#define BUTTON_SENSOR_ENABLE_SHUTDOWN BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN
|
||||
#else
|
||||
#define BUTTON_SENSOR_ENABLE_SHUTDOWN 1
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_GPIO_CFG (IOC_CURRENT_2MA | IOC_STRENGTH_AUTO | \
|
||||
IOC_IOPULL_UP | IOC_SLEW_DISABLE | \
|
||||
IOC_HYST_DISABLE | IOC_BOTH_EDGES | \
|
||||
IOC_INT_ENABLE | IOC_IOMODE_NORMAL | \
|
||||
IOC_NO_WAKE_UP | IOC_INPUT_ENABLE)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBOUNCE_DURATION (CLOCK_SECOND >> 5)
|
||||
|
||||
struct btn_timer {
|
||||
struct timer debounce;
|
||||
clock_time_t start;
|
||||
clock_time_t duration;
|
||||
};
|
||||
|
||||
static struct btn_timer left_timer, right_timer;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
button_press_handler(gpio_hal_pin_mask_t pin_mask)
|
||||
{
|
||||
if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_LEFT)) {
|
||||
if(!timer_expired(&left_timer.debounce)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&left_timer.debounce, DEBOUNCE_DURATION);
|
||||
|
||||
/*
|
||||
* Start press duration counter on press (falling), notify on release
|
||||
* (rising)
|
||||
*/
|
||||
if(ti_lib_gpio_read_dio(BOARD_IOID_KEY_LEFT) == 0) {
|
||||
left_timer.start = clock_time();
|
||||
left_timer.duration = 0;
|
||||
} else {
|
||||
left_timer.duration = clock_time() - left_timer.start;
|
||||
sensors_changed(&button_left_sensor);
|
||||
}
|
||||
}
|
||||
|
||||
if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_RIGHT)) {
|
||||
if(BUTTON_SENSOR_ENABLE_SHUTDOWN == 0) {
|
||||
if(!timer_expired(&right_timer.debounce)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&right_timer.debounce, DEBOUNCE_DURATION);
|
||||
|
||||
/*
|
||||
* Start press duration counter on press (falling), notify on release
|
||||
* (rising)
|
||||
*/
|
||||
if(ti_lib_gpio_read_dio(BOARD_IOID_KEY_RIGHT) == 0) {
|
||||
right_timer.start = clock_time();
|
||||
right_timer.duration = 0;
|
||||
} else {
|
||||
right_timer.duration = clock_time() - right_timer.start;
|
||||
sensors_changed(&button_right_sensor);
|
||||
}
|
||||
} else {
|
||||
lpm_shutdown(BOARD_IOID_KEY_RIGHT, IOC_IOPULL_UP, IOC_WAKE_ON_LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static gpio_hal_event_handler_t press_handler = {
|
||||
.next = NULL,
|
||||
.handler = button_press_handler,
|
||||
.pin_mask = 0,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
config_buttons(int type, int c, uint32_t key)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
ti_lib_gpio_clear_event_dio(key);
|
||||
ti_lib_rom_ioc_pin_type_gpio_input(key);
|
||||
ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
|
||||
press_handler.pin_mask |= gpio_hal_pin_to_mask(key);
|
||||
gpio_hal_register_handler(&press_handler);
|
||||
break;
|
||||
case SENSORS_ACTIVE:
|
||||
if(c) {
|
||||
ti_lib_gpio_clear_event_dio(key);
|
||||
ti_lib_rom_ioc_pin_type_gpio_input(key);
|
||||
ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
|
||||
ti_lib_rom_ioc_int_enable(key);
|
||||
} else {
|
||||
ti_lib_rom_ioc_int_disable(key);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
config_left(int type, int value)
|
||||
{
|
||||
config_buttons(type, value, BOARD_IOID_KEY_LEFT);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
config_right(int type, int value)
|
||||
{
|
||||
config_buttons(type, value, BOARD_IOID_KEY_RIGHT);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type, uint32_t key_io_id)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
if(ti_lib_rom_ioc_port_configure_get(key_io_id) & IOC_INT_ENABLE) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value_left(int type)
|
||||
{
|
||||
if(type == BUTTON_SENSOR_VALUE_STATE) {
|
||||
return ti_lib_gpio_read_dio(BOARD_IOID_KEY_LEFT) == 0 ?
|
||||
BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
|
||||
} else if(type == BUTTON_SENSOR_VALUE_DURATION) {
|
||||
return (int)left_timer.duration;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value_right(int type)
|
||||
{
|
||||
if(type == BUTTON_SENSOR_VALUE_STATE) {
|
||||
return ti_lib_gpio_read_dio(BOARD_IOID_KEY_RIGHT) == 0 ?
|
||||
BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
|
||||
} else if(type == BUTTON_SENSOR_VALUE_DURATION) {
|
||||
return (int)right_timer.duration;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status_left(int type)
|
||||
{
|
||||
return status(type, BOARD_IOID_KEY_LEFT);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status_right(int type)
|
||||
{
|
||||
return status(type, BOARD_IOID_KEY_RIGHT);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_left_sensor, BUTTON_SENSOR, value_left, config_left,
|
||||
status_left);
|
||||
SENSORS_SENSOR(button_right_sensor, BUTTON_SENSOR, value_right, config_right,
|
||||
status_right);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -62,7 +62,7 @@
|
|||
*/
|
||||
#define LEDS_CONF_COUNT 2
|
||||
#define LEDS_CONF_RED 1
|
||||
#define LEDS_CONF_YELLOW 2
|
||||
#define LEDS_CONF_GREEN 2
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -188,6 +188,16 @@
|
|||
}
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Board indices for the button HAL
|
||||
*
|
||||
* Those values are not meant to be modified by the user
|
||||
* @{
|
||||
*/
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_LEFT 0x00
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_RIGHT 0x01
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Device string used on startup
|
||||
* @{
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
*/
|
||||
#define LEDS_CONF_COUNT 2
|
||||
#define LEDS_CONF_RED 1
|
||||
#define LEDS_CONF_YELLOW 2
|
||||
#define LEDS_CONF_GREEN 2
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -205,6 +205,16 @@
|
|||
}
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Board indices for the button HAL
|
||||
*
|
||||
* Those values are not meant to be modified by the user
|
||||
* @{
|
||||
*/
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_LEFT 0x00
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_RIGHT 0x01
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Device string used on startup
|
||||
* @{
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
*/
|
||||
#define LEDS_CONF_COUNT 2
|
||||
#define LEDS_CONF_RED 1
|
||||
#define LEDS_CONF_YELLOW 2
|
||||
#define LEDS_CONF_GREEN 2
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
@ -189,6 +189,16 @@
|
|||
}
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Board indices for the button HAL
|
||||
*
|
||||
* Those values are not meant to be modified by the user
|
||||
* @{
|
||||
*/
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_LEFT 0x00
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_RIGHT 0x01
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Device string used on startup
|
||||
* @{
|
||||
|
|
|
@ -68,7 +68,9 @@
|
|||
#include "lib/sensors.h"
|
||||
#include "button-sensor.h"
|
||||
#include "dev/serial-line.h"
|
||||
#include "dev/button-hal.h"
|
||||
#include "net/mac/framer/frame802154.h"
|
||||
#include "board-peripherals.h"
|
||||
|
||||
#include "driverlib/driverlib_release.h"
|
||||
|
||||
|
@ -84,6 +86,12 @@ unsigned short node_id = 0;
|
|||
/** \brief Board specific iniatialisation */
|
||||
void board_init(void);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef BOARD_CONF_HAS_SENSORS
|
||||
#define BOARD_HAS_SENSORS BOARD_CONF_HAS_SENSORS
|
||||
#else
|
||||
#define BOARD_HAS_SENSORS 1
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
fade(leds_mask_t l)
|
||||
{
|
||||
|
@ -188,6 +196,9 @@ platform_init_stage_two()
|
|||
#else
|
||||
ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE);
|
||||
#endif
|
||||
|
||||
button_hal_init();
|
||||
|
||||
fade(LEDS_GREEN);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -218,7 +229,10 @@ platform_init_stage_three()
|
|||
|
||||
LOG_INFO(" Node ID: %d\n", node_id);
|
||||
|
||||
#if BOARD_HAS_SENSORS
|
||||
process_start(&sensors_process, NULL);
|
||||
#endif
|
||||
|
||||
fade(LEDS_ORANGE);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -3,8 +3,8 @@ CFLAGS += -DBACKDOOR_IOID=0x00000000
|
|||
|
||||
CONTIKI_TARGET_DIRS += sensortag common
|
||||
|
||||
BOARD_SOURCEFILES += sensortag-sensors.c sensor-common.c
|
||||
BOARD_SOURCEFILES += sensortag-sensors.c board-buttons.c sensor-common.c
|
||||
BOARD_SOURCEFILES += bmp-280-sensor.c tmp-007-sensor.c opt-3001-sensor.c
|
||||
BOARD_SOURCEFILES += hdc-1000-sensor.c mpu-9250-sensor.c button-sensor.c xmem.c
|
||||
BOARD_SOURCEFILES += reed-relay.c ext-flash.c buzzer.c
|
||||
BOARD_SOURCEFILES += hdc-1000-sensor.c mpu-9250-sensor.c xmem.c
|
||||
BOARD_SOURCEFILES += ext-flash.c buzzer.c
|
||||
BOARD_SOURCEFILES += board.c board-spi.c board-i2c.c
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
|
@ -32,34 +33,30 @@
|
|||
* \addtogroup sensortag-cc26xx-peripherals
|
||||
* @{
|
||||
*
|
||||
* \defgroup sensortag-cc26xx-button-sensor SensorTag 2.0 Button Sensor
|
||||
*
|
||||
* One of the buttons can be configured as general purpose or as an on/off key
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the Sensortag Button Driver
|
||||
* Defines Sensortag buttons for use with the button HAL
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef BUTTON_SENSOR_H_
|
||||
#define BUTTON_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR "Button"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR_VALUE_STATE 0
|
||||
#define BUTTON_SENSOR_VALUE_DURATION 1
|
||||
#include "contiki.h"
|
||||
#include "dev/gpio-hal.h"
|
||||
#include "dev/button-hal.h"
|
||||
|
||||
#define BUTTON_SENSOR_VALUE_RELEASED 0
|
||||
#define BUTTON_SENSOR_VALUE_PRESSED 1
|
||||
#include "ti-lib.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor button_left_sensor;
|
||||
extern const struct sensors_sensor button_right_sensor;
|
||||
BUTTON_HAL_BUTTON(reed_relay, "Reed Relay", BOARD_IOID_REED_RELAY, \
|
||||
GPIO_HAL_PIN_CFG_PULL_DOWN, \
|
||||
BOARD_BUTTON_HAL_INDEX_REED_RELAY, true);
|
||||
|
||||
BUTTON_HAL_BUTTON(key_left, "Key Left", BOARD_IOID_KEY_LEFT, \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BOARD_BUTTON_HAL_INDEX_KEY_LEFT, \
|
||||
true);
|
||||
|
||||
BUTTON_HAL_BUTTON(key_right, "Key Right", BOARD_IOID_KEY_RIGHT, \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BOARD_BUTTON_HAL_INDEX_KEY_RIGHT, \
|
||||
true);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BUTTON_SENSOR_H_ */
|
||||
BUTTON_HAL_BUTTONS(&reed_relay, &key_left, &key_right);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
/** @} */
|
|
@ -53,7 +53,6 @@
|
|||
#include "opt-3001-sensor.h"
|
||||
#include "hdc-1000-sensor.h"
|
||||
#include "mpu-9250-sensor.h"
|
||||
#include "reed-relay.h"
|
||||
#include "buzzer.h"
|
||||
#include "ext-flash.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -1,288 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup sensortag-cc26xx-button-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for Sensortag buttons
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "sensortag/button-sensor.h"
|
||||
#include "gpio-hal.h"
|
||||
#include "sys/timer.h"
|
||||
#include "lpm.h"
|
||||
|
||||
#include "ti-lib.h"
|
||||
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN
|
||||
#define BUTTON_SENSOR_ENABLE_SHUTDOWN BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN
|
||||
#else
|
||||
#define BUTTON_SENSOR_ENABLE_SHUTDOWN 1
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_GPIO_CFG (IOC_CURRENT_2MA | IOC_STRENGTH_AUTO | \
|
||||
IOC_IOPULL_UP | IOC_SLEW_DISABLE | \
|
||||
IOC_HYST_DISABLE | IOC_BOTH_EDGES | \
|
||||
IOC_INT_ENABLE | IOC_IOMODE_NORMAL | \
|
||||
IOC_NO_WAKE_UP | IOC_INPUT_ENABLE)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBOUNCE_DURATION (CLOCK_SECOND >> 5)
|
||||
|
||||
struct btn_timer {
|
||||
struct timer debounce;
|
||||
clock_time_t start;
|
||||
clock_time_t duration;
|
||||
};
|
||||
|
||||
static struct btn_timer left_timer, right_timer;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Handler for Sensortag-CC26XX button presses
|
||||
*/
|
||||
static void
|
||||
button_press_handler(gpio_hal_pin_mask_t pin_mask)
|
||||
{
|
||||
if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_LEFT)) {
|
||||
if(!timer_expired(&left_timer.debounce)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&left_timer.debounce, DEBOUNCE_DURATION);
|
||||
|
||||
/*
|
||||
* Start press duration counter on press (falling), notify on release
|
||||
* (rising)
|
||||
*/
|
||||
if(ti_lib_gpio_read_dio(BOARD_IOID_KEY_LEFT) == 0) {
|
||||
left_timer.start = clock_time();
|
||||
left_timer.duration = 0;
|
||||
} else {
|
||||
left_timer.duration = clock_time() - left_timer.start;
|
||||
sensors_changed(&button_left_sensor);
|
||||
}
|
||||
}
|
||||
|
||||
if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_RIGHT)) {
|
||||
if(BUTTON_SENSOR_ENABLE_SHUTDOWN == 0) {
|
||||
if(!timer_expired(&right_timer.debounce)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&right_timer.debounce, DEBOUNCE_DURATION);
|
||||
|
||||
/*
|
||||
* Start press duration counter on press (falling), notify on release
|
||||
* (rising)
|
||||
*/
|
||||
if(ti_lib_gpio_read_dio(BOARD_IOID_KEY_RIGHT) == 0) {
|
||||
right_timer.start = clock_time();
|
||||
right_timer.duration = 0;
|
||||
} else {
|
||||
right_timer.duration = clock_time() - right_timer.start;
|
||||
sensors_changed(&button_right_sensor);
|
||||
}
|
||||
} else {
|
||||
lpm_shutdown(BOARD_IOID_KEY_RIGHT, IOC_IOPULL_UP, IOC_WAKE_ON_LOW);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static gpio_hal_event_handler_t press_handler = {
|
||||
.next = NULL,
|
||||
.handler = button_press_handler,
|
||||
.pin_mask = 0,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Configuration function for the button sensor for all buttons.
|
||||
*
|
||||
* \param type This function does nothing unless type == SENSORS_ACTIVE
|
||||
* \param c 0: disable the button, non-zero: enable
|
||||
* \param key: One of BOARD_KEY_LEFT, BOARD_KEY_RIGHT etc
|
||||
*/
|
||||
static void
|
||||
config_buttons(int type, int c, uint32_t key)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
ti_lib_gpio_clear_event_dio(key);
|
||||
ti_lib_rom_ioc_pin_type_gpio_input(key);
|
||||
ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
|
||||
press_handler.pin_mask |= gpio_hal_pin_to_mask(key);
|
||||
gpio_hal_register_handler(&press_handler);
|
||||
break;
|
||||
case SENSORS_ACTIVE:
|
||||
if(c) {
|
||||
ti_lib_gpio_clear_event_dio(key);
|
||||
ti_lib_rom_ioc_pin_type_gpio_input(key);
|
||||
ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
|
||||
ti_lib_rom_ioc_int_enable(key);
|
||||
} else {
|
||||
ti_lib_rom_ioc_int_disable(key);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Configuration function for the left button.
|
||||
*
|
||||
* Parameters are passed onto config_buttons, which does the actual
|
||||
* configuration
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor API. The return value is also required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type passed to config_buttons as-is
|
||||
* \param value passed to config_buttons as-is
|
||||
*
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_left(int type, int value)
|
||||
{
|
||||
config_buttons(type, value, BOARD_IOID_KEY_LEFT);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Configuration function for the right button.
|
||||
*
|
||||
* Parameters are passed onto config_buttons, which does the actual
|
||||
* configuration
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor api. The return value is also required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type passed to config_buttons as-is
|
||||
* \param value passed to config_buttons as-is
|
||||
*
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_right(int type, int value)
|
||||
{
|
||||
config_buttons(type, value, BOARD_IOID_KEY_RIGHT);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Status function for all buttons
|
||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
||||
* \param key_io_id BOARD_IOID_KEY_LEFT, BOARD_IOID_KEY_RIGHT etc
|
||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
||||
*
|
||||
* This function will only be called by status_left, status_right and the
|
||||
* called will pass the correct key_io_id
|
||||
*/
|
||||
static int
|
||||
status(int type, uint32_t key_io_id)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
if(ti_lib_ioc_port_configure_get(key_io_id) & IOC_INT_ENABLE) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value_left(int type)
|
||||
{
|
||||
if(type == BUTTON_SENSOR_VALUE_STATE) {
|
||||
return ti_lib_gpio_read_dio(BOARD_IOID_KEY_LEFT) == 0 ?
|
||||
BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
|
||||
} else if(type == BUTTON_SENSOR_VALUE_DURATION) {
|
||||
return (int)left_timer.duration;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value_right(int type)
|
||||
{
|
||||
if(type == BUTTON_SENSOR_VALUE_STATE) {
|
||||
return ti_lib_gpio_read_dio(BOARD_IOID_KEY_RIGHT) == 0 ?
|
||||
BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
|
||||
} else if(type == BUTTON_SENSOR_VALUE_DURATION) {
|
||||
return (int)right_timer.duration;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Status function for the left button.
|
||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
||||
*
|
||||
* This function will call status. It will pass type verbatim and it will also
|
||||
* pass the correct key_io_id
|
||||
*/
|
||||
static int
|
||||
status_left(int type)
|
||||
{
|
||||
return status(type, BOARD_IOID_KEY_LEFT);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Status function for the right button.
|
||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
||||
*
|
||||
* This function will call status. It will pass type verbatim and it will also
|
||||
* pass the correct key_io_id
|
||||
*/
|
||||
static int
|
||||
status_right(int type)
|
||||
{
|
||||
return status(type, BOARD_IOID_KEY_RIGHT);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_left_sensor, BUTTON_SENSOR, value_left, config_left,
|
||||
status_left);
|
||||
SENSORS_SENSOR(button_right_sensor, BUTTON_SENSOR, value_right, config_right,
|
||||
status_right);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -238,6 +238,17 @@
|
|||
#define SMARTRF_SETTINGS_CONF_OVERRIDE_TRIM_OFFSET 0x00018883
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Board indices for the button HAL
|
||||
*
|
||||
* Those values are not meant to be modified by the user
|
||||
* @{
|
||||
*/
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_LEFT 0x00
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_RIGHT 0x01
|
||||
#define BOARD_BUTTON_HAL_INDEX_REED_RELAY 0xFF
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Device string used on startup
|
||||
* @{
|
||||
|
|
|
@ -218,6 +218,17 @@
|
|||
#define BOARD_IOID_AUDIO_CLK IOID_11
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Board indices for the button HAL
|
||||
*
|
||||
* Those values are not meant to be modified by the user
|
||||
* @{
|
||||
*/
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_LEFT 0x00
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_RIGHT 0x01
|
||||
#define BOARD_BUTTON_HAL_INDEX_REED_RELAY 0xFF
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Device string used on startup
|
||||
* @{
|
||||
|
|
|
@ -1,145 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup sensortag-cc26xx-reed-relay
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the Sensortag Reed Relay
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "sys/clock.h"
|
||||
#include "sys/timer.h"
|
||||
#include "dev/gpio-hal.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "sensortag/reed-relay.h"
|
||||
#include "sys/timer.h"
|
||||
|
||||
#include "ti-lib.h"
|
||||
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct timer debouncetimer;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define REED_IO_CFG (IOC_CURRENT_2MA | IOC_STRENGTH_AUTO | \
|
||||
IOC_IOPULL_DOWN | IOC_SLEW_DISABLE | \
|
||||
IOC_HYST_DISABLE | IOC_BOTH_EDGES | \
|
||||
IOC_INT_DISABLE | IOC_IOMODE_NORMAL | \
|
||||
IOC_NO_WAKE_UP | IOC_INPUT_ENABLE)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Handler for Sensortag-CC26XX reed interrupts
|
||||
*/
|
||||
static void
|
||||
reed_interrupt_handler(gpio_hal_pin_mask_t pin_mask)
|
||||
{
|
||||
if(!timer_expired(&debouncetimer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
sensors_changed(&reed_relay_sensor);
|
||||
timer_set(&debouncetimer, CLOCK_SECOND / 2);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return (int)ti_lib_gpio_read_dio(BOARD_IOID_REED_RELAY);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static gpio_hal_event_handler_t event_handler = {
|
||||
.next = NULL,
|
||||
.handler = reed_interrupt_handler,
|
||||
.pin_mask = gpio_hal_pin_to_mask(BOARD_IOID_REED_RELAY),
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Configuration function for the button sensor for all buttons.
|
||||
*
|
||||
* \param type SENSORS_HW_INIT: Initialise. SENSORS_ACTIVE: Enables/Disables
|
||||
* depending on 'value'
|
||||
* \param value 0: disable, non-zero: enable
|
||||
* \return Always returns 1
|
||||
*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
ti_lib_ioc_int_disable(BOARD_IOID_REED_RELAY);
|
||||
ti_lib_gpio_clear_event_dio(BOARD_IOID_REED_RELAY);
|
||||
|
||||
/* Enable the GPIO clock when the CM3 is running */
|
||||
ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_GPIO);
|
||||
|
||||
/* S/W control, input, pull-down */
|
||||
ti_lib_ioc_port_configure_set(BOARD_IOID_REED_RELAY, IOC_PORT_GPIO,
|
||||
REED_IO_CFG);
|
||||
|
||||
gpio_hal_register_handler(&event_handler);
|
||||
break;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
ti_lib_ioc_int_enable(BOARD_IOID_REED_RELAY);
|
||||
} else {
|
||||
ti_lib_ioc_int_disable(BOARD_IOID_REED_RELAY);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Status function for the reed
|
||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
||||
* \return 1 Interrupt enabled, 0: Disabled
|
||||
*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return (ti_lib_ioc_port_configure_get(BOARD_IOID_REED_RELAY)
|
||||
& IOC_INT_ENABLE) == IOC_INT_ENABLE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(reed_relay_sensor, "REED", value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -37,19 +37,16 @@
|
|||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "sensortag/button-sensor.h"
|
||||
#include "sensortag/bmp-280-sensor.h"
|
||||
#include "sensortag/tmp-007-sensor.h"
|
||||
#include "sensortag/opt-3001-sensor.h"
|
||||
#include "sensortag/hdc-1000-sensor.h"
|
||||
#include "sensortag/mpu-9250-sensor.h"
|
||||
#include "sensortag/reed-relay.h"
|
||||
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \brief Exports a global symbol to be used by the sensor API */
|
||||
SENSORS(&button_left_sensor, &button_right_sensor,
|
||||
&bmp_280_sensor, &tmp_007_sensor, &opt_3001_sensor, &hdc_1000_sensor,
|
||||
&mpu_9250_sensor, &reed_relay_sensor);
|
||||
SENSORS(&bmp_280_sensor, &tmp_007_sensor, &opt_3001_sensor, &hdc_1000_sensor,
|
||||
&mpu_9250_sensor);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
|
@ -2,7 +2,7 @@ CFLAGS += -DBOARD_SMARTRF06EB=1
|
|||
|
||||
CONTIKI_TARGET_DIRS += srf06
|
||||
|
||||
BOARD_SOURCEFILES += srf06-sensors.c button-sensor.c board.c
|
||||
BOARD_SOURCEFILES += srf06-sensors.c board-buttons.c board.c
|
||||
BOARD_SOURCEFILES += als-sensor.c
|
||||
|
||||
### Signal that we can be programmed with cc2538-bsl
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup srf06-common-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Defines SmarfRF06 + CC13xxEM/CC26xxEM buttons for use with the button HAL
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/button-hal.h"
|
||||
|
||||
#include "ti-lib.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
BUTTON_HAL_BUTTON(key_left, "Key Left", BOARD_IOID_KEY_LEFT, \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BOARD_BUTTON_HAL_INDEX_KEY_LEFT, \
|
||||
true);
|
||||
BUTTON_HAL_BUTTON(key_right, "Key Right", BOARD_IOID_KEY_RIGHT, \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BOARD_BUTTON_HAL_INDEX_KEY_RIGHT, \
|
||||
true);
|
||||
BUTTON_HAL_BUTTON(key_up, "Key Up", BOARD_IOID_KEY_UP, \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BOARD_BUTTON_HAL_INDEX_KEY_UP, \
|
||||
true);
|
||||
BUTTON_HAL_BUTTON(key_down, "Key Down", BOARD_IOID_KEY_DOWN, \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BOARD_BUTTON_HAL_INDEX_KEY_DOWN, \
|
||||
true);
|
||||
BUTTON_HAL_BUTTON(key_select, "Key Select", BOARD_IOID_KEY_SELECT, \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, \
|
||||
BOARD_BUTTON_HAL_INDEX_KEY_SELECT, true);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
BUTTON_HAL_BUTTONS(&key_left, &key_right, &key_up, &key_down, &key_select);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -1,498 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup srf06-common-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the SmartRF06EB buttons when a CC13xx/CC26xxEM is mounted on it
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "srf06/button-sensor.h"
|
||||
#include "gpio-hal.h"
|
||||
#include "sys/timer.h"
|
||||
#include "lpm.h"
|
||||
|
||||
#include "ti-lib.h"
|
||||
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN
|
||||
#define BUTTON_SENSOR_ENABLE_SHUTDOWN BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN
|
||||
#else
|
||||
#define BUTTON_SENSOR_ENABLE_SHUTDOWN 1
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_GPIO_CFG (IOC_CURRENT_2MA | IOC_STRENGTH_AUTO | \
|
||||
IOC_IOPULL_UP | IOC_SLEW_DISABLE | \
|
||||
IOC_HYST_DISABLE | IOC_BOTH_EDGES | \
|
||||
IOC_INT_ENABLE | IOC_IOMODE_NORMAL | \
|
||||
IOC_NO_WAKE_UP | IOC_INPUT_ENABLE)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBOUNCE_DURATION (CLOCK_SECOND >> 5)
|
||||
|
||||
struct btn_timer {
|
||||
struct timer debounce;
|
||||
clock_time_t start;
|
||||
clock_time_t duration;
|
||||
};
|
||||
|
||||
static struct btn_timer sel_timer, left_timer, right_timer, up_timer,
|
||||
down_timer;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Handler for SmartRF button presses
|
||||
*/
|
||||
static void
|
||||
button_press_handler(gpio_hal_pin_mask_t pin_mask)
|
||||
{
|
||||
if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_SELECT)) {
|
||||
if(!timer_expired(&sel_timer.debounce)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&sel_timer.debounce, DEBOUNCE_DURATION);
|
||||
|
||||
/*
|
||||
* Start press duration counter on press (falling), notify on release
|
||||
* (rising)
|
||||
*/
|
||||
if(ti_lib_gpio_read_dio(BOARD_IOID_KEY_SELECT) == 0) {
|
||||
sel_timer.start = clock_time();
|
||||
sel_timer.duration = 0;
|
||||
} else {
|
||||
sel_timer.duration = clock_time() - sel_timer.start;
|
||||
sensors_changed(&button_select_sensor);
|
||||
}
|
||||
}
|
||||
|
||||
if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_LEFT)) {
|
||||
if(!timer_expired(&left_timer.debounce)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&left_timer.debounce, DEBOUNCE_DURATION);
|
||||
|
||||
/*
|
||||
* Start press duration counter on press (falling), notify on release
|
||||
* (rising)
|
||||
*/
|
||||
if(ti_lib_gpio_read_dio(BOARD_IOID_KEY_LEFT) == 0) {
|
||||
left_timer.start = clock_time();
|
||||
left_timer.duration = 0;
|
||||
} else {
|
||||
left_timer.duration = clock_time() - left_timer.start;
|
||||
sensors_changed(&button_left_sensor);
|
||||
}
|
||||
}
|
||||
|
||||
if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_RIGHT)) {
|
||||
if(BUTTON_SENSOR_ENABLE_SHUTDOWN == 0) {
|
||||
if(!timer_expired(&right_timer.debounce)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&right_timer.debounce, DEBOUNCE_DURATION);
|
||||
|
||||
/*
|
||||
* Start press duration counter on press (falling), notify on release
|
||||
* (rising)
|
||||
*/
|
||||
if(ti_lib_gpio_read_dio(BOARD_IOID_KEY_RIGHT) == 0) {
|
||||
right_timer.start = clock_time();
|
||||
right_timer.duration = 0;
|
||||
} else {
|
||||
right_timer.duration = clock_time() - right_timer.start;
|
||||
sensors_changed(&button_right_sensor);
|
||||
}
|
||||
} else {
|
||||
lpm_shutdown(BOARD_IOID_KEY_RIGHT, IOC_IOPULL_UP, IOC_WAKE_ON_LOW);
|
||||
}
|
||||
}
|
||||
|
||||
if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_UP)) {
|
||||
if(!timer_expired(&up_timer.debounce)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&up_timer.debounce, DEBOUNCE_DURATION);
|
||||
|
||||
/*
|
||||
* Start press duration counter on press (falling), notify on release
|
||||
* (rising)
|
||||
*/
|
||||
if(ti_lib_gpio_read_dio(BOARD_IOID_KEY_UP) == 0) {
|
||||
up_timer.start = clock_time();
|
||||
up_timer.duration = 0;
|
||||
} else {
|
||||
up_timer.duration = clock_time() - up_timer.start;
|
||||
sensors_changed(&button_up_sensor);
|
||||
}
|
||||
}
|
||||
|
||||
if(pin_mask & gpio_hal_pin_to_mask(BOARD_IOID_KEY_DOWN)) {
|
||||
if(!timer_expired(&down_timer.debounce)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&down_timer.debounce, DEBOUNCE_DURATION);
|
||||
|
||||
/*
|
||||
* Start press duration counter on press (falling), notify on release
|
||||
* (rising)
|
||||
*/
|
||||
if(ti_lib_gpio_read_dio(BOARD_IOID_KEY_DOWN) == 0) {
|
||||
down_timer.start = clock_time();
|
||||
down_timer.duration = 0;
|
||||
} else {
|
||||
down_timer.duration = clock_time() - down_timer.start;
|
||||
sensors_changed(&button_down_sensor);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static gpio_hal_event_handler_t press_handler = {
|
||||
.next = NULL,
|
||||
.handler = button_press_handler,
|
||||
.pin_mask = 0,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Configuration function for the button sensor for all buttons.
|
||||
*
|
||||
* \param type This function does nothing unless type == SENSORS_ACTIVE
|
||||
* \param c 0: disable the button, non-zero: enable
|
||||
* \param key: One of BOARD_KEY_LEFT, BOARD_KEY_RIGHT etc
|
||||
*/
|
||||
static void
|
||||
config_buttons(int type, int c, uint32_t key)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
ti_lib_gpio_clear_event_dio(key);
|
||||
ti_lib_rom_ioc_pin_type_gpio_input(key);
|
||||
ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
|
||||
press_handler.pin_mask |= gpio_hal_pin_to_mask(key);
|
||||
gpio_hal_register_handler(&press_handler);
|
||||
break;
|
||||
case SENSORS_ACTIVE:
|
||||
if(c) {
|
||||
ti_lib_gpio_clear_event_dio(key);
|
||||
ti_lib_rom_ioc_pin_type_gpio_input(key);
|
||||
ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG);
|
||||
ti_lib_rom_ioc_int_enable(key);
|
||||
} else {
|
||||
ti_lib_rom_ioc_int_disable(key);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Configuration function for the select button.
|
||||
*
|
||||
* Parameters are passed onto config_buttons, which does the actual
|
||||
* configuration
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor api. The return value is also required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type passed to config_buttons as-is
|
||||
* \param value passed to config_buttons as-is
|
||||
*
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_select(int type, int value)
|
||||
{
|
||||
config_buttons(type, value, BOARD_IOID_KEY_SELECT);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Configuration function for the left button.
|
||||
*
|
||||
* Parameters are passed onto config_buttons, which does the actual
|
||||
* configuration
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor api. The return value is also required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type passed to config_buttons as-is
|
||||
* \param value passed to config_buttons as-is
|
||||
*
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_left(int type, int value)
|
||||
{
|
||||
config_buttons(type, value, BOARD_IOID_KEY_LEFT);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Configuration function for the right button.
|
||||
*
|
||||
* Parameters are passed onto config_buttons, which does the actual
|
||||
* configuration
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor api. The return value is also required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type passed to config_buttons as-is
|
||||
* \param value passed to config_buttons as-is
|
||||
*
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_right(int type, int value)
|
||||
{
|
||||
config_buttons(type, value, BOARD_IOID_KEY_RIGHT);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Configuration function for the up button.
|
||||
*
|
||||
* Parameters are passed onto config_buttons, which does the actual
|
||||
* configuration
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor api. The return value is also required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type passed to config_buttons as-is
|
||||
* \param value passed to config_buttons as-is
|
||||
*
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_up(int type, int value)
|
||||
{
|
||||
config_buttons(type, value, BOARD_IOID_KEY_UP);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Configuration function for the down button.
|
||||
*
|
||||
* Parameters are passed onto config_buttons, which does the actual
|
||||
* configuration
|
||||
* Parameters are ignored. They have been included because the prototype is
|
||||
* dictated by the core sensor api. The return value is also required by
|
||||
* the API but otherwise ignored.
|
||||
*
|
||||
* \param type passed to config_buttons as-is
|
||||
* \param value passed to config_buttons as-is
|
||||
*
|
||||
* \return ignored
|
||||
*/
|
||||
static int
|
||||
config_down(int type, int value)
|
||||
{
|
||||
config_buttons(type, value, BOARD_IOID_KEY_DOWN);
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value_select(int type)
|
||||
{
|
||||
if(type == BUTTON_SENSOR_VALUE_STATE) {
|
||||
return ti_lib_gpio_read_dio(BOARD_IOID_KEY_SELECT) == 0 ?
|
||||
BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
|
||||
} else if(type == BUTTON_SENSOR_VALUE_DURATION) {
|
||||
return (int)sel_timer.duration;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value_left(int type)
|
||||
{
|
||||
if(type == BUTTON_SENSOR_VALUE_STATE) {
|
||||
return ti_lib_gpio_read_dio(BOARD_IOID_KEY_LEFT) == 0 ?
|
||||
BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
|
||||
} else if(type == BUTTON_SENSOR_VALUE_DURATION) {
|
||||
return (int)left_timer.duration;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value_right(int type)
|
||||
{
|
||||
if(type == BUTTON_SENSOR_VALUE_STATE) {
|
||||
return ti_lib_gpio_read_dio(BOARD_IOID_KEY_RIGHT) == 0 ?
|
||||
BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
|
||||
} else if(type == BUTTON_SENSOR_VALUE_DURATION) {
|
||||
return (int)right_timer.duration;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value_up(int type)
|
||||
{
|
||||
if(type == BUTTON_SENSOR_VALUE_STATE) {
|
||||
return ti_lib_gpio_read_dio(BOARD_IOID_KEY_UP) == 0 ?
|
||||
BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
|
||||
} else if(type == BUTTON_SENSOR_VALUE_DURATION) {
|
||||
return (int)up_timer.duration;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value_down(int type)
|
||||
{
|
||||
if(type == BUTTON_SENSOR_VALUE_STATE) {
|
||||
return ti_lib_gpio_read_dio(BOARD_IOID_KEY_DOWN) == 0 ?
|
||||
BUTTON_SENSOR_VALUE_PRESSED : BUTTON_SENSOR_VALUE_RELEASED;
|
||||
} else if(type == BUTTON_SENSOR_VALUE_DURATION) {
|
||||
return (int)down_timer.duration;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Status function for all buttons
|
||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
||||
* \param key_io_id BOARD_IOID_KEY_LEFT, BOARD_IOID_KEY_RIGHT etc
|
||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
||||
*
|
||||
* This function will only be called by status_left, status_right and the
|
||||
* called will pass the correct key_io_id
|
||||
*/
|
||||
static int
|
||||
status(int type, uint32_t key_io_id)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
if(ti_lib_ioc_port_configure_get(key_io_id) & IOC_INT_ENABLE) {
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Status function for the select button.
|
||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
||||
*
|
||||
* This function will call status. It will pass type verbatim and it will also
|
||||
* pass the correct key_io_id
|
||||
*/
|
||||
static int
|
||||
status_select(int type)
|
||||
{
|
||||
return status(type, BOARD_IOID_KEY_SELECT);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Status function for the left button.
|
||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
||||
*
|
||||
* This function will call status. It will pass type verbatim and it will also
|
||||
* pass the correct key_io_id
|
||||
*/
|
||||
static int
|
||||
status_left(int type)
|
||||
{
|
||||
return status(type, BOARD_IOID_KEY_LEFT);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Status function for the right button.
|
||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
||||
*
|
||||
* This function will call status. It will pass type verbatim and it will also
|
||||
* pass the correct key_io_id
|
||||
*/
|
||||
static int
|
||||
status_right(int type)
|
||||
{
|
||||
return status(type, BOARD_IOID_KEY_RIGHT);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Status function for the up button.
|
||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
||||
*
|
||||
* This function will call status. It will pass type verbatim and it will also
|
||||
* pass the correct key_io_id
|
||||
*/
|
||||
static int
|
||||
status_up(int type)
|
||||
{
|
||||
return status(type, BOARD_IOID_KEY_UP);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Status function for the down button.
|
||||
* \param type SENSORS_ACTIVE or SENSORS_READY
|
||||
* \return 1 if the button's port interrupt is enabled (edge detect)
|
||||
*
|
||||
* This function will call status. It will pass type verbatim and it will also
|
||||
* pass the correct key_io_id
|
||||
*/
|
||||
static int
|
||||
status_down(int type)
|
||||
{
|
||||
return status(type, BOARD_IOID_KEY_DOWN);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_select_sensor, BUTTON_SENSOR, value_select,
|
||||
config_select, status_select);
|
||||
SENSORS_SENSOR(button_left_sensor, BUTTON_SENSOR, value_left, config_left,
|
||||
status_left);
|
||||
SENSORS_SENSOR(button_right_sensor, BUTTON_SENSOR, value_right, config_right,
|
||||
status_right);
|
||||
SENSORS_SENSOR(button_up_sensor, BUTTON_SENSOR, value_up, config_up, status_up);
|
||||
SENSORS_SENSOR(button_down_sensor, BUTTON_SENSOR, value_down, config_down,
|
||||
status_down);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -232,6 +232,19 @@
|
|||
#endif
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Board indices for the button HAL
|
||||
*
|
||||
* Those values are not meant to be modified by the user
|
||||
* @{
|
||||
*/
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_LEFT 0x00
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_RIGHT 0x01
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_UP 0x02
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_DOWN 0x03
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_SELECT 0x04
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Device string used on startup
|
||||
* @{
|
||||
|
|
|
@ -232,6 +232,19 @@
|
|||
#endif
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Board indices for the button HAL
|
||||
*
|
||||
* Those values are not meant to be modified by the user
|
||||
* @{
|
||||
*/
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_LEFT 0x00
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_RIGHT 0x01
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_UP 0x02
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_DOWN 0x03
|
||||
#define BOARD_BUTTON_HAL_INDEX_KEY_SELECT 0x04
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Device string used on startup
|
||||
* @{
|
||||
|
|
|
@ -38,13 +38,11 @@
|
|||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "srf06/button-sensor.h"
|
||||
#include "srf06/als-sensor.h"
|
||||
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \brief Exports a global symbol to be used by the sensor API */
|
||||
SENSORS(&button_select_sensor, &button_left_sensor, &button_right_sensor,
|
||||
&button_up_sensor, &button_down_sensor, &als_sensor);
|
||||
SENSORS(&als_sensor);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
||||
|
|
|
@ -33,7 +33,7 @@ PLATFORM_ROOT_DIR = $(CONTIKI)/arch/platform/$(TARGET)
|
|||
### Include
|
||||
CONTIKI_TARGET_SOURCEFILES += platform.c leds-arch.c
|
||||
CONTIKI_TARGET_SOURCEFILES += leds.c cc1200-zoul-arch.c
|
||||
CONTIKI_TARGET_SOURCEFILES += adc-zoul.c button-sensor.c zoul-sensors.c
|
||||
CONTIKI_TARGET_SOURCEFILES += adc-zoul.c board-buttons.c zoul-sensors.c
|
||||
CONTIKI_TARGET_SOURCEFILES += $(BOARD_SOURCEFILES)
|
||||
|
||||
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
|
@ -29,29 +30,30 @@
|
|||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup sensortag-cc26xx-peripherals
|
||||
* \addtogroup zoul
|
||||
* @{
|
||||
*
|
||||
* \defgroup sensortag-cc26xx-reed-relay SensorTag 2.0 Reed Relay
|
||||
*
|
||||
* The reed relay acts like a button without a button. To trigger the reed,
|
||||
* approach a magnet to the sensortag and a sensors_changed event will be
|
||||
* generated, in a fashion similar to as if a button had been pressed
|
||||
* \defgroup zoul-buttons Zoul user button
|
||||
*
|
||||
* Generic module controlling the user button on the Zoul
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the Sensortag Reed Relay
|
||||
* Defines the Zoul user button for use with the button HAL
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef REED_RELAY_H
|
||||
#define REED_RELAY_H
|
||||
#include "contiki.h"
|
||||
#include "dev/button-hal.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#if PLATFORM_HAS_BUTTON
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor reed_relay_sensor;
|
||||
BUTTON_HAL_BUTTON(button_user, "User button", \
|
||||
GPIO_PORT_PIN_TO_GPIO_HAL_PIN(BUTTON_USER_PORT, BUTTON_USER_PIN), \
|
||||
GPIO_HAL_PIN_CFG_PULL_UP, BUTTON_HAL_ID_USER_BUTTON, true);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* REED_RELAY_H */
|
||||
BUTTON_HAL_BUTTONS(&button_user);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
|
@ -1,178 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
|
||||
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup zoul-button-sensor
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Driver for the Zoul user button
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/nvic.h"
|
||||
#include "dev/ioc.h"
|
||||
#include "dev/gpio.h"
|
||||
#include "dev/gpio-hal.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "sys/timer.h"
|
||||
#include "sys/ctimer.h"
|
||||
#include "sys/process.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_USER_PORT_BASE GPIO_PORT_TO_BASE(BUTTON_USER_PORT)
|
||||
#define BUTTON_USER_PIN_MASK GPIO_PIN_MASK(BUTTON_USER_PIN)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBOUNCE_DURATION (CLOCK_SECOND >> 4)
|
||||
|
||||
static struct timer debouncetimer;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static clock_time_t press_duration = 0;
|
||||
static struct ctimer press_counter;
|
||||
static uint8_t press_event_counter;
|
||||
|
||||
process_event_t button_press_duration_exceeded;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
duration_exceeded_callback(void *data)
|
||||
{
|
||||
press_event_counter++;
|
||||
process_post(PROCESS_BROADCAST, button_press_duration_exceeded,
|
||||
&press_event_counter);
|
||||
ctimer_set(&press_counter, press_duration, duration_exceeded_callback,
|
||||
NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Retrieves the value of the button pin
|
||||
* \param type Returns the pin level or the counter of press duration events.
|
||||
* type == BUTTON_SENSOR_VALUE_TYPE_LEVEL or
|
||||
* type == BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION
|
||||
* respectively
|
||||
*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case BUTTON_SENSOR_VALUE_TYPE_LEVEL:
|
||||
return GPIO_READ_PIN(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
case BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION:
|
||||
return press_event_counter;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
button_press_handler(gpio_hal_pin_mask_t pin_mask)
|
||||
{
|
||||
if(!timer_expired(&debouncetimer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
timer_set(&debouncetimer, DEBOUNCE_DURATION);
|
||||
|
||||
if(press_duration) {
|
||||
press_event_counter = 0;
|
||||
if(value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) == BUTTON_SENSOR_PRESSED_LEVEL) {
|
||||
ctimer_set(&press_counter, press_duration, duration_exceeded_callback,
|
||||
NULL);
|
||||
} else {
|
||||
ctimer_stop(&press_counter);
|
||||
}
|
||||
}
|
||||
|
||||
sensors_changed(&button_sensor);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static gpio_hal_event_handler_t press_handler = {
|
||||
.next = NULL,
|
||||
.handler = button_press_handler,
|
||||
.pin_mask = gpio_hal_pin_to_mask(BUTTON_USER_PIN) << (BUTTON_USER_PORT << 3),
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Init function for the User button.
|
||||
* \param type SENSORS_ACTIVE: Activate / Deactivate the sensor (value == 1
|
||||
* or 0 respectively)
|
||||
*
|
||||
* \param value Depends on the value of the type argument
|
||||
* \return Depends on the value of the type argument
|
||||
*/
|
||||
static int
|
||||
config_user(int type, int value)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_HW_INIT:
|
||||
button_press_duration_exceeded = process_alloc_event();
|
||||
|
||||
/* Software controlled */
|
||||
GPIO_SOFTWARE_CONTROL(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
|
||||
/* Set pin to input */
|
||||
GPIO_SET_INPUT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
|
||||
/* Enable edge detection */
|
||||
GPIO_DETECT_EDGE(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
|
||||
/* Both Edges */
|
||||
GPIO_TRIGGER_BOTH_EDGES(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
|
||||
ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE);
|
||||
|
||||
gpio_hal_register_handler(&press_handler);
|
||||
break;
|
||||
case SENSORS_ACTIVE:
|
||||
if(value) {
|
||||
GPIO_ENABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
NVIC_EnableIRQ(BUTTON_USER_VECTOR);
|
||||
} else {
|
||||
GPIO_DISABLE_INTERRUPT(BUTTON_USER_PORT_BASE, BUTTON_USER_PIN_MASK);
|
||||
NVIC_DisableIRQ(BUTTON_USER_VECTOR);
|
||||
}
|
||||
return value;
|
||||
case BUTTON_SENSOR_CONFIG_TYPE_INTERVAL:
|
||||
press_duration = (clock_time_t)value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, value, config_user, NULL);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2015, Zolertia - http://www.zolertia.com
|
||||
* Copyright (c) 2015, University of Bristol - http://www.bristol.ac.uk
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup zoul-sensors
|
||||
* @{
|
||||
*
|
||||
* \defgroup zoul-button-sensor Zoul User Button Driver
|
||||
*
|
||||
* Driver for the Zoul user button
|
||||
*
|
||||
* The user button (on Zoul-based platforms like the RE-Mote and the Firefly)
|
||||
* will generate a sensors_changed event on press as well as on release.
|
||||
*
|
||||
* Unlike many other platforms, the user button has the ability to
|
||||
* generate events when the user keeps the button pressed. The user can
|
||||
* configure the button driver with a timer interval in clock ticks. When the
|
||||
* button is kept pressed, the driver will then generate a broadcast event
|
||||
* each time the interval passes. For example the driver can be configured to
|
||||
* generate an event every second while the button is kept pressed. This
|
||||
* functionality can be enabled through the configure() function, by passing
|
||||
* BUTTON_SENSOR_CONFIG_TYPE_INTERVAL as the type argument.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the Zoul User Button Driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef BUTTON_SENSOR_H_
|
||||
#define BUTTON_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR "Button"
|
||||
|
||||
extern const struct sensors_sensor button_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern process_event_t button_press_duration_exceeded;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR_CONFIG_TYPE_INTERVAL 0x0100
|
||||
|
||||
#define BUTTON_SENSOR_VALUE_TYPE_LEVEL 0
|
||||
#define BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION 1
|
||||
|
||||
#define BUTTON_SENSOR_PRESSED_LEVEL 0
|
||||
#define BUTTON_SENSOR_RELEASED_LEVEL 8
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BUTTON_SENSOR_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
|
@ -47,12 +47,7 @@
|
|||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \brief Exports global symbols for the sensor API */
|
||||
SENSORS(&vdd3_sensor,
|
||||
#if PLATFORM_HAS_BUTTON
|
||||
&button_sensor,
|
||||
#endif
|
||||
&cc2538_temp_sensor
|
||||
);
|
||||
SENSORS(&vdd3_sensor, &cc2538_temp_sensor);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
|
|
|
@ -48,7 +48,6 @@
|
|||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/cc2538-sensors.h"
|
||||
#include "dev/button-sensor.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Zoul sensor constants
|
||||
|
|
|
@ -54,8 +54,10 @@
|
|||
#include "dev/udma.h"
|
||||
#include "dev/crypto.h"
|
||||
#include "dev/rtcc.h"
|
||||
#include "dev/button-hal.h"
|
||||
#include "usb/usb-serial.h"
|
||||
#include "lib/random.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "net/netstack.h"
|
||||
#include "net/mac/framer/frame802154.h"
|
||||
#include "net/linkaddr.h"
|
||||
|
@ -221,6 +223,10 @@ platform_init_stage_two()
|
|||
/* Populate linkaddr_node_addr */
|
||||
ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE);
|
||||
|
||||
#if PLATFORM_HAS_BUTTON
|
||||
button_hal_init();
|
||||
#endif
|
||||
|
||||
INTERRUPTS_ENABLE();
|
||||
|
||||
fade(LEDS_BLUE);
|
||||
|
@ -241,10 +247,6 @@ platform_init_stage_three()
|
|||
|
||||
process_start(&sensors_process, NULL);
|
||||
|
||||
#if PLATFORM_HAS_BUTTON
|
||||
SENSORS_ACTIVATE(button_sensor);
|
||||
#endif
|
||||
|
||||
fade(LEDS_GREEN);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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. */
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
CONTIKI_PROJECT = button-hal-example
|
||||
CONTIKI = ../../..
|
||||
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
|
@ -0,0 +1,15 @@
|
|||
# Button HAL Example
|
||||
This example demonstrates and tests the functionality of the Button HAL.
|
||||
You can use this example to:
|
||||
|
||||
* Understand the logic of the button HAL.
|
||||
* Test your implementation of arch-specific button HAL components if you are
|
||||
developing a new port.
|
||||
|
||||
This example assumes a device with at least one switch (button or simiar).
|
||||
|
||||
# Supported devices
|
||||
This example is expected to work off-the-shelf on the following boards:
|
||||
|
||||
* All CC13xx/CC26xx devices
|
||||
* All CC2538 devices
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2018, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/button-hal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(button_hal_example, "Button HAL Example");
|
||||
AUTOSTART_PROCESSES(&button_hal_example);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(button_hal_example, ev, data)
|
||||
{
|
||||
button_hal_button_t *btn;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
btn = button_hal_get_by_index(0);
|
||||
|
||||
printf("Button HAL example.\n");
|
||||
printf("Device button count: %u.\n", button_hal_button_count);
|
||||
printf("%s on pin %u with ID=0, Logic=%s, Pull=%s\n",
|
||||
BUTTON_HAL_GET_DESCRIPTION(btn), btn->pin,
|
||||
btn->negative_logic ? "Negative" : "Positive",
|
||||
btn->pull == GPIO_HAL_PIN_CFG_PULL_UP ? "Pull Up" : "Pull Down");
|
||||
|
||||
while(1) {
|
||||
|
||||
PROCESS_YIELD();
|
||||
|
||||
if(ev == button_hal_press_event) {
|
||||
btn = (button_hal_button_t *)data;
|
||||
printf("Press event (%s)\n", BUTTON_HAL_GET_DESCRIPTION(btn));
|
||||
|
||||
if(btn == button_hal_get_by_id(BUTTON_HAL_ID_BUTTON_ZERO)) {
|
||||
printf("This was button 0, on pin %u\n", btn->pin);
|
||||
}
|
||||
} else if(ev == button_hal_release_event) {
|
||||
btn = (button_hal_button_t *)data;
|
||||
printf("Release event (%s)\n", BUTTON_HAL_GET_DESCRIPTION(btn));
|
||||
} else if(ev == button_hal_periodic_event) {
|
||||
btn = (button_hal_button_t *)data;
|
||||
printf("Periodic event, %u seconds (%s)\n", btn->press_duration_seconds,
|
||||
BUTTON_HAL_GET_DESCRIPTION(btn));
|
||||
|
||||
if(btn->press_duration_seconds > 5) {
|
||||
printf("%s pressed for more than 5 secs. Do custom action\n",
|
||||
BUTTON_HAL_GET_DESCRIPTION(btn));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2018, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef PROJECT_CONF_H_
|
||||
#define PROJECT_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Force button descriptions */
|
||||
#define BUTTON_HAL_CONF_WITH_DESCRIPTION 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* PROJECT_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -33,7 +33,7 @@
|
|||
#include "dev/gpio-hal.h"
|
||||
#include "sys/etimer.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/button-hal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -129,8 +129,9 @@ PROCESS_THREAD(gpio_hal_example, ev, data)
|
|||
|
||||
counter++;
|
||||
etimer_set(&et, CLOCK_SECOND);
|
||||
} else if(ev == sensors_event && data == &button_sensor) {
|
||||
printf("Button event\n");
|
||||
} else if(ev == button_hal_release_event) {
|
||||
printf("Button release event %s\n",
|
||||
BUTTON_HAL_GET_DESCRIPTION((button_hal_button_t *)data));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
CONTIKI_PROJECT = mqtt-client
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
MODULES += os/net/app-layer/mqtt
|
||||
|
||||
CONTIKI = ../..
|
||||
-include $(CONTIKI)/Makefile.identify-target
|
||||
|
||||
MODULES_REL += arch/platform/$(TARGET)
|
||||
|
||||
PLATFORMS_ONLY = srf06-cc26xx cc2538dk openmote-cc2538 zoul
|
||||
|
||||
include $(CONTIKI)/Makefile.include
|
|
@ -1,15 +1,18 @@
|
|||
MQTT Demo
|
||||
=========
|
||||
MQTT Client Example
|
||||
===================
|
||||
The MQTT client can be used to:
|
||||
|
||||
* Publish sensor readings to an MQTT broker.
|
||||
* Subscribe to a topic and receive commands from an MQTT broker
|
||||
|
||||
The demo will give some visual feedback with the green LED:
|
||||
The demo will give some visual feedback with a LED (configurable):
|
||||
* Very fast blinking: Searching for a network
|
||||
* Fast blinking: Connecting to broker
|
||||
* Slow, long blinking: Sending a publish message
|
||||
|
||||
This example is known to work with all platforms that support the new button
|
||||
API.
|
||||
|
||||
Publishing
|
||||
----------
|
||||
By default the example will attempt to publish readings to an MQTT broker
|
||||
|
@ -20,7 +23,7 @@ running on the IPv6 address specified as `MQTT_DEMO_BROKER_IP_ADDR` in
|
|||
The publish messages include sensor readings but also some other information,
|
||||
such as device uptime in seconds and a message sequence number. The demo will
|
||||
publish to topic `iot-2/evt/status/fmt/json`. The device will connect using
|
||||
client-id `d:quickstart:cc2538:<device-id>`, where `<device-id>` gets
|
||||
client-id `d:contiki-ng:mqtt-client:<device-id>`, where `<device-id>` gets
|
||||
constructed from the device's IEEE address.
|
||||
|
||||
Subscribing
|
|
@ -1,10 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
|
@ -28,33 +29,54 @@
|
|||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup srf06-common-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the SmartRF06EB + CC13xx/CC26xxEM Button Driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef BUTTON_SENSOR_H_
|
||||
#define BUTTON_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR "Button"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR_VALUE_STATE 0
|
||||
#define BUTTON_SENSOR_VALUE_DURATION 1
|
||||
#include "contiki.h"
|
||||
#include "dev/cc2538-sensors.h"
|
||||
#include "mqtt-client.h"
|
||||
|
||||
#define BUTTON_SENSOR_VALUE_RELEASED 0
|
||||
#define BUTTON_SENSOR_VALUE_PRESSED 1
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor button_select_sensor;
|
||||
extern const struct sensors_sensor button_left_sensor;
|
||||
extern const struct sensors_sensor button_right_sensor;
|
||||
extern const struct sensors_sensor button_up_sensor;
|
||||
extern const struct sensors_sensor button_down_sensor;
|
||||
#define TMP_BUF_SZ 32
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BUTTON_SENSOR_H_ */
|
||||
char tmp_buf[TMP_BUF_SZ];
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static char *
|
||||
temp_reading(void)
|
||||
{
|
||||
memset(tmp_buf, 0, TMP_BUF_SZ);
|
||||
snprintf(tmp_buf, TMP_BUF_SZ, "\"On-Chip Temp (mC)\":%d",
|
||||
cc2538_temp_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
||||
return tmp_buf;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
temp_init(void)
|
||||
{
|
||||
SENSORS_ACTIVATE(cc2538_temp_sensor);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const mqtt_client_extension_t builtin_sensors_cc2538_temp = {
|
||||
temp_init,
|
||||
temp_reading,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static char *
|
||||
vdd3_reading(void)
|
||||
{
|
||||
memset(tmp_buf, 0, TMP_BUF_SZ);
|
||||
snprintf(tmp_buf, TMP_BUF_SZ, "\"VDD3 (mV)\":%d",
|
||||
vdd3_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
||||
return tmp_buf;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
vdd3_init(void)
|
||||
{
|
||||
SENSORS_ACTIVATE(vdd3_sensor);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const mqtt_client_extension_t builtin_sensors_vdd3 = {
|
||||
vdd3_init,
|
||||
vdd3_reading,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef BUILTIN_SENSORS_H_
|
||||
#define BUILTIN_SENSORS_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "mqtt-client.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const mqtt_client_extension_t builtin_sensors_vdd3;
|
||||
extern const mqtt_client_extension_t builtin_sensors_cc2538_temp;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BUILTIN_SENSORS_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,16 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
|
@ -27,48 +27,56 @@
|
|||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup openmote-cc2538
|
||||
* @{
|
||||
*
|
||||
* \defgroup openmote-button-sensor OpenMote-CC2538 user button driver
|
||||
*
|
||||
* The user button will generate a sensors_changed event on press as
|
||||
* well as on release.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header for the OpenMote-CC2538 button driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef BUTTON_SENSOR_H_
|
||||
#define BUTTON_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR "Button"
|
||||
#include "contiki.h"
|
||||
#include "batmon-sensor.h"
|
||||
#include "mqtt-client.h"
|
||||
|
||||
extern const struct sensors_sensor button_sensor;
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern process_event_t button_press_duration_exceeded;
|
||||
#define TMP_BUF_SZ 32
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR_CONFIG_TYPE_INTERVAL 0x0100
|
||||
|
||||
#define BUTTON_SENSOR_VALUE_TYPE_LEVEL 0
|
||||
#define BUTTON_SENSOR_VALUE_TYPE_PRESS_DURATION 1
|
||||
|
||||
#define BUTTON_SENSOR_PRESSED_LEVEL 0
|
||||
#define BUTTON_SENSOR_RELEASED_LEVEL 8
|
||||
char tmp_buf[TMP_BUF_SZ];
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BUTTON_SENSOR_H_ */
|
||||
static char *
|
||||
temp_reading(void)
|
||||
{
|
||||
memset(tmp_buf, 0, TMP_BUF_SZ);
|
||||
snprintf(tmp_buf, TMP_BUF_SZ, "\"On-Chip Temp (mC)\":%d",
|
||||
batmon_sensor.value(BATMON_SENSOR_TYPE_TEMP));
|
||||
return tmp_buf;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
temp_init(void)
|
||||
{
|
||||
SENSORS_ACTIVATE(batmon_sensor);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const mqtt_client_extension_t builtin_sensors_batmon_temp = {
|
||||
temp_init,
|
||||
temp_reading,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static char *
|
||||
volt_reading(void)
|
||||
{
|
||||
memset(tmp_buf, 0, TMP_BUF_SZ);
|
||||
snprintf(tmp_buf, TMP_BUF_SZ, "\"Volt (mV)\":%d",
|
||||
(batmon_sensor.value(BATMON_SENSOR_TYPE_VOLT) * 125) >> 5);
|
||||
return tmp_buf;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
volt_init(void)
|
||||
{
|
||||
SENSORS_ACTIVATE(batmon_sensor);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const mqtt_client_extension_t builtin_sensors_batmon_volt = {
|
||||
volt_init,
|
||||
volt_reading,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef BUILTIN_SENSORS_H_
|
||||
#define BUILTIN_SENSORS_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "mqtt-client.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const mqtt_client_extension_t builtin_sensors_batmon_temp;
|
||||
extern const mqtt_client_extension_t builtin_sensors_batmon_volt;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BUILTIN_SENSORS_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1 @@
|
|||
MODULES_REL += arch/cpu/cc2538
|
|
@ -1,10 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2018, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
|
@ -28,38 +29,33 @@
|
|||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \defgroup launchpad-button-sensor LaunchPad Button Driver
|
||||
*
|
||||
* One of the buttons can be configured as general purpose or as an on/off key
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the LaunchPad Button Driver
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef BUTTON_SENSOR_H_
|
||||
#define BUTTON_SENSOR_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR "Button"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_SENSOR_VALUE_STATE 0
|
||||
#define BUTTON_SENSOR_VALUE_DURATION 1
|
||||
#include "contiki.h"
|
||||
#include "als-extend.h"
|
||||
#include "dev/als-sensor.h"
|
||||
|
||||
#define BUTTON_SENSOR_VALUE_RELEASED 0
|
||||
#define BUTTON_SENSOR_VALUE_PRESSED 1
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern const struct sensors_sensor button_left_sensor;
|
||||
extern const struct sensors_sensor button_right_sensor;
|
||||
#define TMP_BUF_SZ 32
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BUTTON_SENSOR_H_ */
|
||||
char tmp_buf[TMP_BUF_SZ];
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
als_init(void)
|
||||
{
|
||||
SENSORS_ACTIVATE(als_sensor);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static char *
|
||||
als_reading(void)
|
||||
{
|
||||
memset(tmp_buf, 0, TMP_BUF_SZ);
|
||||
snprintf(tmp_buf, TMP_BUF_SZ, "\"ALS (raw)\":%d", als_sensor.value(0));
|
||||
return tmp_buf;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
const mqtt_client_extension_t als_extend = {
|
||||
als_init,
|
||||
als_reading,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
|
@ -1,10 +1,11 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2018, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
|
@ -28,20 +29,13 @@
|
|||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Generic module controlling LaunchPad sensors
|
||||
*/
|
||||
#ifndef ALS_EXTEND_H_
|
||||
#define ALS_EXTEND_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "launchpad/button-sensor.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "mqtt-client.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \brief Exports a global symbol to be used by the sensor API */
|
||||
SENSORS(&button_left_sensor, &button_right_sensor);
|
||||
extern const mqtt_client_extension_t als_extend;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* ALS_EXTEND_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -1,16 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
|
@ -28,39 +28,14 @@
|
|||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup cc2538-smartrf-sensors
|
||||
* @{
|
||||
*
|
||||
* \defgroup cc2538dk-button-sensor cc2538dk Button Driver
|
||||
*
|
||||
* Driver for the SmartRF06EB buttons
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the cc2538dk Button Driver
|
||||
*/
|
||||
#ifndef BUTTON_SENSOR_H_
|
||||
#define BUTTON_SENSOR_H_
|
||||
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/gpio.h"
|
||||
|
||||
#define BUTTON_SENSOR "Button"
|
||||
|
||||
#define button_sensor button_select_sensor
|
||||
extern const struct sensors_sensor button_select_sensor;
|
||||
extern const struct sensors_sensor button_left_sensor;
|
||||
extern const struct sensors_sensor button_right_sensor;
|
||||
extern const struct sensors_sensor button_up_sensor;
|
||||
extern const struct sensors_sensor button_down_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BUTTON_SENSOR_H_ */
|
||||
#include "contiki.h"
|
||||
#include "builtin-sensors.h"
|
||||
#include "als-extend.h"
|
||||
#include "mqtt-client.h"
|
||||
|
||||
/** \brief Common initialiser for all SmartRF Buttons */
|
||||
void button_sensor_init();
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
MQTT_CLIENT_EXTENSIONS(&builtin_sensors_vdd3, &builtin_sensors_cc2538_temp,
|
||||
&als_extend);
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1 @@
|
|||
MODULES_REL += arch/cpu/cc2538
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "builtin-sensors.h"
|
||||
#include "mqtt-client.h"
|
||||
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
MQTT_CLIENT_EXTENSIONS(&builtin_sensors_vdd3, &builtin_sensors_cc2538_temp);
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1 @@
|
|||
MODULES_REL += arch/cpu/cc26xx-cc13xx
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "builtin-sensors.h"
|
||||
#include "mqtt-client.h"
|
||||
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
MQTT_CLIENT_EXTENSIONS(&builtin_sensors_batmon_temp,
|
||||
&builtin_sensors_batmon_volt);
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1 @@
|
|||
MODULES_REL += arch/cpu/cc2538
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "builtin-sensors.h"
|
||||
#include "mqtt-client.h"
|
||||
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
MQTT_CLIENT_EXTENSIONS(&builtin_sensors_vdd3, &builtin_sensors_cc2538_temp);
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -28,19 +29,6 @@
|
|||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** \addtogroup cc2538-examples
|
||||
* @{
|
||||
*
|
||||
* \defgroup cc2538-mqtt-demo CC2538 MQTT Demo Project
|
||||
*
|
||||
* Demonstrates MQTT functionality. Works with IBM Quickstart as well as
|
||||
* mosquitto.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* An MQTT example for the cc2538-based platforms
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "net/routing/routing.h"
|
||||
#include "mqtt.h"
|
||||
|
@ -50,13 +38,17 @@
|
|||
#include "sys/etimer.h"
|
||||
#include "sys/ctimer.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/button-hal.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/cc2538-sensors.h"
|
||||
#include "os/sys/log.h"
|
||||
#include "mqtt-client.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define LOG_MODULE "mqtt-client"
|
||||
#define LOG_LEVEL LOG_LEVEL_NONE
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* IBM server: messaging.quickstart.internetofthings.ibmcloud.com
|
||||
* (184.172.124.189) mapped in an NAT64 (prefix 64:ff9b::/96) IPv6 address
|
||||
|
@ -65,14 +57,20 @@
|
|||
* Alternatively, publish to a local MQTT broker (e.g. mosquitto) running on
|
||||
* the node that hosts your border router
|
||||
*/
|
||||
#ifdef MQTT_DEMO_BROKER_IP_ADDR
|
||||
static const char *broker_ip = MQTT_DEMO_BROKER_IP_ADDR;
|
||||
#define DEFAULT_ORG_ID "mqtt-demo"
|
||||
#ifdef MQTT_CLIENT_CONF_BROKER_IP_ADDR
|
||||
static const char *broker_ip = MQTT_CLIENT_CONF_BROKER_IP_ADDR;
|
||||
#define DEFAULT_ORG_ID "contiki-ng"
|
||||
#else
|
||||
static const char *broker_ip = "0064:ff9b:0000:0000:0000:0000:b8ac:7cbd";
|
||||
#define DEFAULT_ORG_ID "quickstart"
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifdef MQTT_CLIENT_CONF_STATUS_LED
|
||||
#define MQTT_CLIENT_STATUS_LED MQTT_CLIENT_CONF_STATUS_LED
|
||||
#else
|
||||
#define MQTT_CLIENT_STATUS_LED LEDS_GREEN
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* A timeout used when waiting for something to happen (e.g. to connect or to
|
||||
* disconnect)
|
||||
|
@ -128,7 +126,7 @@ static uint8_t state;
|
|||
#define NO_NET_LED_DURATION (NET_CONNECT_PERIODIC >> 1)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Default configuration values */
|
||||
#define DEFAULT_TYPE_ID "cc2538"
|
||||
#define DEFAULT_TYPE_ID "mqtt-client"
|
||||
#define DEFAULT_AUTH_TOKEN "AUTHZ"
|
||||
#define DEFAULT_EVENT_TYPE_ID "status"
|
||||
#define DEFAULT_SUBSCRIBE_CMD_TYPE "+"
|
||||
|
@ -137,14 +135,13 @@ static uint8_t state;
|
|||
#define DEFAULT_KEEP_ALIVE_TIMER 60
|
||||
#define DEFAULT_RSSI_MEAS_INTERVAL (CLOCK_SECOND * 30)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Take a sensor reading on button press */
|
||||
#define PUBLISH_TRIGGER &button_sensor
|
||||
|
||||
#define MQTT_CLIENT_SENSOR_NONE (void *)0xFFFFFFFF
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Payload length of ICMPv6 echo requests used to measure RSSI with def rt */
|
||||
#define ECHO_REQ_PAYLOAD_LEN 20
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_NAME(mqtt_demo_process);
|
||||
AUTOSTART_PROCESSES(&mqtt_demo_process);
|
||||
PROCESS_NAME(mqtt_client_process);
|
||||
AUTOSTART_PROCESSES(&mqtt_client_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Data structure declaration for the MQTT client configuration
|
||||
|
@ -164,8 +161,6 @@ typedef struct mqtt_client_config {
|
|||
/* Maximum TCP segment size for outgoing segments of our socket */
|
||||
#define MAX_TCP_SEGMENT_SIZE 32
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define STATUS_LED LEDS_GREEN
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* Buffers for Client ID and Topic.
|
||||
* Make sure they are large enough to hold the entire respective string
|
||||
|
@ -202,9 +197,12 @@ static int def_rt_rssi = 0;
|
|||
/*---------------------------------------------------------------------------*/
|
||||
static mqtt_client_config_t conf;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(mqtt_demo_process, "MQTT Demo");
|
||||
extern const mqtt_client_extension_t *mqtt_client_extensions[];
|
||||
extern const uint8_t mqtt_client_extension_count;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
PROCESS(mqtt_client_process, "MQTT Client");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
ipaddr_sprintf(char *buf, uint8_t buf_len, const uip_ipaddr_t *addr)
|
||||
{
|
||||
uint16_t a;
|
||||
|
@ -241,25 +239,25 @@ echo_reply_handler(uip_ipaddr_t *source, uint8_t ttl, uint8_t *data,
|
|||
static void
|
||||
publish_led_off(void *d)
|
||||
{
|
||||
leds_off(STATUS_LED);
|
||||
leds_off(MQTT_CLIENT_STATUS_LED);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
pub_handler(const char *topic, uint16_t topic_len, const uint8_t *chunk,
|
||||
uint16_t chunk_len)
|
||||
{
|
||||
DBG("Pub Handler: topic='%s' (len=%u), chunk_len=%u\n", topic, topic_len,
|
||||
chunk_len);
|
||||
LOG_DBG("Pub Handler: topic='%s' (len=%u), chunk_len=%u\n", topic,
|
||||
topic_len, chunk_len);
|
||||
|
||||
/* If we don't like the length, ignore */
|
||||
if(topic_len != 23 || chunk_len != 1) {
|
||||
printf("Incorrect topic or chunk len. Ignored\n");
|
||||
LOG_ERR("Incorrect topic or chunk len. Ignored\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* If the format != json, ignore */
|
||||
if(strncmp(&topic[topic_len - 4], "json", 4) != 0) {
|
||||
printf("Incorrect format\n");
|
||||
LOG_ERR("Incorrect format\n");
|
||||
}
|
||||
|
||||
if(strncmp(&topic[10], "leds", 4) == 0) {
|
||||
|
@ -277,16 +275,16 @@ mqtt_event(struct mqtt_connection *m, mqtt_event_t event, void *data)
|
|||
{
|
||||
switch(event) {
|
||||
case MQTT_EVENT_CONNECTED: {
|
||||
DBG("APP - Application has a MQTT connection\n");
|
||||
LOG_DBG("Application has a MQTT connection\n");
|
||||
timer_set(&connection_life, CONNECTION_STABLE_TIME);
|
||||
state = STATE_CONNECTED;
|
||||
break;
|
||||
}
|
||||
case MQTT_EVENT_DISCONNECTED: {
|
||||
DBG("APP - MQTT Disconnect. Reason %u\n", *((mqtt_event_t *)data));
|
||||
LOG_DBG("MQTT Disconnect. Reason %u\n", *((mqtt_event_t *)data));
|
||||
|
||||
state = STATE_DISCONNECTED;
|
||||
process_poll(&mqtt_demo_process);
|
||||
process_poll(&mqtt_client_process);
|
||||
break;
|
||||
}
|
||||
case MQTT_EVENT_PUBLISH: {
|
||||
|
@ -295,29 +293,28 @@ mqtt_event(struct mqtt_connection *m, mqtt_event_t event, void *data)
|
|||
/* Implement first_flag in publish message? */
|
||||
if(msg_ptr->first_chunk) {
|
||||
msg_ptr->first_chunk = 0;
|
||||
DBG("APP - Application received a publish on topic '%s'. Payload "
|
||||
"size is %i bytes. Content:\n\n",
|
||||
msg_ptr->topic, msg_ptr->payload_length);
|
||||
LOG_DBG("Application received publish for topic '%s'. Payload "
|
||||
"size is %i bytes.\n", msg_ptr->topic, msg_ptr->payload_length);
|
||||
}
|
||||
|
||||
pub_handler(msg_ptr->topic, strlen(msg_ptr->topic), msg_ptr->payload_chunk,
|
||||
msg_ptr->payload_length);
|
||||
pub_handler(msg_ptr->topic, strlen(msg_ptr->topic),
|
||||
msg_ptr->payload_chunk, msg_ptr->payload_length);
|
||||
break;
|
||||
}
|
||||
case MQTT_EVENT_SUBACK: {
|
||||
DBG("APP - Application is subscribed to topic successfully\n");
|
||||
LOG_DBG("Application is subscribed to topic successfully\n");
|
||||
break;
|
||||
}
|
||||
case MQTT_EVENT_UNSUBACK: {
|
||||
DBG("APP - Application is unsubscribed to topic successfully\n");
|
||||
LOG_DBG("Application is unsubscribed to topic successfully\n");
|
||||
break;
|
||||
}
|
||||
case MQTT_EVENT_PUBACK: {
|
||||
DBG("APP - Publishing complete.\n");
|
||||
LOG_DBG("Publishing complete.\n");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
DBG("APP - Application got a unhandled MQTT event: %i\n", event);
|
||||
LOG_DBG("Application got a unhandled MQTT event: %i\n", event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +327,7 @@ construct_pub_topic(void)
|
|||
|
||||
/* len < 0: Error. Len >= BUFFER_SIZE: Buffer too small */
|
||||
if(len < 0 || len >= BUFFER_SIZE) {
|
||||
printf("Pub Topic: %d, Buffer %d\n", len, BUFFER_SIZE);
|
||||
LOG_INFO("Pub Topic: %d, Buffer %d\n", len, BUFFER_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -345,7 +342,7 @@ construct_sub_topic(void)
|
|||
|
||||
/* len < 0: Error. Len >= BUFFER_SIZE: Buffer too small */
|
||||
if(len < 0 || len >= BUFFER_SIZE) {
|
||||
printf("Sub Topic: %d, Buffer %d\n", len, BUFFER_SIZE);
|
||||
LOG_INFO("Sub Topic: %d, Buffer %d\n", len, BUFFER_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -363,7 +360,7 @@ construct_client_id(void)
|
|||
|
||||
/* len < 0: Error. Len >= BUFFER_SIZE: Buffer too small */
|
||||
if(len < 0 || len >= BUFFER_SIZE) {
|
||||
printf("Client ID: %d, Buffer %d\n", len, BUFFER_SIZE);
|
||||
LOG_ERR("Client ID: %d, Buffer %d\n", len, BUFFER_SIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -438,9 +435,9 @@ subscribe(void)
|
|||
|
||||
status = mqtt_subscribe(&conn, NULL, sub_topic, MQTT_QOS_LEVEL_0);
|
||||
|
||||
DBG("APP - Subscribing!\n");
|
||||
LOG_DBG("Subscribing!\n");
|
||||
if(status == MQTT_STATUS_OUT_QUEUE_FULL) {
|
||||
DBG("APP - Tried to subscribe but command queue was full!\n");
|
||||
LOG_ERR("Tried to subscribe but command queue was full!\n");
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -450,6 +447,7 @@ publish(void)
|
|||
/* Publish MQTT topic in IBM quickstart format */
|
||||
int len;
|
||||
int remaining = APP_BUFFER_SIZE;
|
||||
int i;
|
||||
|
||||
seq_nr_value++;
|
||||
|
||||
|
@ -458,13 +456,17 @@ publish(void)
|
|||
len = snprintf(buf_ptr, remaining,
|
||||
"{"
|
||||
"\"d\":{"
|
||||
"\"myName\":\"%s\","
|
||||
"\"Platform\":\""CONTIKI_TARGET_STRING"\","
|
||||
#ifdef CONTIKI_BOARD_STRING
|
||||
"\"Board\":\""CONTIKI_BOARD_STRING"\","
|
||||
#endif
|
||||
"\"Seq #\":%d,"
|
||||
"\"Uptime (sec)\":%lu",
|
||||
BOARD_STRING, seq_nr_value, clock_seconds());
|
||||
seq_nr_value, clock_seconds());
|
||||
|
||||
if(len < 0 || len >= remaining) {
|
||||
printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len);
|
||||
LOG_ERR("Buffer too short. Have %d, need %d + \\0\n", remaining,
|
||||
len);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -476,47 +478,43 @@ publish(void)
|
|||
memset(def_rt_str, 0, sizeof(def_rt_str));
|
||||
ipaddr_sprintf(def_rt_str, sizeof(def_rt_str), uip_ds6_defrt_choose());
|
||||
|
||||
len = snprintf(buf_ptr, remaining, ",\"Def Route\":\"%s\",\"RSSI (dBm)\":%d",
|
||||
len = snprintf(buf_ptr, remaining,
|
||||
",\"Def Route\":\"%s\",\"RSSI (dBm)\":%d",
|
||||
def_rt_str, def_rt_rssi);
|
||||
|
||||
if(len < 0 || len >= remaining) {
|
||||
printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len);
|
||||
LOG_ERR("Buffer too short. Have %d, need %d + \\0\n", remaining,
|
||||
len);
|
||||
return;
|
||||
}
|
||||
remaining -= len;
|
||||
buf_ptr += len;
|
||||
|
||||
len = snprintf(buf_ptr, remaining, ",\"On-Chip Temp (mC)\":%d",
|
||||
cc2538_temp_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
||||
for(i = 0; i < mqtt_client_extension_count; i++) {
|
||||
len = snprintf(buf_ptr, remaining, ",%s",
|
||||
mqtt_client_extensions[i]->value());
|
||||
|
||||
if(len < 0 || len >= remaining) {
|
||||
printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len);
|
||||
return;
|
||||
if(len < 0 || len >= remaining) {
|
||||
LOG_ERR("Buffer too short. Have %d, need %d + \\0\n", remaining,
|
||||
len);
|
||||
return;
|
||||
}
|
||||
remaining -= len;
|
||||
buf_ptr += len;
|
||||
}
|
||||
remaining -= len;
|
||||
buf_ptr += len;
|
||||
|
||||
len = snprintf(buf_ptr, remaining, ",\"VDD3 (mV)\":%d",
|
||||
vdd3_sensor.value(CC2538_SENSORS_VALUE_TYPE_CONVERTED));
|
||||
|
||||
if(len < 0 || len >= remaining) {
|
||||
printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len);
|
||||
return;
|
||||
}
|
||||
remaining -= len;
|
||||
buf_ptr += len;
|
||||
|
||||
len = snprintf(buf_ptr, remaining, "}}");
|
||||
|
||||
if(len < 0 || len >= remaining) {
|
||||
printf("Buffer too short. Have %d, need %d + \\0\n", remaining, len);
|
||||
LOG_ERR("Buffer too short. Have %d, need %d + \\0\n", remaining,
|
||||
len);
|
||||
return;
|
||||
}
|
||||
|
||||
mqtt_publish(&conn, NULL, pub_topic, (uint8_t *)app_buffer,
|
||||
strlen(app_buffer), MQTT_QOS_LEVEL_0, MQTT_RETAIN_OFF);
|
||||
|
||||
DBG("APP - Publish!\n");
|
||||
LOG_DBG("Publish!\n");
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
|
@ -546,7 +544,7 @@ state_machine(void)
|
|||
switch(state) {
|
||||
case STATE_INIT:
|
||||
/* If we have just been configured register MQTT connection */
|
||||
mqtt_register(&conn, &mqtt_demo_process, client_id, mqtt_event,
|
||||
mqtt_register(&conn, &mqtt_client_process, client_id, mqtt_event,
|
||||
MAX_TCP_SEGMENT_SIZE);
|
||||
|
||||
/*
|
||||
|
@ -555,7 +553,7 @@ state_machine(void)
|
|||
*/
|
||||
if(strncasecmp(conf.org_id, QUICKSTART, strlen(conf.org_id)) != 0) {
|
||||
if(strlen(conf.auth_token) == 0) {
|
||||
printf("User name set, but empty auth token\n");
|
||||
LOG_ERR("User name set, but empty auth token\n");
|
||||
state = STATE_ERROR;
|
||||
break;
|
||||
} else {
|
||||
|
@ -569,31 +567,31 @@ state_machine(void)
|
|||
connect_attempt = 1;
|
||||
|
||||
state = STATE_REGISTERED;
|
||||
DBG("Init\n");
|
||||
LOG_DBG("Init\n");
|
||||
/* Continue */
|
||||
case STATE_REGISTERED:
|
||||
if(uip_ds6_get_global(ADDR_PREFERRED) != NULL) {
|
||||
/* Registered and with a public IP. Connect */
|
||||
DBG("Registered. Connect attempt %u\n", connect_attempt);
|
||||
LOG_DBG("Registered. Connect attempt %u\n", connect_attempt);
|
||||
ping_parent();
|
||||
connect_to_broker();
|
||||
} else {
|
||||
leds_on(STATUS_LED);
|
||||
leds_on(MQTT_CLIENT_STATUS_LED);
|
||||
ctimer_set(&ct, NO_NET_LED_DURATION, publish_led_off, NULL);
|
||||
}
|
||||
etimer_set(&publish_periodic_timer, NET_CONNECT_PERIODIC);
|
||||
return;
|
||||
break;
|
||||
case STATE_CONNECTING:
|
||||
leds_on(STATUS_LED);
|
||||
leds_on(MQTT_CLIENT_STATUS_LED);
|
||||
ctimer_set(&ct, CONNECTING_LED_DURATION, publish_led_off, NULL);
|
||||
/* Not connected yet. Wait */
|
||||
DBG("Connecting (%u)\n", connect_attempt);
|
||||
LOG_DBG("Connecting (%u)\n", connect_attempt);
|
||||
break;
|
||||
case STATE_CONNECTED:
|
||||
/* Don't subscribe unless we are a registered device */
|
||||
if(strncasecmp(conf.org_id, QUICKSTART, strlen(conf.org_id)) == 0) {
|
||||
DBG("Using 'quickstart': Skipping subscribe\n");
|
||||
LOG_DBG("Using 'quickstart': Skipping subscribe\n");
|
||||
state = STATE_PUBLISHING;
|
||||
}
|
||||
/* Continue */
|
||||
|
@ -613,13 +611,12 @@ state_machine(void)
|
|||
subscribe();
|
||||
state = STATE_PUBLISHING;
|
||||
} else {
|
||||
leds_on(STATUS_LED);
|
||||
leds_on(MQTT_CLIENT_STATUS_LED);
|
||||
ctimer_set(&ct, PUBLISH_LED_ON_DURATION, publish_led_off, NULL);
|
||||
LOG_DBG("Publishing\n");
|
||||
publish();
|
||||
}
|
||||
etimer_set(&publish_periodic_timer, conf.pub_interval);
|
||||
|
||||
DBG("Publishing\n");
|
||||
/* Return here so we don't end up rescheduling the timer */
|
||||
return;
|
||||
} else {
|
||||
|
@ -632,12 +629,12 @@ state_machine(void)
|
|||
* trigger a new message and we wait for TCP to either ACK the entire
|
||||
* packet after retries, or to timeout and notify us.
|
||||
*/
|
||||
DBG("Publishing... (MQTT state=%d, q=%u)\n", conn.state,
|
||||
conn.out_queue_full);
|
||||
LOG_DBG("Publishing... (MQTT state=%d, q=%u)\n", conn.state,
|
||||
conn.out_queue_full);
|
||||
}
|
||||
break;
|
||||
case STATE_DISCONNECTED:
|
||||
DBG("Disconnected\n");
|
||||
LOG_DBG("Disconnected\n");
|
||||
if(connect_attempt < RECONNECT_ATTEMPTS ||
|
||||
RECONNECT_ATTEMPTS == RETRY_FOREVER) {
|
||||
/* Disconnect and backoff */
|
||||
|
@ -648,7 +645,7 @@ state_machine(void)
|
|||
interval = connect_attempt < 3 ? RECONNECT_INTERVAL << connect_attempt :
|
||||
RECONNECT_INTERVAL << 3;
|
||||
|
||||
DBG("Disconnected. Attempt %u in %lu ticks\n", connect_attempt, interval);
|
||||
LOG_DBG("Disconnected. Attempt %u in %lu ticks\n", connect_attempt, interval);
|
||||
|
||||
etimer_set(&publish_periodic_timer, interval);
|
||||
|
||||
|
@ -657,23 +654,23 @@ state_machine(void)
|
|||
} else {
|
||||
/* Max reconnect attempts reached. Enter error state */
|
||||
state = STATE_ERROR;
|
||||
DBG("Aborting connection after %u attempts\n", connect_attempt - 1);
|
||||
LOG_DBG("Aborting connection after %u attempts\n", connect_attempt - 1);
|
||||
}
|
||||
break;
|
||||
case STATE_CONFIG_ERROR:
|
||||
/* Idle away. The only way out is a new config */
|
||||
printf("Bad configuration.\n");
|
||||
LOG_ERR("Bad configuration.\n");
|
||||
return;
|
||||
case STATE_ERROR:
|
||||
default:
|
||||
leds_on(STATUS_LED);
|
||||
leds_on(MQTT_CLIENT_STATUS_LED);
|
||||
/*
|
||||
* 'default' should never happen.
|
||||
*
|
||||
* If we enter here it's because of some error. Stop timers. The only thing
|
||||
* that can bring us out is a new config event
|
||||
*/
|
||||
printf("Default case: State=0x%02x\n", state);
|
||||
LOG_ERR("Default case: State=0x%02x\n", state);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -681,17 +678,31 @@ state_machine(void)
|
|||
etimer_set(&publish_periodic_timer, STATE_MACHINE_PERIODIC);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(mqtt_demo_process, ev, data)
|
||||
static void
|
||||
init_extensions(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < mqtt_client_extension_count; i++) {
|
||||
if(mqtt_client_extensions[i]->init) {
|
||||
mqtt_client_extensions[i]->init();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(mqtt_client_process, ev, data)
|
||||
{
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
printf("MQTT Demo Process\n");
|
||||
printf("MQTT Client Process\n");
|
||||
|
||||
if(init_config() != 1) {
|
||||
PROCESS_EXIT();
|
||||
}
|
||||
|
||||
init_extensions();
|
||||
|
||||
update_config();
|
||||
|
||||
def_rt_rssi = 0x8000000;
|
||||
|
@ -704,7 +715,8 @@ PROCESS_THREAD(mqtt_demo_process, ev, data)
|
|||
|
||||
PROCESS_YIELD();
|
||||
|
||||
if(ev == sensors_event && data == PUBLISH_TRIGGER) {
|
||||
if(ev == button_hal_release_event &&
|
||||
((button_hal_button_t *)data)->unique_id == BUTTON_HAL_ID_BUTTON_ZERO) {
|
||||
if(state == STATE_ERROR) {
|
||||
connect_attempt = 1;
|
||||
state = STATE_REGISTERED;
|
||||
|
@ -713,7 +725,8 @@ PROCESS_THREAD(mqtt_demo_process, ev, data)
|
|||
|
||||
if((ev == PROCESS_EVENT_TIMER && data == &publish_periodic_timer) ||
|
||||
ev == PROCESS_EVENT_POLL ||
|
||||
(ev == sensors_event && data == PUBLISH_TRIGGER)) {
|
||||
(ev == button_hal_release_event &&
|
||||
((button_hal_button_t *)data)->unique_id == BUTTON_HAL_ID_BUTTON_ZERO)) {
|
||||
state_machine();
|
||||
}
|
||||
|
||||
|
@ -726,7 +739,3 @@ PROCESS_THREAD(mqtt_demo_process, ev, data)
|
|||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef MQTT_CLIENT_H_
|
||||
#define MQTT_CLIENT_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
typedef struct mqtt_client_extension_s {
|
||||
void (*init)(void);
|
||||
char *(*value)(void);
|
||||
} mqtt_client_extension_t;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define MQTT_CLIENT_EXTENSIONS(...) \
|
||||
const mqtt_client_extension_t *mqtt_client_extensions[] = {__VA_ARGS__}; \
|
||||
const uint8_t mqtt_client_extension_count = \
|
||||
(sizeof(mqtt_client_extensions) / sizeof(mqtt_client_extensions[0]));
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* MQTT_CLIENT_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -29,26 +29,14 @@
|
|||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup cc2538-mqtt-demo
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Project specific configuration defines for the MQTT demo
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef PROJECT_CONF_H_
|
||||
#define PROJECT_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Enable TCP */
|
||||
#define UIP_CONF_TCP 1
|
||||
|
||||
/* User configuration */
|
||||
#define MQTT_DEMO_STATUS_LED LEDS_GREEN
|
||||
#define MQTT_DEMO_PUBLISH_TRIGGER &button_right_sensor
|
||||
|
||||
/* If undefined, the demo will attempt to connect to IBM's quickstart */
|
||||
#define MQTT_DEMO_BROKER_IP_ADDR "fd00::1"
|
||||
#define MQTT_CLIENT_CONF_BROKER_IP_ADDR "fd00::1"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* PROJECT_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -6,7 +6,7 @@
|
|||
<project EXPORT="discard">[APPS_DIR]/serial_socket</project>
|
||||
<project EXPORT="discard">[APPS_DIR]/powertracker</project>
|
||||
<simulation>
|
||||
<title>NullNet Broadcast Example</title>
|
||||
<title>NullNet Unicast Example</title>
|
||||
<randomseed>123456</randomseed>
|
||||
<motedelay_us>1000000</motedelay_us>
|
||||
<radiomedium>
|
||||
|
@ -23,8 +23,8 @@
|
|||
org.contikios.cooja.contikimote.ContikiMoteType
|
||||
<identifier>mtype634</identifier>
|
||||
<description>Cooja Mote Type #1</description>
|
||||
<source>[CONTIKI_DIR]/examples/nullnet/nullnet-broadcast.c</source>
|
||||
<commands>make nullnet-broadcast.cooja TARGET=cooja</commands>
|
||||
<source>[CONTIKI_DIR]/examples/nullnet/nullnet-unicast.c</source>
|
||||
<commands>make nullnet-unicast.cooja TARGET=cooja</commands>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Position</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.interfaces.Battery</moteinterface>
|
||||
<moteinterface>org.contikios.cooja.contikimote.interfaces.ContikiVib</moteinterface>
|
||||
|
@ -175,4 +175,3 @@
|
|||
<location_y>408</location_y>
|
||||
</plugin>
|
||||
</simconf>
|
||||
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
CONTIKI_PROJECT = mqtt-demo
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
PLATFORMS_ONLY = cc2538dk openmote-cc2538 zoul
|
||||
|
||||
MODULES += os/net/app-layer/mqtt
|
||||
|
||||
CONTIKI = ../../../..
|
||||
include $(CONTIKI)/Makefile.include
|
|
@ -1 +0,0 @@
|
|||
TARGET = cc2538dk
|
|
@ -62,8 +62,8 @@
|
|||
* - sensors : Some sensortag sensors are read asynchronously (see sensor
|
||||
* documentation). For those, this example will print out
|
||||
* readings in a staggered fashion at a random interval
|
||||
* - Buttons : CC26XX_DEMO_SENSOR_1 button will toggle CC26XX_DEMO_LEDS_BUTTON
|
||||
* - CC26XX_DEMO_SENSOR_2 turns on LEDS_REBOOT and causes a
|
||||
* - Buttons : CC26XX_DEMO_TRIGGER_1 button will toggle CC26XX_DEMO_LEDS_BUTTON
|
||||
* - CC26XX_DEMO_TRIGGER_2 turns on LEDS_REBOOT and causes a
|
||||
* watchdog reboot
|
||||
* - The remaining buttons will just print something
|
||||
* - The example also shows how to retrieve the duration of a
|
||||
|
@ -81,6 +81,7 @@
|
|||
#include "sys/ctimer.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "dev/button-hal.h"
|
||||
#include "random.h"
|
||||
#include "button-sensor.h"
|
||||
#include "batmon-sensor.h"
|
||||
|
@ -97,23 +98,11 @@
|
|||
#define CC26XX_DEMO_LEDS_BUTTON LEDS_RED
|
||||
#define CC26XX_DEMO_LEDS_REBOOT LEDS_ALL
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define CC26XX_DEMO_SENSOR_NONE (void *)0xFFFFFFFF
|
||||
|
||||
#define CC26XX_DEMO_SENSOR_1 &button_left_sensor
|
||||
#define CC26XX_DEMO_SENSOR_2 &button_right_sensor
|
||||
#define CC26XX_DEMO_TRIGGER_1 BOARD_BUTTON_HAL_INDEX_KEY_LEFT
|
||||
#define CC26XX_DEMO_TRIGGER_2 BOARD_BUTTON_HAL_INDEX_KEY_RIGHT
|
||||
|
||||
#if BOARD_SENSORTAG
|
||||
#define CC26XX_DEMO_SENSOR_3 CC26XX_DEMO_SENSOR_NONE
|
||||
#define CC26XX_DEMO_SENSOR_4 CC26XX_DEMO_SENSOR_NONE
|
||||
#define CC26XX_DEMO_SENSOR_5 &reed_relay_sensor
|
||||
#elif BOARD_LAUNCHPAD
|
||||
#define CC26XX_DEMO_SENSOR_3 CC26XX_DEMO_SENSOR_NONE
|
||||
#define CC26XX_DEMO_SENSOR_4 CC26XX_DEMO_SENSOR_NONE
|
||||
#define CC26XX_DEMO_SENSOR_5 CC26XX_DEMO_SENSOR_NONE
|
||||
#else
|
||||
#define CC26XX_DEMO_SENSOR_3 &button_up_sensor
|
||||
#define CC26XX_DEMO_SENSOR_4 &button_down_sensor
|
||||
#define CC26XX_DEMO_SENSOR_5 &button_select_sensor
|
||||
#define CC26XX_DEMO_TRIGGER_3 BOARD_BUTTON_HAL_INDEX_REED_RELAY
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct etimer et;
|
||||
|
@ -343,10 +332,6 @@ get_sync_sensor_readings(void)
|
|||
static void
|
||||
init_sensors(void)
|
||||
{
|
||||
#if BOARD_SENSORTAG
|
||||
SENSORS_ACTIVATE(reed_relay_sensor);
|
||||
#endif
|
||||
|
||||
SENSORS_ACTIVATE(batmon_sensor);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -392,46 +377,41 @@ PROCESS_THREAD(cc26xx_demo_process, ev, data)
|
|||
|
||||
etimer_set(&et, CC26XX_DEMO_LOOP_INTERVAL);
|
||||
}
|
||||
} else if(ev == sensors_event) {
|
||||
if(data == CC26XX_DEMO_SENSOR_1) {
|
||||
printf("Left: Pin %d, press duration %d clock ticks\n",
|
||||
(CC26XX_DEMO_SENSOR_1)->value(BUTTON_SENSOR_VALUE_STATE),
|
||||
(CC26XX_DEMO_SENSOR_1)->value(BUTTON_SENSOR_VALUE_DURATION));
|
||||
} else if(ev == button_hal_periodic_event) {
|
||||
button_hal_button_t *button = data;
|
||||
|
||||
if((CC26XX_DEMO_SENSOR_1)->value(BUTTON_SENSOR_VALUE_DURATION) >
|
||||
CLOCK_SECOND) {
|
||||
printf("Long button press!\n");
|
||||
}
|
||||
printf("%s periodic event, duration %d seconds\n",
|
||||
BUTTON_HAL_GET_DESCRIPTION(button),
|
||||
button->press_duration_seconds);
|
||||
} else if(ev == button_hal_release_event) {
|
||||
button_hal_button_t *btn = (button_hal_button_t *)data;
|
||||
|
||||
printf("%s release event\n", BUTTON_HAL_GET_DESCRIPTION(btn));
|
||||
|
||||
if(btn->unique_id== CC26XX_DEMO_TRIGGER_1) {
|
||||
leds_toggle(CC26XX_DEMO_LEDS_BUTTON);
|
||||
} else if(data == CC26XX_DEMO_SENSOR_2) {
|
||||
} else if(btn->unique_id == CC26XX_DEMO_TRIGGER_2) {
|
||||
leds_on(CC26XX_DEMO_LEDS_REBOOT);
|
||||
watchdog_reboot();
|
||||
} else if(data == CC26XX_DEMO_SENSOR_3) {
|
||||
printf("Up\n");
|
||||
} else if(data == CC26XX_DEMO_SENSOR_4) {
|
||||
printf("Down\n");
|
||||
} else if(data == CC26XX_DEMO_SENSOR_5) {
|
||||
#if BOARD_SENSORTAG
|
||||
} else if(btn->unique_id == CC26XX_DEMO_TRIGGER_3) {
|
||||
if(buzzer_state()) {
|
||||
buzzer_stop();
|
||||
} else {
|
||||
buzzer_start(1000);
|
||||
}
|
||||
} else if(ev == sensors_event && data == &bmp_280_sensor) {
|
||||
}
|
||||
} else if(ev == sensors_event) {
|
||||
if(data == &bmp_280_sensor) {
|
||||
get_bmp_reading();
|
||||
} else if(ev == sensors_event && data == &opt_3001_sensor) {
|
||||
} else if(data == &opt_3001_sensor) {
|
||||
get_light_reading();
|
||||
} else if(ev == sensors_event && data == &hdc_1000_sensor) {
|
||||
} else if(data == &hdc_1000_sensor) {
|
||||
get_hdc_reading();
|
||||
} else if(ev == sensors_event && data == &tmp_007_sensor) {
|
||||
} else if(data == &tmp_007_sensor) {
|
||||
get_tmp_reading();
|
||||
} else if(ev == sensors_event && data == &mpu_9250_sensor) {
|
||||
} else if(data == &mpu_9250_sensor) {
|
||||
get_mpu_reading();
|
||||
#elif BOARD_SMARTRF06EB
|
||||
printf("Sel: Pin %d, press duration %d clock ticks\n",
|
||||
button_select_sensor.value(BUTTON_SENSOR_VALUE_STATE),
|
||||
button_select_sensor.value(BUTTON_SENSOR_VALUE_DURATION));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
#include "lib/list.h"
|
||||
#include "sys/process.h"
|
||||
#include "net/ipv6/sicslowpan.h"
|
||||
#include "button-sensor.h"
|
||||
#include "dev/button-hal.h"
|
||||
#include "batmon-sensor.h"
|
||||
#include "httpd-simple.h"
|
||||
#include "cc26xx-web-demo.h"
|
||||
|
@ -882,8 +882,6 @@ init_sensors(void)
|
|||
list_add(sensor_list, &mpu_gyro_x_reading);
|
||||
list_add(sensor_list, &mpu_gyro_y_reading);
|
||||
list_add(sensor_list, &mpu_gyro_z_reading);
|
||||
|
||||
SENSORS_ACTIVATE(reed_relay_sensor);
|
||||
#endif
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -977,16 +975,16 @@ PROCESS_THREAD(cc26xx_web_demo_process, ev, data)
|
|||
}
|
||||
#endif
|
||||
|
||||
if(ev == sensors_event && data == CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER) {
|
||||
if((CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER)->value(
|
||||
BUTTON_SENSOR_VALUE_DURATION) > CLOCK_SECOND * 5) {
|
||||
printf("Restoring defaults!\n");
|
||||
cc26xx_web_demo_restore_defaults();
|
||||
} else {
|
||||
init_sensor_readings();
|
||||
|
||||
process_post(PROCESS_BROADCAST, cc26xx_web_demo_publish_event, NULL);
|
||||
}
|
||||
if(ev == button_hal_release_event &&
|
||||
((button_hal_button_t *)data)->unique_id ==
|
||||
CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER) {
|
||||
init_sensor_readings();
|
||||
process_post(PROCESS_BROADCAST, cc26xx_web_demo_publish_event, NULL);
|
||||
} else if(ev == button_hal_periodic_event &&
|
||||
((button_hal_button_t *)data)->unique_id ==
|
||||
CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER) {
|
||||
printf("Restoring defaults!\n");
|
||||
cc26xx_web_demo_restore_defaults();
|
||||
} else if(ev == httpd_simple_event_new_config) {
|
||||
save_config();
|
||||
#if BOARD_SENSORTAG
|
||||
|
|
|
@ -98,18 +98,18 @@
|
|||
/*---------------------------------------------------------------------------*/
|
||||
/* User configuration */
|
||||
/* Take a sensor reading on button press */
|
||||
#define CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER &button_left_sensor
|
||||
#define CC26XX_WEB_DEMO_SENSOR_READING_TRIGGER BOARD_BUTTON_HAL_INDEX_KEY_LEFT
|
||||
|
||||
/* Payload length of ICMPv6 echo requests used to measure RSSI with def rt */
|
||||
#define CC26XX_WEB_DEMO_ECHO_REQ_PAYLOAD_LEN 20
|
||||
|
||||
#if BOARD_SENSORTAG
|
||||
/* Force an MQTT publish on sensor event */
|
||||
#define CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER &reed_relay_sensor
|
||||
#define CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER BOARD_BUTTON_HAL_INDEX_REED_RELAY
|
||||
#elif BOARD_LAUNCHPAD
|
||||
#define CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER &button_left_sensor
|
||||
#define CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER BOARD_BUTTON_HAL_INDEX_KEY_LEFT
|
||||
#else
|
||||
#define CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER &button_down_sensor
|
||||
#define CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER BOARD_BUTTON_HAL_INDEX_KEY_DOWN
|
||||
#endif
|
||||
|
||||
#define CC26XX_WEB_DEMO_STATUS_LED LEDS_GREEN
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
#include "sys/etimer.h"
|
||||
#include "sys/ctimer.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "button-sensor.h"
|
||||
#include "dev/button-hal.h"
|
||||
#include "board-peripherals.h"
|
||||
#include "cc26xx-web-demo.h"
|
||||
#include "dev/leds.h"
|
||||
|
@ -882,10 +882,14 @@ PROCESS_THREAD(mqtt_client_process, ev, data)
|
|||
|
||||
PROCESS_YIELD();
|
||||
|
||||
if(ev == sensors_event && data == CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER) {
|
||||
if(state == MQTT_CLIENT_STATE_ERROR) {
|
||||
connect_attempt = 1;
|
||||
state = MQTT_CLIENT_STATE_REGISTERED;
|
||||
if(ev == button_hal_release_event) {
|
||||
button_hal_button_t *btn = (button_hal_button_t *)data;
|
||||
|
||||
if(btn->unique_id == CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER) {
|
||||
if(state == MQTT_CLIENT_STATE_ERROR) {
|
||||
connect_attempt = 1;
|
||||
state = MQTT_CLIENT_STATE_REGISTERED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -901,7 +905,9 @@ PROCESS_THREAD(mqtt_client_process, ev, data)
|
|||
if((ev == PROCESS_EVENT_TIMER && data == &publish_periodic_timer) ||
|
||||
ev == PROCESS_EVENT_POLL ||
|
||||
ev == cc26xx_web_demo_publish_event ||
|
||||
(ev == sensors_event && data == CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER)) {
|
||||
(ev == button_hal_release_event &&
|
||||
((button_hal_button_t *)data)->unique_id ==
|
||||
CC26XX_WEB_DEMO_MQTT_PUBLISH_TRIGGER)) {
|
||||
state_machine();
|
||||
}
|
||||
|
||||
|
|
|
@ -31,9 +31,6 @@
|
|||
#ifndef PROJECT_CONF_H_
|
||||
#define PROJECT_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Disable button shutdown functionality */
|
||||
#define BUTTON_SENSOR_CONF_ENABLE_SHUTDOWN 0
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Enable the ROM bootloader */
|
||||
#define ROM_BOOTLOADER_ENABLE 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "sys/process.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "button-sensor.h"
|
||||
#include "dev/button-hal.h"
|
||||
#include "batmon-sensor.h"
|
||||
#include "board-peripherals.h"
|
||||
#include "net/netstack.h"
|
||||
|
@ -63,6 +63,8 @@
|
|||
#define VERY_SLEEPY_MODE_OFF 0
|
||||
#define VERY_SLEEPY_MODE_ON 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_TRIGGER BOARD_BUTTON_HAL_INDEX_KEY_LEFT
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define MAC_CAN_BE_TURNED_OFF 0
|
||||
#define MAC_MUST_STAY_ON 1
|
||||
|
||||
|
@ -358,7 +360,8 @@ PROCESS_THREAD(very_sleepy_demo_process, ev, data)
|
|||
|
||||
PROCESS_YIELD();
|
||||
|
||||
if(ev == sensors_event && data == &button_left_sensor) {
|
||||
if(ev == button_hal_release_event &&
|
||||
((button_hal_button_t *)data)->unique_id == BUTTON_TRIGGER) {
|
||||
switch_to_normal();
|
||||
}
|
||||
|
||||
|
@ -368,7 +371,8 @@ PROCESS_THREAD(very_sleepy_demo_process, ev, data)
|
|||
}
|
||||
|
||||
if((ev == PROCESS_EVENT_TIMER && data == &et_periodic) ||
|
||||
(ev == sensors_event && data == &button_left_sensor) ||
|
||||
(ev == button_hal_release_event &&
|
||||
((button_hal_button_t *)data)->unique_id == BUTTON_TRIGGER) ||
|
||||
(ev == event_new_config)) {
|
||||
|
||||
/*
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include "ipv6/ip64-addr.h"
|
||||
#include "dev/leds.h"
|
||||
#include "net/routing/routing.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/button-hal.h"
|
||||
#include <stdio.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct http_socket s;
|
||||
|
@ -138,13 +138,10 @@ PROCESS_THREAD(http_example_process, ev, data)
|
|||
|
||||
while(1) {
|
||||
PROCESS_YIELD();
|
||||
if((ev == sensors_event) && (data == &button_sensor)) {
|
||||
if(button_sensor.value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) ==
|
||||
BUTTON_SENSOR_PRESSED_LEVEL) {
|
||||
leds_on(LEDS_GREEN);
|
||||
printf("Button pressed! sending a POST to IFTTT\n");
|
||||
http_socket_post(&s, url_buffer, NULL, 0, NULL, callback, NULL);
|
||||
}
|
||||
if(ev == button_hal_release_event) {
|
||||
leds_on(LEDS_GREEN);
|
||||
printf("Button pressed! sending a POST to IFTTT\n");
|
||||
http_socket_post(&s, url_buffer, NULL, 0, NULL, callback, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "dev/rgb-bl-lcd.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "dev/button-hal.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define SCROLL_PERIOD (CLOCK_SECOND / 6)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -104,18 +104,13 @@ PROCESS_THREAD(remote_lcd_process, ev, data)
|
|||
printf("Counter: %05u\n", counter);
|
||||
counter++;
|
||||
etimer_restart(&et);
|
||||
} else if(ev == sensors_event) {
|
||||
if(data == &button_sensor) {
|
||||
if(button_sensor.value(BUTTON_SENSOR_VALUE_TYPE_LEVEL) ==
|
||||
BUTTON_SENSOR_PRESSED_LEVEL) {
|
||||
printf("Button pressed!!\n");
|
||||
lcd_set_cursor(0, LCD_RGB_1ST_ROW);
|
||||
lcd_write("Button pressed!!");
|
||||
} else {
|
||||
lcd_set_cursor(0, LCD_RGB_1ST_ROW);
|
||||
lcd_write("Press the button!");
|
||||
}
|
||||
}
|
||||
} else if(ev == button_hal_press_event) {
|
||||
printf("Button pressed!!\n");
|
||||
lcd_set_cursor(0, LCD_RGB_1ST_ROW);
|
||||
lcd_write("Button pressed!!");
|
||||
} else if(ev == button_hal_release_event) {
|
||||
lcd_set_cursor(0, LCD_RGB_1ST_ROW);
|
||||
lcd_write("Press the button!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,231 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup button_hal
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Platform-independent button driver.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "sys/process.h"
|
||||
#include "sys/ctimer.h"
|
||||
#include "sys/critical.h"
|
||||
#include "dev/gpio-hal.h"
|
||||
#include "dev/button-hal.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(button_hal_process, "Button HAL process");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
process_event_t button_hal_press_event;
|
||||
process_event_t button_hal_release_event;
|
||||
process_event_t button_hal_periodic_event;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* A mask of all pins that have changed state since the last process poll */
|
||||
static volatile gpio_hal_pin_mask_t pmask;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
extern button_hal_button_t *button_hal_buttons[];
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Common handler for all handler events, and register it with the GPIO HAL */
|
||||
static gpio_hal_event_handler_t button_event_handler;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
duration_exceeded_callback(void *btn)
|
||||
{
|
||||
button_hal_button_t *button = (button_hal_button_t *)btn;
|
||||
|
||||
button->press_duration_seconds++;
|
||||
ctimer_set(&button->duration_ctimer, CLOCK_SECOND,
|
||||
duration_exceeded_callback, button);
|
||||
process_post(PROCESS_BROADCAST, button_hal_periodic_event, button);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
debounce_handler(void *btn)
|
||||
{
|
||||
button_hal_button_t *button;
|
||||
int expired;
|
||||
uint8_t button_state;
|
||||
|
||||
button = (button_hal_button_t *)btn;
|
||||
|
||||
/*
|
||||
* A new debounce may have been triggered after expiration of the previous
|
||||
* one but before we got called.
|
||||
*/
|
||||
if(!ctimer_expired(&button->debounce_ctimer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
expired = ctimer_expired(&button->duration_ctimer);
|
||||
|
||||
button_state = button_hal_get_state(button);
|
||||
|
||||
/*
|
||||
* A debounce timer expired. Inspect the button's state. If the button's
|
||||
* state is the same as it was before, then we ignore this as noise.
|
||||
*/
|
||||
if(button_state == BUTTON_HAL_STATE_PRESSED && expired) {
|
||||
/*
|
||||
* Button is pressed and no tick counter running. Treat as new press.
|
||||
* Include the debounce duration in the first periodic, so that the
|
||||
* callback will happen 1 second after the button press, not 1 second
|
||||
* after the end of the debounce. Notify process about the press event.
|
||||
*/
|
||||
button->press_duration_seconds = 0;
|
||||
ctimer_set(&button->duration_ctimer,
|
||||
CLOCK_SECOND - BUTTON_HAL_DEBOUNCE_DURATION,
|
||||
duration_exceeded_callback, button);
|
||||
process_post(PROCESS_BROADCAST, button_hal_press_event, button);
|
||||
} else if(button_state == BUTTON_HAL_STATE_RELEASED && expired == 0) {
|
||||
/*
|
||||
* Button is released and there is a duration_ctimer running. Treat this
|
||||
* as a new release and notify processes.
|
||||
*/
|
||||
ctimer_stop(&button->duration_ctimer);
|
||||
process_post(PROCESS_BROADCAST, button_hal_release_event, button);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
press_release_handler(gpio_hal_pin_mask_t pin_mask)
|
||||
{
|
||||
pmask |= pin_mask;
|
||||
process_poll(&button_hal_process);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
button_hal_button_t *
|
||||
button_hal_get_by_id(uint8_t unique_id)
|
||||
{
|
||||
button_hal_button_t **button;
|
||||
|
||||
for(button = button_hal_buttons; *button != NULL; button++) {
|
||||
if((*button)->unique_id == unique_id) {
|
||||
return *button;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
button_hal_button_t *
|
||||
button_hal_get_by_index(uint8_t index)
|
||||
{
|
||||
if(index >= button_hal_button_count) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return button_hal_buttons[index];
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
uint8_t
|
||||
button_hal_get_state(button_hal_button_t *button)
|
||||
{
|
||||
uint8_t pin_state = gpio_hal_arch_read_pin(button->pin);
|
||||
|
||||
if((pin_state == 0 && button->negative_logic == true) ||
|
||||
(pin_state == 1 && button->negative_logic == false)) {
|
||||
return BUTTON_HAL_STATE_PRESSED;
|
||||
}
|
||||
|
||||
return BUTTON_HAL_STATE_RELEASED;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
button_hal_init()
|
||||
{
|
||||
button_hal_button_t **button;
|
||||
gpio_hal_pin_cfg_t cfg;
|
||||
|
||||
button_hal_press_event = process_alloc_event();
|
||||
button_hal_release_event = process_alloc_event();
|
||||
button_hal_periodic_event = process_alloc_event();
|
||||
|
||||
button_event_handler.pin_mask = 0;
|
||||
button_event_handler.handler = press_release_handler;
|
||||
|
||||
for(button = button_hal_buttons; *button != NULL; button++) {
|
||||
cfg = GPIO_HAL_PIN_CFG_EDGE_BOTH | GPIO_HAL_PIN_CFG_INT_ENABLE |
|
||||
(*button)->pull;
|
||||
gpio_hal_arch_pin_set_input((*button)->pin);
|
||||
gpio_hal_arch_pin_cfg_set((*button)->pin, cfg);
|
||||
gpio_hal_arch_interrupt_enable((*button)->pin);
|
||||
button_event_handler.pin_mask |= gpio_hal_pin_to_mask((*button)->pin);
|
||||
}
|
||||
|
||||
process_start(&button_hal_process, NULL);
|
||||
|
||||
gpio_hal_register_handler(&button_event_handler);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(button_hal_process, ev, data)
|
||||
{
|
||||
int_master_status_t status;
|
||||
gpio_hal_pin_mask_t pins;
|
||||
button_hal_button_t **button;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
while(1) {
|
||||
PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_POLL);
|
||||
|
||||
status = critical_enter();
|
||||
pins = pmask;
|
||||
pmask = 0;
|
||||
critical_exit(status);
|
||||
|
||||
for(button = button_hal_buttons; *button != NULL; button++) {
|
||||
if(gpio_hal_pin_to_mask((*button)->pin) & pins) {
|
||||
/* Ignore all button presses/releases during its debounce */
|
||||
if(ctimer_expired(&(*button)->debounce_ctimer)) {
|
||||
/*
|
||||
* Here we merely set a debounce timer. At the end of the debounce we
|
||||
* will inspect the button's state and we will take action only if it
|
||||
* has changed.
|
||||
*
|
||||
* This is to prevent erroneous edge detections due to interference.
|
||||
*/
|
||||
ctimer_set(&(*button)->debounce_ctimer, BUTTON_HAL_DEBOUNCE_DURATION,
|
||||
debounce_handler, *button);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/** @} */
|
|
@ -0,0 +1,270 @@
|
|||
/*
|
||||
* Copyright (c) 2017, George Oikonomou - http://www.spd.gr
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \addtogroup dev
|
||||
* @{
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \defgroup button_hal Button HAL
|
||||
*
|
||||
* Hardware abstraction layer for user buttons.
|
||||
*
|
||||
* This HAL enables an abstraction of general-purpose / user buttons or
|
||||
* similar peripherals (e.g. a reed relay can also be abstracted through this
|
||||
* HAL). The HAL handles software debounce timers internally, therefore the
|
||||
* platform-specific button driver does not need to worry about debouncing.
|
||||
*
|
||||
* The platform developer needs to define a variable of type
|
||||
* \c button_hal_button_t for each user button. Within this variable, the
|
||||
* developer needs to specify the GPIO pin where the button is attached,
|
||||
* whether the button uses negative logic, and whether the GPIO pin should
|
||||
* be configured with internal pullup/down. The developer also needs to provide
|
||||
* a unique index for each button, as well as a description.
|
||||
*
|
||||
* With those in place, the HAL will generate the following process events:
|
||||
*
|
||||
* - button_hal_press_event: Upon press of the button
|
||||
* - button_hal_release_event: Upon release of the button
|
||||
* - button_hal_periodic_event: Generated every second that the user button is
|
||||
* kept pressed.
|
||||
*
|
||||
* With those events in place, an application can perform an action:
|
||||
*
|
||||
* - Immediately after the button gets pressed.
|
||||
* - After the button has been pressed for N seconds.
|
||||
* - Immediately upon release of the button. This action can vary depending
|
||||
* on how long the button had been pressed for.
|
||||
*
|
||||
* A platform with user buttons can either implement this API (recommended) or
|
||||
* the older button_sensor API. Some examples will not work if this API is not
|
||||
* implemented.
|
||||
*
|
||||
* This API requires the platform to first support the GPIO HAL API.
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file for the button HAL
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef BUTTON_HAL_H_
|
||||
#define BUTTON_HAL_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "dev/gpio-hal.h"
|
||||
#include "sys/clock.h"
|
||||
#include "sys/ctimer.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Controls the software debounce timer duration.
|
||||
*
|
||||
* The platform can provide a more suitable value. This value will apply to
|
||||
* all buttons.
|
||||
*/
|
||||
#ifdef BUTTON_HAL_CONF_DEBOUNCE_DURATION
|
||||
#define BUTTON_HAL_DEBOUNCE_DURATION BUTTON_HAL_CONF_DEBOUNCE_DURATION
|
||||
#else
|
||||
#define BUTTON_HAL_DEBOUNCE_DURATION (CLOCK_SECOND >> 6)
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Controls whether buttons will have human-readable names
|
||||
*
|
||||
* Define this to zero to save code space
|
||||
*/
|
||||
#if BUTTON_HAL_CONF_WITH_DESCRIPTION
|
||||
#define BUTTON_HAL_WITH_DESCRIPTION BUTTON_HAL_CONF_WITH_DESCRIPTION
|
||||
#else
|
||||
#define BUTTON_HAL_WITH_DESCRIPTION 1
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_HAL_STATE_RELEASED 0
|
||||
#define BUTTON_HAL_STATE_PRESSED 1
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Optional button IDs
|
||||
*/
|
||||
#define BUTTON_HAL_ID_BUTTON_ZERO 0x00
|
||||
#define BUTTON_HAL_ID_BUTTON_ONE 0x01
|
||||
#define BUTTON_HAL_ID_BUTTON_TWO 0x02
|
||||
#define BUTTON_HAL_ID_BUTTON_THREE 0x03
|
||||
#define BUTTON_HAL_ID_BUTTON_FOUR 0x04
|
||||
#define BUTTON_HAL_ID_BUTTON_FIVE 0x05
|
||||
|
||||
#define BUTTON_HAL_ID_USER_BUTTON BUTTON_HAL_ID_BUTTON_ZERO
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief A logical representation of a user button
|
||||
*/
|
||||
typedef struct button_hal_button_s button_hal_button_t;
|
||||
|
||||
struct button_hal_button_s {
|
||||
/** Used by the s/w debounce functionality */
|
||||
struct ctimer debounce_ctimer;
|
||||
|
||||
/** A callback timer used to count duration of button presses */
|
||||
struct ctimer duration_ctimer;
|
||||
|
||||
#if BUTTON_HAL_WITH_DESCRIPTION
|
||||
/**
|
||||
* \brief A textual description of the button
|
||||
*
|
||||
* This field may only be accessed using the BUTTON_HAL_GET_DESCRIPTION()
|
||||
* macro.
|
||||
*/
|
||||
const char *description;
|
||||
#endif
|
||||
|
||||
/** True if the button uses negative logic (active: low) */
|
||||
const bool negative_logic;
|
||||
|
||||
/** The gpio pin connected to the button */
|
||||
const gpio_hal_pin_t pin;
|
||||
|
||||
/** The pin's pull configuration */
|
||||
const gpio_hal_pin_cfg_t pull;
|
||||
|
||||
/** A counter of the duration (in seconds) of a button press */
|
||||
uint8_t press_duration_seconds;
|
||||
|
||||
/**
|
||||
* \brief A unique identifier for this button.
|
||||
*
|
||||
* The platform code is responsible of setting unique values here. This can
|
||||
* be used later to determine which button generated an event. Many examples
|
||||
* assume the existence of a button with ID == BUTTON_HAL_ID_BUTTON_ZERO,
|
||||
* so it is good idea to use this ID for one of your platform's buttons.
|
||||
*/
|
||||
const uint8_t unique_id;
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if BUTTON_HAL_WITH_DESCRIPTION
|
||||
/**
|
||||
* \brief Define a button to be used by the HAL
|
||||
* \param name The variable name for the button
|
||||
* \param descr A textual description
|
||||
* \param p The pin connected to the button
|
||||
* \param nl True if the button is connected using negative logic
|
||||
* \param u The button's pull configuration
|
||||
* \param id A unique numeric identifier
|
||||
*/
|
||||
#define BUTTON_HAL_BUTTON(name, descr, p, u, id, nl) \
|
||||
static button_hal_button_t name = { \
|
||||
.description = descr, \
|
||||
.pin = p, \
|
||||
.pull = u, \
|
||||
.unique_id = id, \
|
||||
.negative_logic = nl, \
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Retrieve the textual description of a button
|
||||
* \param b A pointer to the button button_hal_button_t
|
||||
*
|
||||
* This macro will return the value of the description field for b. If
|
||||
* BUTTON_HAL_WITH_DESCRIPTION is 0 then this macro will return ""
|
||||
*/
|
||||
#define BUTTON_HAL_GET_DESCRIPTION(b) (b)->description
|
||||
#else
|
||||
#define BUTTON_HAL_BUTTON(name, descr, p, u, id, nl) \
|
||||
static button_hal_button_t name = { \
|
||||
.pin = p, \
|
||||
.pull = u, \
|
||||
.unique_id = id, \
|
||||
.negative_logic = nl, \
|
||||
}
|
||||
|
||||
#define BUTTON_HAL_GET_DESCRIPTION(b) ""
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define BUTTON_HAL_BUTTONS(...) \
|
||||
button_hal_button_t *button_hal_buttons[] = {__VA_ARGS__, NULL}; \
|
||||
const uint8_t button_hal_button_count = \
|
||||
(sizeof(button_hal_buttons) / sizeof(button_hal_buttons[0])) - 1;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief The number of buttons on a device
|
||||
*/
|
||||
extern const uint8_t button_hal_button_count;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief A broadcast event generated when a button gets pressed
|
||||
*/
|
||||
extern process_event_t button_hal_press_event;
|
||||
|
||||
/**
|
||||
* \brief A broadcast event generated when a button gets released
|
||||
*/
|
||||
extern process_event_t button_hal_release_event;
|
||||
|
||||
/**
|
||||
* \brief A broadcast event generated every second while a button is kept pressed
|
||||
*/
|
||||
extern process_event_t button_hal_periodic_event;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Initialise the button HAL
|
||||
*/
|
||||
void button_hal_init(void);
|
||||
|
||||
/**
|
||||
* \brief Retrieve a button by ID
|
||||
* \param unique_id The button unique ID to search for
|
||||
* \return A pointer to the button or NULL if not found
|
||||
*/
|
||||
button_hal_button_t *button_hal_get_by_id(uint8_t unique_id);
|
||||
|
||||
/**
|
||||
* \brief Retrieve a button by its index
|
||||
* \param index The button's index (0, 1, ... button_hal_button_count - 1)
|
||||
* \return A pointer to the button or NULL if not found
|
||||
*/
|
||||
button_hal_button_t *button_hal_get_by_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* \brief Get the state of a button (pressed / released)
|
||||
* \param button A pointer to the button
|
||||
* \retval BUTTON_HAL_STATE_RELEASED The button is currently released
|
||||
* \retval BUTTON_HAL_STATE_PRESSED The button is currently pressed
|
||||
*/
|
||||
uint8_t button_hal_get_state(button_hal_button_t *button);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* BUTTON_HAL_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
|
@ -353,7 +353,7 @@ add_fragment(uint16_t tag, uint16_t frag_size, uint8_t offset)
|
|||
for(i = 0; i < SICSLOWPAN_REASS_CONTEXTS; i++) {
|
||||
/* clear all fragment info with expired timer to free all fragment buffers */
|
||||
if(frag_info[i].len > 0 && timer_expired(&frag_info[i].reass_timer)) {
|
||||
clear_fragments(i);
|
||||
clear_fragments(i);
|
||||
}
|
||||
|
||||
/* We use len as indication on used or not used */
|
||||
|
@ -421,12 +421,12 @@ copy_frags2uip(int context)
|
|||
|
||||
/* Copy from the fragment context info buffer first */
|
||||
memcpy((uint8_t *)UIP_IP_BUF, (uint8_t *)frag_info[context].first_frag,
|
||||
frag_info[context].first_frag_len);
|
||||
frag_info[context].first_frag_len);
|
||||
for(i = 0; i < SICSLOWPAN_FRAGMENT_BUFFERS; i++) {
|
||||
/* And also copy all matching fragments */
|
||||
if(frag_buf[i].len > 0 && frag_buf[i].index == context) {
|
||||
memcpy((uint8_t *)UIP_IP_BUF + (uint16_t)(frag_buf[i].offset << 3),
|
||||
(uint8_t *)frag_buf[i].data, frag_buf[i].len);
|
||||
(uint8_t *)frag_buf[i].data, frag_buf[i].len);
|
||||
}
|
||||
}
|
||||
/* deallocate all the fragments for this context */
|
||||
|
@ -676,9 +676,9 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
|
|||
LOG_DBG("before compression (%d): ", UIP_IP_BUF->len[1]);
|
||||
for(ndx = 0; ndx < UIP_IP_BUF->len[1] + 40; ndx++) {
|
||||
uint8_t data = ((uint8_t *) (UIP_IP_BUF))[ndx];
|
||||
LOG_DBG("%02x", data);
|
||||
LOG_DBG_("%02x", data);
|
||||
}
|
||||
LOG_DBG("\n");
|
||||
LOG_DBG_("\n");
|
||||
}
|
||||
|
||||
hc06_ptr = PACKETBUF_IPHC_BUF + 2;
|
||||
|
@ -1000,9 +1000,9 @@ compress_hdr_iphc(linkaddr_t *link_destaddr)
|
|||
LOG_DBG("after compression %d: ", (int)(hc06_ptr - packetbuf_ptr));
|
||||
for(ndx = 0; ndx < hc06_ptr - packetbuf_ptr; ndx++) {
|
||||
uint8_t data = ((uint8_t *) packetbuf_ptr)[ndx];
|
||||
LOG_DBG("%02x", data);
|
||||
LOG_DBG_("%02x", data);
|
||||
}
|
||||
LOG_DBG("\n");
|
||||
LOG_DBG_("\n");
|
||||
}
|
||||
|
||||
packetbuf_hdr_len = hc06_ptr - packetbuf_ptr;
|
||||
|
@ -1059,7 +1059,7 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len)
|
|||
SICSLOWPAN_IP_BUF(buf)->vtc = 0x60 | ((tmp >> 2) & 0x0f);
|
||||
/* ECN rolled down two steps + lowest DSCP bits at top two bits */
|
||||
SICSLOWPAN_IP_BUF(buf)->tcflow = ((tmp >> 2) & 0x30) | (tmp << 6) |
|
||||
(SICSLOWPAN_IP_BUF(buf)->tcflow & 0x0f);
|
||||
(SICSLOWPAN_IP_BUF(buf)->tcflow & 0x0f);
|
||||
} else {
|
||||
/* Traffic class is compressed (set version and no TC)*/
|
||||
SICSLOWPAN_IP_BUF(buf)->vtc = 0x60;
|
||||
|
@ -1074,7 +1074,7 @@ uncompress_hdr_iphc(uint8_t *buf, uint16_t ip_len)
|
|||
/* Version and flow label are compressed */
|
||||
if((iphc0 & SICSLOWPAN_IPHC_TC_C) == 0) {
|
||||
/* Traffic class is inline */
|
||||
SICSLOWPAN_IP_BUF(buf)->vtc = 0x60 | ((*hc06_ptr >> 2) & 0x0f);
|
||||
SICSLOWPAN_IP_BUF(buf)->vtc = 0x60 | ((*hc06_ptr >> 2) & 0x0f);
|
||||
SICSLOWPAN_IP_BUF(buf)->tcflow = ((*hc06_ptr << 6) & 0xC0) | ((*hc06_ptr >> 2) & 0x30);
|
||||
SICSLOWPAN_IP_BUF(buf)->flow = 0;
|
||||
hc06_ptr += 1;
|
||||
|
@ -1902,16 +1902,16 @@ input(void)
|
|||
uip_len = packetbuf_payload_len + uncomp_hdr_len;
|
||||
#endif /* SICSLOWPAN_CONF_FRAG */
|
||||
LOG_INFO("input: IP packet ready (length %d)\n",
|
||||
uip_len);
|
||||
uip_len);
|
||||
|
||||
if(LOG_DBG_ENABLED) {
|
||||
uint16_t ndx;
|
||||
LOG_DBG("after decompression %u:", UIP_IP_BUF->len[1]);
|
||||
for (ndx = 0; ndx < UIP_IP_BUF->len[1] + 40; ndx++) {
|
||||
uint8_t data = ((uint8_t *) (UIP_IP_BUF))[ndx];
|
||||
LOG_DBG("%02x", data);
|
||||
LOG_DBG_("%02x", data);
|
||||
}
|
||||
LOG_DBG("\n");
|
||||
LOG_DBG_("\n");
|
||||
}
|
||||
|
||||
/* if callback is set then set attributes and call */
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "net/mac/tsch/tsch-schedule.h"
|
||||
#include "net/mac/tsch/tsch-log.h"
|
||||
#include "net/mac/tsch/tsch-rpl.h"
|
||||
#include "net/link-stats.h"
|
||||
|
||||
#if ROUTING_CONF_RPL_LITE
|
||||
#include "net/routing/rpl-lite/rpl.h"
|
||||
|
@ -83,6 +84,11 @@ tsch_rpl_callback_joining_network(void)
|
|||
void
|
||||
tsch_rpl_callback_leaving_network(void)
|
||||
{
|
||||
/* Forget past link statistics. If we are leaving a TSCH
|
||||
network, there are changes we've been out of sync in the recent past, and
|
||||
as a result have irrelevant link statistices. */
|
||||
link_stats_reset();
|
||||
/* RPL local repair */
|
||||
NETSTACK_ROUTING.local_repair("TSCH leaving");
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -275,7 +275,7 @@ keepalive_packet_sent(void *ptr, int status, int transmissions)
|
|||
LOG_INFO_(", st %d-%d\n", status, transmissions);
|
||||
|
||||
/* We got no ack, try to recover by switching to the last neighbor we received an EB from */
|
||||
if(status != MAC_TX_OK) {
|
||||
if(status == MAC_TX_NOACK) {
|
||||
if(linkaddr_cmp(&last_eb_nbr_addr, &linkaddr_null)) {
|
||||
LOG_WARN("not able to re-synchronize, received no EB from other neighbors\n");
|
||||
if(sync_count == 0) {
|
||||
|
|
|
@ -220,7 +220,6 @@ rpl_local_repair(const char *str)
|
|||
curr_instance.dag.state = DAG_INITIALIZED; /* Reset DAG state */
|
||||
}
|
||||
curr_instance.of->reset(); /* Reset OF */
|
||||
link_stats_reset(); /* Forget past link statistics */
|
||||
rpl_neighbor_remove_all(); /* Remove all neighbors */
|
||||
rpl_timers_dio_reset("Local repair"); /* Reset Trickle timer */
|
||||
rpl_timers_schedule_state_update();
|
||||
|
|
|
@ -257,8 +257,8 @@ void
|
|||
rpl_timers_schedule_dao(void)
|
||||
{
|
||||
if(curr_instance.used && curr_instance.mop != RPL_MOP_NO_DOWNWARD_ROUTES) {
|
||||
/* No need for aggregation delay as per RFC 6550 section 9.5, as this only
|
||||
* serves storing mode. Use simply delay instead, with the only PURPOSE
|
||||
/* No need for DAO aggregation delay as per RFC 6550 section 9.5, as this
|
||||
* only serves storing mode. Use simple delay instead, with the only purpose
|
||||
* to reduce congestion. */
|
||||
clock_time_t expiration_time = RPL_DAO_DELAY / 2 + (random_rand() % (RPL_DAO_DELAY));
|
||||
/* Increment next seqno */
|
||||
|
@ -306,8 +306,10 @@ handle_dao_timer(void *ptr)
|
|||
rpl_icmp6_dao_output(curr_instance.default_lifetime);
|
||||
|
||||
#if !RPL_WITH_DAO_ACK
|
||||
/* There is DAO-ACK, schedule a refresh. Must be done after rpl_icmp6_dao_output,
|
||||
because we increment curr_instance.dag.dao_curr_seqno for the next DAO (refresh) */
|
||||
/* There is no DAO-ACK, schedule a refresh. Must be done after rpl_icmp6_dao_output,
|
||||
because we increment curr_instance.dag.dao_curr_seqno for the next DAO (refresh).
|
||||
Where there is DAO-ACK, the refresh is scheduled after reception of the ACK.
|
||||
Happens when handle_dao_timer is called again next. */
|
||||
schedule_dao_refresh();
|
||||
#endif /* !RPL_WITH_DAO_ACK */
|
||||
}
|
||||
|
|
|
@ -56,20 +56,18 @@
|
|||
|
||||
#define IPSO_INPUT_STATE 5500
|
||||
#define IPSO_INPUT_COUNTER 5501
|
||||
#define IPSO_INPUT_POLARITY 5502
|
||||
#define IPSO_INPUT_DEBOUNCE 5503
|
||||
#define IPSO_INPUT_EDGE_SEL 5504
|
||||
#define IPSO_INPUT_CTR_RESET 5505
|
||||
#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");
|
||||
|
@ -80,13 +78,12 @@ static lwm2m_status_t lwm2m_callback(lwm2m_object_instance_t *object,
|
|||
lwm2m_context_t *ctx);
|
||||
|
||||
static int input_state = 0;
|
||||
static int polarity = 0;
|
||||
static int32_t counter = 0;
|
||||
static int32_t edge_selection = 3; /* both */
|
||||
static int32_t debounce_time = 10;
|
||||
|
||||
static const lwm2m_resource_id_t resources[] = {
|
||||
RO(IPSO_INPUT_STATE), RO(IPSO_INPUT_COUNTER), RW(IPSO_INPUT_POLARITY),
|
||||
RO(IPSO_INPUT_STATE), RO(IPSO_INPUT_COUNTER),
|
||||
RW(IPSO_INPUT_DEBOUNCE), RW(IPSO_INPUT_EDGE_SEL), EX(IPSO_INPUT_CTR_RESET),
|
||||
RO(IPSO_INPUT_SENSOR_TYPE)
|
||||
};
|
||||
|
@ -104,15 +101,8 @@ static lwm2m_object_instance_t reg_object = {
|
|||
static int
|
||||
read_state(void)
|
||||
{
|
||||
int value;
|
||||
if(polarity == 0) {
|
||||
value = input_state ? 1 : 0;
|
||||
} else {
|
||||
value = input_state ? 0 : 1;
|
||||
}
|
||||
PRINTF("Read button state (polarity=%d, state=%d): %d\n",
|
||||
polarity, input_state, value);
|
||||
return value;
|
||||
PRINTF("Read button state: %d\n", input_state);
|
||||
return input_state;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -128,9 +118,6 @@ lwm2m_callback(lwm2m_object_instance_t *object,
|
|||
case IPSO_INPUT_COUNTER:
|
||||
lwm2m_object_write_int(ctx, counter);
|
||||
break;
|
||||
case IPSO_INPUT_POLARITY:
|
||||
lwm2m_object_write_int(ctx, polarity);
|
||||
break;
|
||||
case IPSO_INPUT_DEBOUNCE:
|
||||
lwm2m_object_write_int(ctx, debounce_time);
|
||||
break;
|
||||
|
@ -168,18 +155,33 @@ 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
|
||||
if(ev == button_hal_press_event) {
|
||||
input_state = 1;
|
||||
counter++;
|
||||
if((edge_selection & 2) != 0) {
|
||||
lwm2m_notify_object_observers(®_object, IPSO_INPUT_STATE);
|
||||
}
|
||||
lwm2m_notify_object_observers(®_object, IPSO_INPUT_COUNTER);
|
||||
} else if(ev == button_hal_release_event) {
|
||||
input_state = 0;
|
||||
if((edge_selection & 1) != 0) {
|
||||
lwm2m_notify_object_observers(®_object, IPSO_INPUT_STATE);
|
||||
}
|
||||
}
|
||||
#else /* PLATFORM_SUPPORTS_BUTTON_HAL */
|
||||
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 +208,7 @@ PROCESS_THREAD(ipso_button_process, ev, data)
|
|||
}
|
||||
}
|
||||
}
|
||||
#endif /* PLATFORM_SUPPORTS_BUTTON_HAL */
|
||||
}
|
||||
|
||||
PROCESS_END();
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -218,8 +218,11 @@ PT_THREAD(cmd_ping(struct pt *pt, shell_output_func output, char *args))
|
|||
|
||||
/* Get argument (remote IPv6) */
|
||||
SHELL_ARGS_NEXT(args, next_args);
|
||||
if(uiplib_ipaddrconv(args, &remote_addr) == 0) {
|
||||
SHELL_OUTPUT(output, "Invalid IPv6: %s\n", args);
|
||||
if(args == NULL) {
|
||||
SHELL_OUTPUT(output, "Destination IPv6 address is not specified\n");
|
||||
PT_EXIT(pt);
|
||||
} else if(uiplib_ipaddrconv(args, &remote_addr) == 0) {
|
||||
SHELL_OUTPUT(output, "Invalid IPv6 address: %s\n", args);
|
||||
PT_EXIT(pt);
|
||||
}
|
||||
|
||||
|
@ -334,6 +337,7 @@ PT_THREAD(cmd_help(struct pt *pt, shell_output_func output, char *args))
|
|||
|
||||
PT_END(pt);
|
||||
}
|
||||
#if UIP_CONF_IPV6_RPL
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(cmd_rpl_set_root(struct pt *pt, shell_output_func output, char *args))
|
||||
|
@ -412,6 +416,7 @@ PT_THREAD(cmd_rpl_local_repair(struct pt *pt, shell_output_func output, char *ar
|
|||
|
||||
PT_END(pt);
|
||||
}
|
||||
#endif /* UIP_CONF_IPV6_RPL */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static
|
||||
PT_THREAD(cmd_ipaddr(struct pt *pt, shell_output_func output, char *args))
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue