#ifndef MAIN_H
#define MAIN_H

#include <windows.h>
#include "resource.h"
#include "tserial.h"
#include "gps.h"
#include <tchar.h>
#include <stdlib.h>
#include <commctrl.h>
#include <math.h>
#include <process.h>

// volba prostredi
//#define OUTDOOR
#define INDOOR

//ladeni programu 
//#define TEST

//Zvukova signalizace
//tony
#define HIGH 2000
#define LOW 500
#define SHORT 300
#define LONG 500
//morzeovka
#define MALA 50
#define MEZERA 150
#define TECKA 50
#define CARKA 150


#define _MainClassName TEXT("RoboKopMainClass")
#define _AppName TEXT("ROBO-KOP")
#define _TimerClock 1
#define STEP 20
#define MAX_SPEED 255

#define LOW_VOLTAGE 22 //hodnota maleho napeti baterii ve V
#define LOWLOW_VOLTAGE 20 //hodnota nizkeho napeti baterii ve V
#define LOWVOLT_LIMIT 3	//cas za ktery se robot vypne pri nizkem napeti, perioda kontroly napeti 2 s
#define GPS_DEAD_ANGLE 20	//necitlivost navigace GPS a kompasu

#define DELAY_DRIVE_IN 10 //prodleva vláken v ms	
#define DELAY_DRIVE_OUT 10 //prodleva vláken v ms	
#define DELAY_SUPERSONIC 10 //prodleva vláken v ms
#define DELAY_COMPASS 10 //prodleva vláken v ms


#ifdef INDOOR
#define AUT_SPEED_1 60	//rychlost jizdy vpred v aut rezimu
#define AUT_SPEED_2 40	//rychlost otaceni a couvani	

#define PROV_VZD 50		//v indoor rezimu stejne
#define VYHYBACI_VZD 50	//v indoor rezimu stejne

#define PRUJEZDNA_VZD 55
#define MIN_VZD 35
#define SLEPA_VZD 30
#endif

#ifdef OUTDOOR
#define AUT_SPEED_1 80	//jine pro jina prostredi
#define AUT_SPEED_2 40

#define PROV_VZD 60
#define VYHYBACI_VZD 70	//objizdeni vzdalenejsich prekazek

#define PRUJEZDNA_VZD 55
#define MIN_VZD 40
#define SLEPA_VZD 35
#endif

HINSTANCE g_hInstance;
HWND g_hwndMain;
HWND g_hwndMan;
HWND g_hwndAut;
HWND g_hwndEdit;
HWND g_hwndStatusBar;

HANDLE hThreadUltrasonic;	// handle na vlakno
HANDLE hThreadDrive;	
HANDLE hThreadDrive2;
HANDLE hThreadSound;
HANDLE hThreadCompass;
HANDLE hThreadGPS;

DWORD idThreadUltrasonic;
DWORD idThreadDrive;
DWORD idThreadDrive2;
DWORD idThreadSound;
DWORD idThreadCompass;
DWORD idThreadGPS;

int g_iDriveErr = 1;
int g_iUltrasonicErr = 1;
int g_iCompassErr = 1;
int g_iGPS1Err = 1;
int g_iGPS2Err = 1;

int g_iuzA = 0;
int g_iuzB = 0;
int g_iuzC = 0;

int g_iX = 0;
int g_iY = 0;
int g_iZ = 0;

int g_iSpeedA = 0;
int g_iSpeedB = 0;
int g_iAngleAct = 180;
int g_iAngleReq = 180;

int g_iSpeedCamA = 0;
int g_iSpeedCamB = 0;

int g_iStat = 0;		//stav v jakem se nachazi robot pri zataceni
int g_iStatUs = 0;		//stav robotu pri objizdeni prekazky podle ultrazvuku
int g_iCam = 0;

double g_fVoltage = 24.0;


bool g_bStop = false;
bool g_bManual = true;
bool g_bSend = true;
bool g_bEnd = false;
bool g_bLowVoltEnabled = true;

#ifdef INDOOR
bool g_bCamEnabled = false;
bool g_bGPSEnabled = false;
#else
bool g_bCamEnabled = true;
bool g_bGPSEnabled = true;
#endif

char g_chStat[20] = "Chyba!";
char g_chMode[20]="Manuální     ";
char g_chBufferDriveSend[20];
char g_chBufferDriveIn[6] = "00000";
char g_chMelody = 'k';

char precteno_gps[63] = " ";
char precteno_gps2[63] = " ";

char g_chFlagDir = 'U';	//priznak predchazejiciho smeru pri manualnim ovladani

char g_chSignDriveA = '+';
char g_chSignDriveB = '+';

char g_chSignCamA = '+';
char g_chSignCamB = '+';

char g_chtest[6] = " ";


Tserial *g_tsUltrasonic;
Tserial *g_tsDrive;
Tserial *g_tsCompass;
Tserial *g_tsGPS1;
Tserial *g_tsGPS2;



#endif