add button sensor with debug
This commit is contained in:
parent
48217bcf80
commit
356ea01a8d
|
@ -45,15 +45,15 @@
|
||||||
|
|
||||||
/* Define which resources to include to meet memory constraints. */
|
/* Define which resources to include to meet memory constraints. */
|
||||||
#define REST_RES_INFO 1
|
#define REST_RES_INFO 1
|
||||||
#define REST_RES_DS1820 1
|
#define REST_RES_DS1820 0
|
||||||
#define REST_RES_DHT11 1
|
#define REST_RES_DHT11 0
|
||||||
#define REST_RES_TEMPERATURE 1
|
#define REST_RES_TEMPERATURE 0
|
||||||
#define REST_RES_HELLO 0
|
#define REST_RES_HELLO 0
|
||||||
#define REST_RES_MIRROR 0 /* causes largest code size */
|
#define REST_RES_MIRROR 0 /* causes largest code size */
|
||||||
#define REST_RES_CHUNKS 0
|
#define REST_RES_CHUNKS 0
|
||||||
#define REST_RES_SEPARATE 0
|
#define REST_RES_SEPARATE 0
|
||||||
#define REST_RES_PUSHING 0
|
#define REST_RES_PUSHING 0
|
||||||
#define REST_RES_EVENT 0
|
#define REST_RES_EVENT 1
|
||||||
#define REST_RES_SUB 0
|
#define REST_RES_SUB 0
|
||||||
#define REST_RES_LEDS 0
|
#define REST_RES_LEDS 0
|
||||||
#define REST_RES_TOGGLE 0
|
#define REST_RES_TOGGLE 0
|
||||||
|
@ -765,7 +765,7 @@ pushing_periodic_handler(resource_t *r)
|
||||||
* Additionally takes a period parameter that defines the interval to call [name]_periodic_handler().
|
* Additionally takes a period parameter that defines the interval to call [name]_periodic_handler().
|
||||||
* A default post_handler takes care of subscriptions and manages a list of subscribers to notify.
|
* A default post_handler takes care of subscriptions and manages a list of subscribers to notify.
|
||||||
*/
|
*/
|
||||||
EVENT_RESOURCE(event, METHOD_GET, "sensors/button", "title=\"Event demo\";obs");
|
EVENT_RESOURCE(event, METHOD_GET, "sensors/pir", "title=\"Event demo\";obs");
|
||||||
|
|
||||||
void
|
void
|
||||||
event_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
event_handler(void* request, void* response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset)
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
/* Dummy sensor routine */
|
|
||||||
|
|
||||||
#include "lib/sensors.h"
|
|
||||||
#include "dev/button-sensor.h"
|
|
||||||
const struct sensors_sensor button_sensor;
|
|
||||||
static int status(int type);
|
|
||||||
struct sensors_sensor *sensors[1];
|
|
||||||
unsigned char sensors_flags[1];
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
value(int type)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
configure(int type, int c)
|
|
||||||
{
|
|
||||||
switch (type) {
|
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
if (c) {
|
|
||||||
if(!status(SENSORS_ACTIVE)) {
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
status(int type)
|
|
||||||
{
|
|
||||||
switch (type) {
|
|
||||||
case SENSORS_ACTIVE:
|
|
||||||
case SENSORS_READY:
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
|
|
||||||
value, configure, status);
|
|
||||||
|
|
|
@ -1,56 +1,20 @@
|
||||||
/*
|
/* Sensor routine */
|
||||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* This file is part of the Contiki operating system.
|
|
||||||
*
|
|
||||||
* @(#)$Id: button-sensor.c,v 1.4 2010/01/14 20:01:19 nifi Exp $
|
|
||||||
*/
|
|
||||||
#include "contiki.h"
|
|
||||||
#include "lib/sensors.h"
|
#include "lib/sensors.h"
|
||||||
#include "dev/button-sensor.h"
|
#include "dev/button-sensor.h"
|
||||||
//#include "dev/leds.h"
|
|
||||||
|
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
#include "led.h" // debug
|
||||||
//#include "dev/hwconf.h"
|
|
||||||
//#include "isr_compat.h"
|
|
||||||
|
|
||||||
const struct sensors_sensor button_sensor;
|
const struct sensors_sensor button_sensor;
|
||||||
|
|
||||||
static struct timer debouncetimer;
|
static struct timer debouncetimer;
|
||||||
static int status(int type);
|
static int status(int type);
|
||||||
|
|
||||||
static int enabled = 0;
|
static int enabled = 0;
|
||||||
|
struct sensors_sensor *sensors[1];
|
||||||
|
unsigned char sensors_flags[1];
|
||||||
|
|
||||||
//HWCONF_PIN(BUTTON, 2, 7);
|
#define BUTTON_BIT INTF6
|
||||||
//HWCONF_IRQ(BUTTON, 2, 7);
|
|
||||||
|
|
||||||
#define BUTTON_BIT INTF5
|
|
||||||
#define BUTTON_CHECK_IRQ() (EIFR & BUTTON_BIT) ? 0 : 1
|
#define BUTTON_CHECK_IRQ() (EIFR & BUTTON_BIT) ? 0 : 1
|
||||||
|
|
||||||
#define PRINTF(...) printf(__VA_ARGS__)
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
@ -62,63 +26,64 @@ ISR(INT6_vect)
|
||||||
|
|
||||||
if(BUTTON_CHECK_IRQ()) {
|
if(BUTTON_CHECK_IRQ()) {
|
||||||
if(timer_expired(&debouncetimer)) {
|
if(timer_expired(&debouncetimer)) {
|
||||||
|
led1_on();
|
||||||
timer_set(&debouncetimer, CLOCK_SECOND / 4);
|
timer_set(&debouncetimer, CLOCK_SECOND / 4);
|
||||||
sensors_changed(&button_sensor);
|
sensors_changed(&button_sensor);
|
||||||
|
led1_off();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static int value(int type)
|
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
{
|
{
|
||||||
return (PORTE & _BV(PE5) ? 0 : 1) || !timer_expired(&debouncetimer);
|
return (PORTE & _BV(PE6) ? 0 : 1) || !timer_expired(&debouncetimer);
|
||||||
|
//return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static int configure(int type, int c)
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
{
|
{
|
||||||
PRINTF("Sensor Button Configure called: %d, %d\n",type,c);
|
PRINTF("Sensor Button Configure called: %d, %d\n",type,c);
|
||||||
|
switch (type) {
|
||||||
switch (type) {
|
case SENSORS_ACTIVE:
|
||||||
case SENSORS_ACTIVE:
|
if (c) {
|
||||||
if (c) {
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
if(!status(SENSORS_ACTIVE)) {
|
led1_on();
|
||||||
timer_set(&debouncetimer, 0);
|
timer_set(&debouncetimer, 0);
|
||||||
|
PRINTF("Setup sensor started\n");
|
||||||
PRINTF("Setup sensor started\n");
|
DDRE |= (0<<DDE6); // Set pin as input
|
||||||
|
PORTE |= (1<<PORTE6); // Set port PORTE bint 6 with pullup resistor
|
||||||
DDRE |= (0<<DDE6); // Set pin as input
|
EICRB |= (2<<ISC60); // For falling edge
|
||||||
PORTE |= (1<<PORTE6); // Set port PORTE bint 5 with pullup resistor
|
EIMSK |= (1<<INT6); // Set int
|
||||||
EICRB |= (2<<ISC60); // For falling edge
|
enabled = 1;
|
||||||
|
sei();
|
||||||
//BUTTON_SELECT();
|
led1_off();
|
||||||
|
}
|
||||||
//leds_on(LEDS_RED);
|
PRINTF("Sensor EIMSK set\n");
|
||||||
EIMSK |= (1<<INT6); // Set int
|
} else {
|
||||||
enabled = 1;
|
enabled = 0;
|
||||||
sei();
|
EIMSK &= ~(1<<INT6); // clear int
|
||||||
}
|
PRINTF("Setup sensor failed\n");
|
||||||
PRINTF("Sensor EIMSK set\n");
|
}
|
||||||
} else {
|
return 1;
|
||||||
enabled = 0;
|
}
|
||||||
EIMSK &= ~(1<<INT6); // clear int
|
return 0;
|
||||||
//leds_off(LEDS_RED);
|
|
||||||
PRINTF("Setup sensor failed\n");
|
|
||||||
}
|
}
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
static int
|
static int
|
||||||
status(int type)
|
status(int type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SENSORS_ACTIVE:
|
case SENSORS_ACTIVE:
|
||||||
case SENSORS_READY:
|
case SENSORS_READY:
|
||||||
return enabled;//(EIMSK & (1<<INT5) ? 0 : 1);//BUTTON_IRQ_ENABLED();
|
return enabled;//(EIMSK & (1<<INT6) ? 0 : 1);//BUTTON_IRQ_ENABLED();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
|
||||||
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR, value, configure, status);
|
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
|
||||||
|
value, configure, status);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue