Added support for digital presence/motion sensors
This commit is contained in:
parent
48eb2a4fe2
commit
c644a32dc7
5 changed files with 315 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
|||
DEFINES+=PROJECT_CONF_H=\"project-conf.h\"
|
||||
CONTIKI_PROJECT = zoul-demo test-tsl2563 test-sht25 test-pwm test-power-mgmt
|
||||
CONTIKI_PROJECT += test-bmp085
|
||||
CONTIKI_TARGET_SOURCEFILES += tsl2563.c sht25.c bmp085.c
|
||||
CONTIKI_PROJECT += test-bmp085 test-motion
|
||||
CONTIKI_TARGET_SOURCEFILES += tsl2563.c sht25.c bmp085.c motion-sensor.c
|
||||
|
||||
all: $(CONTIKI_PROJECT)
|
||||
|
||||
|
|
|
@ -41,6 +41,13 @@
|
|||
#define BROADCAST_CHANNEL 129
|
||||
#define NETSTACK_CONF_RDC nullrdc_driver
|
||||
|
||||
/* Pin definition for the test-motion example, for the RE-Mote it uses the
|
||||
* ADC1 pin
|
||||
*/
|
||||
#define MOTION_SENSOR_PORT GPIO_A_NUM
|
||||
#define MOTION_SENSOR_PIN 5
|
||||
#define MOTION_SENSOR_VECTOR NVIC_INT_GPIO_PORT_A
|
||||
|
||||
#endif /* PROJECT_CONF_H_ */
|
||||
|
||||
/** @} */
|
||||
|
|
102
examples/zolertia/zoul/test-motion.c
Normal file
102
examples/zolertia/zoul/test-motion.c
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright (c) 2016, Zolertia - http://www.zolertia.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 Institute 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 INSTITUTE 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 INSTITUTE 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-examples
|
||||
* @{
|
||||
*
|
||||
* \defgroup zoul-motion-test Digital motion sensor test
|
||||
*
|
||||
* The example application shows how to use any digital motion sensor, basically
|
||||
* driving a signal high when motion is detected.
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Test application for the digital motion/presence sensor
|
||||
*
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki.h"
|
||||
#include "cpu.h"
|
||||
#include "sys/rtimer.h"
|
||||
#include "dev/leds.h"
|
||||
#include "dev/motion-sensor.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define LEDS_OFF_HYSTERISIS RTIMER_SECOND
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static struct rtimer rt;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(test_presence_sensor, "Test digital motion sensor");
|
||||
AUTOSTART_PROCESSES(&test_presence_sensor);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
rt_callback(struct rtimer *t, void *ptr)
|
||||
{
|
||||
leds_off(LEDS_RED);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
presence_callback(uint8_t value)
|
||||
{
|
||||
printf("*** Presence detected!\n");
|
||||
leds_on(LEDS_RED);
|
||||
rtimer_set(&rt, RTIMER_NOW() + LEDS_OFF_HYSTERISIS, 1, rt_callback, NULL);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(test_presence_sensor, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
/* Register the callback handler when presence is detected */
|
||||
MOTION_REGISTER_INT(presence_callback);
|
||||
|
||||
/* Enable the sensor, as default it assumes the signal pin has a pull-down
|
||||
* resistor and a rising interrupt (signal goes high when motion is detected),
|
||||
* this is the case of the Grove's PIR sensor v.1.0. If the sensor has an
|
||||
* inverse logic, change at the motion-sensor.c driver file
|
||||
* GPIO_DETECT_FALLING instead of GPIO_DETECT_RISING if using an external
|
||||
* pull-up resistor
|
||||
*/
|
||||
SENSORS_ACTIVATE(motion_sensor);
|
||||
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
* @}
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue