/*************************************************************************** * Copyright (C) 11/2014 by Olaf Rempel * * razzor@kopf-tisch.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; version 2 of the License, * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include #include #include "event.h" #include "input.h" #include "timer.h" /* *********************************************************************** */ #define INPUT_DEBOUNCE_TIMER 60 /* *********************************************************************** */ static uint8_t pcint_old; static uint8_t quad_state; static uint8_t quad_state_old; static uint8_t debounce_timer[2]; static uint8_t input_old_state[2]; /* *********************************************************************** */ static void input_send_event(uint8_t type, uint8_t num, uint8_t state) { if ((debounce_timer[num] == 0) && (state != input_old_state[num]) ) { debounce_timer[num] = 1; event_queue(type, num, state); event_queue(EVENT_TYPE_TIMER_SET, num, INPUT_DEBOUNCE_TIMER); input_old_state[num] = state; } } /* input_send_event */ ISR(PCINT1_vect) { uint8_t pcint_new = PINC & PCMSK1; uint8_t pcint = pcint_new ^ pcint_old; uint8_t quad_state_new = quad_state; /* quadruple decoder A changed */ if (pcint & (1<type == EVENT_TYPE_TIMER_ELAPSED) { if (event->num == EVENT_NUM_TIMER_DEBOUNCE1) { debounce_timer[EVENT_NUM_INPUT_BUTTON] = 0; input_send_event(EVENT_TYPE_INPUT_SWITCH, EVENT_NUM_INPUT_BUTTON, !!(PINC & (1<num == EVENT_NUM_TIMER_DEBOUNCE2) { debounce_timer[EVENT_NUM_INPUT_DOOR] = 0; input_send_event(EVENT_TYPE_INPUT_SWITCH, EVENT_NUM_INPUT_DOOR, !!(PINC & (1<