/*
 * BackgroundServicesv1.h
 *
 * Created: 6/6/2017 12:23:35 AM
 *  Author: Matic
 */ 


#ifndef BACKGROUNDSERVICESV1_H_
#define BACKGROUNDSERVICESV1_H_

#include <avr/io.h>
#include <string.h>
#include "LCD_Ili9341.h"
#include "systime.h"
#include "kbd.h"

extern int score;
extern char display;
extern volatile int xpercent;
extern volatile int ypercent;
extern char cr;
extern char ci;
extern char pad;
extern uint16_t pos_xpercent;
extern uint16_t pos_ypercent;
extern uint8_t color_krozc;
extern uint8_t color_krizc;
extern int win1;
extern int win2;

extern char board[3][3];

#define DISP_NO_CHANGE			0
#define DISP_CROSS1				LCD_DrawCross(1)
#define DISP_CROSS2				LCD_DrawCross(2)
#define DISP_CROSS3				LCD_DrawCross(3)
#define DISP_CROSS4				LCD_DrawCross(4)
#define DISP_CROSS5				LCD_DrawCross(5)
#define DISP_CROSS6				LCD_DrawCross(6)
#define DISP_CROSS7				LCD_DrawCross(7)
#define DISP_CROSS8				LCD_DrawCross(8)
#define DISP_CROSS9				LCD_DrawCross(9)
#define DISP_CIRCLE1			LCD_DrawCircle(1)
#define DISP_CIRCLE2			LCD_DrawCircle(2)
#define DISP_CIRCLE3			LCD_DrawCircle(3)
#define DISP_CIRCLE4			LCD_DrawCircle(4)
#define DISP_CIRCLE5			LCD_DrawCircle(5)
#define DISP_CIRCLE6			LCD_DrawCircle(6)
#define DISP_CIRCLE7			LCD_DrawCircle(7)
#define DISP_CIRCLE8			LCD_DrawCircle(8)
#define DISP_CIRCLE9			LCD_DrawCircle(9)	
#define DISP_PAD1				1
#define DISP_PAD2				2
#define DISP_PAD3				3
#define DISP_PAD4				4
#define DISP_PAD5				5
#define DISP_PAD6				6
#define DISP_PAD7				7
#define DISP_PAD8				8
#define DISP_PAD9				9
#define DISP_START_SCREEN		10
#define DISP_GAME_PLAY_SCREEN	11
#define DISP_END_SCREEN			12
#define DISP_PLAYER1			13
#define DISP_PLAYER2			14
#define DISP_WARNING1			LCD_DrawWarning()
#define DISP_WINNER1			15
#define DISP_WINNER2			16
#define DISP_DRAW				17
#define DISP_CAL_SCREEN			18

#define BALL_R	5
#define MAX_R	(95-1-BALL_R)
#define CENTERX 160
#define CENTERY	128

void LCD_DrawCircle(char circle_nr);
void LCD_DrawCross(char cross_nr);
void LCD_DrawPad(char pad_nr);
void LCD_DrawWarning();
void LCD_DrawPlayer(char draw_player);
void LCD_DrawWinner(char draw_winner);
void LCD_DrawDraw();
int AD_convert(char channel);
void Init_T0();
void Board_Flush();
int Pad_position();
int Winner_combos();
void Refresh_position(char pos_nr);
void BackgroundServices();
void RefreshLCD();
void DrawStartScreen();
void DrawGamePlayScreen();
void DrawGameOver();
void DrawCalScreen();

#endif /* BACKGROUNDSERVICESV1_H_ */