/* Sensor routine */ #include "lib/sensors.h" #include "dev/button-sensor.h" #include #include "led.h" // debug const struct sensors_sensor button_sensor; static struct timer debouncetimer; static int status(int type); static int enabled = 0; volatile static int bstate; volatile static int bstatei; struct sensors_sensor *sensors[1]; unsigned char sensors_flags[1]; #define BUTTON_BIT INTF4 #define BUTTON_CHECK_IRQ() (EIFR & BUTTON_BIT) ? 0 : 1 #define PRINTF(...) printf(__VA_ARGS__) /*---------------------------------------------------------------------------*/ ISR(INT4_vect) { if(BUTTON_CHECK_IRQ()) { bstatei = (PINE & _BV(PE4) ? 0 : 1); if(timer_expired(&debouncetimer)) { // led1_on(); timer_set(&debouncetimer, CLOCK_SECOND / 16); bstate = (PINE & _BV(PE4) ? 0 : 1); if(bstate == bstatei){ sensors_changed(&button_sensor); } // led1_off(); } } } /*---------------------------------------------------------------------------*/ static int value(int type) { //return (PINE & _BV(PE4) ? 0 : 1) || !timer_expired(&debouncetimer); return bstate; } static int configure(int type, int c) { switch (type) { case SENSORS_ACTIVE: if (c) { if(!status(SENSORS_ACTIVE)) { // led1_on(); timer_set(&debouncetimer, 0); DDRE |= (0<