Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

main.c

Go to the documentation of this file.
00001 /***
00002  * This file is part of OpenHome, an open source home automation system.
00003  * Copyright (C) 2003 Jan Klötzke
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 
00027 #include <avr/io.h>
00028 #include <avr/signal.h>
00029 #include <avr/interrupt.h>
00030 #include <avr/pgmspace.h>
00031 #include <inttypes.h>
00032 #include "main/keys.h"
00033 #include "main/lcd.h"
00034 #include "main/rom.h"
00035 #include "net/link.h"
00036 #include "net/transport.h"
00037 #include "net/application.h"
00038 #include "net/presentation.h"
00039 #include "delay.h"
00040 #include "main/menu.h"
00041 #include "main/dcf77.h"
00042 
00043 static uint8_t timer_flag, timer;
00044 static uint16_t backlight;
00045 
00051 INTERRUPT(SIG_OUTPUT_COMPARE2)
00052 {       
00053         timer++;
00054         timer_flag++;
00055         keys_sense_keys();
00056         
00057         // manage backlight
00058         if (keys_key_pressed()) {
00059                 backlight = 10000;
00060                 lcd_enable_backlight();
00061         }
00062         if (backlight > 0) {
00063                 backlight--;
00064                 if (backlight == 0) lcd_disable_backlight();
00065         }
00066 }
00067 
00068 void print_hex(uint8_t value, uint8_t x, uint8_t y)
00069 {
00070         uint8_t buf[3];
00071         uint8_t hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
00072         
00073         buf[0] = hex[value >> 4];
00074         buf[1] = hex[value & 0x0f];
00075         buf[2] = 0x00;
00076         lcd_print(x, y, 0, buf);
00077 }
00078 
00079 
00080 
00081 void print_time(void)
00082 {
00083         struct snt_time_stamp t;
00084         
00085         dcf_get_time(&t);
00086         print_hex(t.hour, 0, 0);
00087         print_hex(t.minute, 10, 0);
00088         print_hex(t.second, 20, 0);
00089 }
00090 
00091 
00097 int main(void)
00098 {
00099         // configure io-pins
00100         PORTE = 0x05;
00101         DDRD  = 0xff;
00102         DDRE  = 0x3e;
00103         
00104         // init subsystems
00105         sei();
00106         lcd_init();
00107         lnk_init();
00108         app_init();
00109         dcf_init();
00110         
00111         // configure timer 2 to 1ms
00112         // use compare match, prescaler to CLK/64
00113         OCR2 = 0x5d;
00114         TCCR2 = _BV(CTC2) | _BV(CS21) | _BV(CS20);
00115         sbi(TIMSK, OCIE2);
00116 
00117         keys_set_leds(0xff);
00118 
00119         lcd_activate();
00120         lcd_disable_backlight();
00121         
00122         menu_init();
00123         
00124         for (;;) {
00125                 while (timer_flag) {
00126                         timer_flag--;
00127                         tsp_check_timeout();
00128                 }
00129                 lnk_process();
00130                 tsp_process();
00131                 app_process();
00132                 menu_process();
00133                 dcf_process();
00134                 
00135                 if (timer == 0) print_time();
00136         }
00137         return 0;
00138 }

Generated on Thu Oct 16 13:13:41 2003 for OpenHomeMainPanel by doxygen 1.3.3