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))
36 #define BUTTON_IS_PRESSED() (!(PINB & _BV(BUTTON_BIT)))
39 #define LED_ON() PORTB |= _BV(LED_BIT)
40 #define LED_OFF() PORTB &= (~_BV(LED_BIT))
42 /* wait new period: timer unit is us: 250 -> 4 khz */
43 static void wait_period(void)
45 static uint8_t prev = 0;
57 uint8_t button_filter = 0;
58 uint16_t time_period = 0;
59 uint32_t time_second = 0;
60 uint8_t always_on = 1;
63 /* PORTB TX/DATA out*/
64 DDRB |= (1 << TX_ENABLE_BIT) |
69 PORTB |= (1 << BUTTON_BIT);
73 TCCR0B = (1 << CS01); /* clk/8 = 1Mhz */
79 /* buzzer at 2 Khz after 10mns if not always on */
80 if (always_on || time_second > 60) {
83 if (((time_second & 1) == 0) &&
95 /* radio duty cycle is 500/4000 */
96 if (time_period < 500) {
107 /* process next time vars */
109 if (time_period >= 4000) {
116 if (BUTTON_IS_PRESSED() && button_filter < 10) {
118 if (button_filter == 10)
121 else if (!BUTTON_IS_PRESSED())
124 /* change mode if button is pressed */
128 always_on = !always_on;