2 * Copyright 2013 Olivier Matz <zer0@droids-corp.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <aversive/wait.h>
23 #define TX_ENABLE_BIT 2
24 #define TX_ENABLE() PORTB |= _BV(TX_ENABLE_BIT)
25 #define TX_DISABLE() PORTB &= (~_BV(TX_ENABLE_BIT))
28 #define TX_ON() PORTB |= _BV(TX_BIT)
29 #define TX_OFF() PORTB &= (~_BV(TX_BIT))
32 #define BUZZER_ON() PORTB |= _BV(BUZZER_BIT)
33 #define BUZZER_OFF() PORTB &= (~_BV(BUZZER_BIT))
35 #define BUTTON_IS_PRESSED() 0
37 /* wait new period: timer unit is us: 250 -> 4 khz */
38 static void wait_period(void)
40 static uint8_t prev = 0;
52 uint8_t button_filter = 0;
53 uint16_t time_period = 0;
54 uint32_t time_second = 0;
55 uint8_t always_on = 1;
58 /* PORTB TX/DATA out*/
59 DDRB |= (1 << TX_ENABLE_BIT) |
65 TCCR0B = (1 << CS01); /* clk/8 = 1Mhz */
70 /* buzzer at 2 Khz after 10mns if not always on */
71 if (always_on || time_second > 600) {
72 if ((time_period & 1) && (time_period < 500))
81 if (time_period < 500) {
91 /* process next time vars */
93 if (time_period >= 4000) {
100 if (BUTTON_IS_PRESSED() && button_filter < 10)
102 else if (BUTTON_IS_PRESSED() && button_filter == 10)
104 else if (!BUTTON_IS_PRESSED())
107 /* change mode if button is pressed */
111 always_on = !always_on;