/*
 * MD_semafor.h
 *
 * Created: 5/6/2013 16:03:37
 *  Author: Dvorkam
 */ 


#ifndef MD_SEMAFOR_H_
#define MD_SEMAFOR_H_
#define SEM1_RED (1<<PD7)
#define SEM1_YELLOW (1<<PD6)
#define SEM1_GREEN (1<<PD5)
#define SEM2_RED (1<<PB2)
#define SEM2_YELLOW (1<<PB1)
#define SEM2_GREEN (1<<PB0)

#define SEM1_RED_ON PORTD|= (1<<PD7)
#define SEM1_YELLOW_ON PORTD|= (1<<PD6)
#define SEM1_GREEN_ON PORTD|= (1<<PD5)
#define SEM2_RED_ON PORTB|= (1<<PB2)
#define SEM2_YELLOW_ON PORTB|= (1<<PB1)
#define SEM2_GREEN_ON PORTB|= (1<<PB0)

#define SEM1_RED_OFF PORTD&= ~(1<<PD7)
#define SEM1_YELLOW_OFF PORTD&= ~(1<<PD6)
#define SEM1_GREEN_OFF PORTD&= ~(1<<PD5)
#define SEM2_RED_OFF PORTB&= ~(1<<PB2)
#define SEM2_YELLOW_OFF PORTB&= ~(1<<PB1)
#define SEM2_GREEN_OFF PORTB&= ~(1<<PB0)

#define RED 2
#define GREEN 0
#define YELLOW 1
#define ORANGE 3

#define MANUAL 0 
#define AUTO_REAL 1 
#define AUTO_FRAC 2

typedef struct SEMAF{
	uint8_t lightstage; //Green/yellow/red/orange
	uint8_t timing[4];  //length for individual lights
}semafor;

typedef struct SEMAFORS{
	semafor semafory[2];	//only 2 traffic light needed
	uint8_t mode;			//Manual/autoreal/autoFrac
	uint8_t stage;			//0-8 for AutoReal or 0-4 autoFrac
	uint8_t nextstagetime;
	uint8_t time;
	}semafors;
	
#endif /* MD_SEMAFOR_H_ */

int Semaf_Manual(void);
int Semaf_AutoFrac(semafors*);
int Semaf_AutoReal(semafors*);