initial upload
This commit is contained in:
parent
32ab451fff
commit
641aad70a9
89
platform/osd-er-lp24/dev/pir-sensor.c
Normal file
89
platform/osd-er-lp24/dev/pir-sensor.c
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
/* Sensor routine */
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
#include "dev/pir-sensor.h"
|
||||||
|
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include "led.h" // debug
|
||||||
|
|
||||||
|
const struct sensors_sensor pir_sensor;
|
||||||
|
|
||||||
|
static struct timer debouncetimer;
|
||||||
|
static int status(int type);
|
||||||
|
static int enabled = 0;
|
||||||
|
struct sensors_sensor *sensors[1];
|
||||||
|
unsigned char sensors_flags[1];
|
||||||
|
|
||||||
|
#define PIR_BIT INTF6
|
||||||
|
#define PIR_CHECK_IRQ() (EIFR & PIR_BIT) ? 0 : 1
|
||||||
|
|
||||||
|
#define PRINTF(...) printf(__VA_ARGS__)
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
ISR(INT6_vect)
|
||||||
|
{
|
||||||
|
|
||||||
|
// leds_toggle(LEDS_YELLOW);
|
||||||
|
|
||||||
|
if(PIR_CHECK_IRQ()) {
|
||||||
|
if(timer_expired(&debouncetimer)) {
|
||||||
|
led1_on();
|
||||||
|
timer_set(&debouncetimer, CLOCK_SECOND / 4);
|
||||||
|
sensors_changed(&pir_sensor);
|
||||||
|
led1_off();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
static int
|
||||||
|
value(int type)
|
||||||
|
{
|
||||||
|
return (PORTE & _BV(PE6) ? 0 : 1) || !timer_expired(&debouncetimer);
|
||||||
|
//return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
configure(int type, int c)
|
||||||
|
{
|
||||||
|
PRINTF("Sensor PIR Configure called: %d, %d\n",type,c);
|
||||||
|
switch (type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
if (c) {
|
||||||
|
if(!status(SENSORS_ACTIVE)) {
|
||||||
|
led1_on();
|
||||||
|
timer_set(&debouncetimer, 0);
|
||||||
|
PRINTF("Setup sensor started\n");
|
||||||
|
DDRE |= (0<<DDE6); // Set pin as input
|
||||||
|
PORTE |= (1<<PORTE6); // Set port PORTE bint 6 with pullup resistor
|
||||||
|
EICRB |= (3<<ISC60); // For rising edge
|
||||||
|
EIMSK |= (1<<INT6); // Set int
|
||||||
|
enabled = 1;
|
||||||
|
sei();
|
||||||
|
led1_off();
|
||||||
|
}
|
||||||
|
PRINTF("Sensor EIMSK set\n");
|
||||||
|
} else {
|
||||||
|
enabled = 0;
|
||||||
|
EIMSK &= ~(1<<INT6); // clear int
|
||||||
|
PRINTF("Setup sensor failed\n");
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
status(int type)
|
||||||
|
{
|
||||||
|
switch (type) {
|
||||||
|
case SENSORS_ACTIVE:
|
||||||
|
case SENSORS_READY:
|
||||||
|
return enabled;//(EIMSK & (1<<INT6) ? 0 : 1);//PIR_IRQ_ENABLED();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SENSORS_SENSOR(pir_sensor, PIR_SENSOR,
|
||||||
|
value, configure, status);
|
||||||
|
|
48
platform/osd-er-lp24/dev/pir-sensor.h
Normal file
48
platform/osd-er-lp24/dev/pir-sensor.h
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2012, BinaryLabs.
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* @(#)$Id: battery-sensor.h,v 1.1 2012/08/25 19:34:06 nifi Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file
|
||||||
|
* PIR sensor header file for Atmega128rfa1.
|
||||||
|
* \author
|
||||||
|
* Harald Pichler <harald@the-develop.net>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __PIR_SENSOR_H__
|
||||||
|
#define __PIR_SENSOR_H__
|
||||||
|
|
||||||
|
#include "lib/sensors.h"
|
||||||
|
|
||||||
|
extern const struct sensors_sensor pir_sensor;
|
||||||
|
|
||||||
|
#define PIR_SENSOR "PIR"
|
||||||
|
|
||||||
|
#endif /* __PIR_SENSOR_H__ */
|
Loading…
Reference in a new issue