From 641aad70a98ed052470bf7c20f72f0174c8e8017 Mon Sep 17 00:00:00 2001 From: harald42 Date: Wed, 13 Feb 2013 15:08:55 +0100 Subject: [PATCH] initial upload --- platform/osd-er-lp24/dev/pir-sensor.c | 89 +++++++++++++++++++++++++++ platform/osd-er-lp24/dev/pir-sensor.h | 48 +++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 platform/osd-er-lp24/dev/pir-sensor.c create mode 100644 platform/osd-er-lp24/dev/pir-sensor.h diff --git a/platform/osd-er-lp24/dev/pir-sensor.c b/platform/osd-er-lp24/dev/pir-sensor.c new file mode 100644 index 000000000..78dd14eec --- /dev/null +++ b/platform/osd-er-lp24/dev/pir-sensor.c @@ -0,0 +1,89 @@ +/* Sensor routine */ + +#include "lib/sensors.h" +#include "dev/pir-sensor.h" + +#include +#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< +*/ + +#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__ */ \ No newline at end of file