/*
 * Copyright 2015 Mario Richter, Peter Stephan
 * This file is part of NeMo.
 *
 * NeMo 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, either version 3 of the License, or
 * (at your option) any later version.
 *
 * NeMo 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 NeMo.  If not, see <http://www.gnu.org/licenses/>.
 */


/*!
 * \file main.h
 * \ingroup	system
 * \brief	Haupt-Headerfile des Projekts mit globalen Defines und Includes.
 */
 
#ifndef __MAIN_H__
#define __MAIN_H__

#define F_CPU 16000000UL					    /*!< Makro für den globalen Systemclock (Quarzfrequenz) */

#define SW_VERSION    "1.0.1w"        /*!< Versionsbezeichnung: MAJOR.MINOR.BUGFIX */

#include "avr/io.h"
#include "avr/interrupt.h"
#include "avr/pgmspace.h"
#include "avr/eeprom.h"
#include "util/delay.h"
#include "string.h"
#include "stdio.h" 
#include "stdlib.h"

#include "adc.h"
#include "usart.h"
#include "enc28j60.h"
#include "net.h"
#include "net_tcp.h"
#include "http.h"
#include "cmd.h"
#include "err.h"
#include "ctype.h"
#include "i2c_eeprom.h"
#include "light.h"

// Konfiguration der Debug-Ausgaben

//! Debuglevel, der beim Programmstart verwendet wird
#define DEBUGLVL_DEFAULT          (DEBUGLVL_STACK_TCP_ERROR | DEBUGLVL_STACK_TCP_INFO | DEBUGLVL_STACK_INFO | DEBUGLVL_STACK_ERROR)
#define DEBUGLVL_ALL              0xFFFF      //!< Alle Debug-Ausgaben aktiv
#define DEBUGLVL_NUL			        0x0000	    //!< Alle Debug-Ausgaben inaktiv

#define DEBUGLVL_ENC_INFO         0x0001      //!< Debuglevel: ENC28J60-Info-Meldungen ausgeben
#define DEBUGLVL_ENC_ERROR        0x0002      //!< Debuglevel: ENC28J60-Fehlermeldungen ausgeben
#define DEBUGLVL_ENC_PACKET       0x0004      //!< Debuglevel: ENC28J60-Packet-Daten ausgeben
#define DEBUGLVL_STACK_INFO       0x0008      //!< Debuglevel: Info-Meldungen des Netzwerkstacks ausgeben
#define DEBUGLVL_STACK_ERROR      0x0010      //!< Debuglevel: Fehler-Meldungen des Netzwerkstacks ausgeben
#define DEBUGLVL_STACK_TCP_INFO   0x0020      //!< Debuglevel: Info-Meldungen des TCP-Stacks ausgeben
#define DEBUGLVL_STACK_TCP_ERROR  0x0040      //!< Debuglevel: Fehler-Meldungen des TCP-Stacks ausgeben

#define IS_NUMBER(A)        (((A) >= '0') && ((A) <= '9'))
#define IS_SIGNEDNUMBER(A)  ((((A) >= '0') && ((A) <= '9')) || ((A) == '-') || ((A) == '+'))
#define IS_HEXNUMBER(A)     ((((A) >= '0') && ((A) <= '9')) || (((A) >= 'a') && ((A) <= 'f')) || (((A) >= 'A') && ((A) <= 'F')))
#define IS_CHARACTER(A)     (((A) >= 0x20) && ((A) <= 0x7E))

extern volatile uint16_t debugLevel;

#ifndef NULL
#define NULL (void *)0;
#endif

void tcpTestHandler2(uint8_t ind, uint8_t flag);

// --------------------------------------
// Timeflags 
#define TIMEFLAG_10MS             0x01        // Jeweils nur einzelne Bits, damit diese unabhängig voneinander sind
#define TIMEFLAG_100MS            0x02
#define TIMEFLAG_1S               0x04

// --------------------------------------
// LED-Ausgänge
#define LED_GRUEN_AN              { PORTA &= ~(1 << PA0); }
#define LED_GRUEN_AUS             { PORTA |=  (1 << PA0); }
#define LED_ROT_AN                { PORTA &= ~(1 << PA3); }
#define LED_ROT_AUS               { PORTA |=  (1 << PA3); }
#define LED_DUO_ROT               { PORTA |=  (1 << PA1); PORTA &= ~(1 << PA2); }
#define LED_DUO_GRUEN             { PORTA &= ~(1 << PA1); PORTA |=  (1 << PA2); }
#define LED_DUO_AUS               { PORTA |=  (1 << PA1); PORTA |=  (1 << PA2); }

// --------------------------------------
// Taster-Eingänge
#define TAST_STOP_PRESSED         !(PINA & (1 << PA5))
#define TAST_PLAY_PRESSED         !(PINA & (1 << PA6))
#define TAST_NEXT_PRESSED         !(PINA & (1 << PA7))

// OutEcho
extern volatile uint8_t outEcho;

#define OE						  0x01


// Temperatursensoren

#define HVMIN 40
#define HVMAX 60
#define HRMIN 25
#define HRMAX 60
#define WVMIN 53
#define WVMAX 63
#define WRMIN 47
#define WRMAX 57

//Bewegungsmelder

#define BPIN PINA
#define BPIN1 PINA6 

#endif

