/*
* MD_semafor.c
*
* Created: 5/6/2013 16:03:54
*  Author: Dvorkam
*/
#include "MD_semafor.h"

int Semaf_Manual(semafors* semaf){
	switch(semaf->semafory[0].lightstage){
		case RED:
		SEM1_RED_ON;
		SEM1_YELLOW_OFF;
		SEM1_GREEN_OFF;
		semaf->
		break;
		
		case GREEN:
		SEM1_GREEN_ON;
		SEM1_YELLOW_OFF;
		SEM1_RED_OFF;
		
		break;
		case ORANGE:
		SEM1_RED_ON;
		SEM1_YELLOW_ON;
		SEM1_GREEN_OFF;
		
		break;
		case YELLOW:
		SEM1_RED_OFF;
		SEM1_YELLOW_ON;
		SEM1_GREEN_OFF;	
		break;
	}
	
	switch(semaf->semafory[1].lightstage){
		case RED:
		SEM2_RED_ON;
		SEM2_YELLOW_OFF;
		SEM2_GREEN_OFF;
		break;
		
		case GREEN:
		SEM2_GREEN_ON;
		SEM2_YELLOW_OFF;
		SEM2_RED_OFF;
		
		break;
		case ORANGE:
		SEM2_RED_ON;
		SEM2_YELLOW_ON;
		SEM2_GREEN_OFF;
		
		break;
		case YELLOW:
		SEM2_RED_OFF;
		SEM2_YELLOW_ON;
		SEM2_GREEN_OFF;
		break;
	}
}
int Semaf_AutoFrac(semafors*semaf){
	switch(semaf->stage){
		case 0:
		SEM1_GREEN_ON;
		SEM2_RED_ON;
		
		SEM1_RED_OFF;
		SEM2_GREEN_OFF;
		SEM1_YELLOW_OFF;
		SEM2_YELLOW_OFF;
		semaf->stage++;
		break;
		
		case 1:
		SEM1_YELLOW_ON;
		SEM2_YELLOW_ON;
		SEM2_RED_ON;		
		SEM1_GREEN_OFF;
		semaf->stage++;
		break;
		
		case 2:
		SEM1_RED_ON;
		SEM2_GREEN_ON;
		
		SEM1_YELLOW_OFF;
		SEM2_YELLOW_OFF;
		SEM2_RED_OFF;
		semaf->stage++;

		break;
		case 3:
		SEM1_YELLOW_ON;
		SEM2_YELLOW_ON;
		
		SEM1_YELLOW_OFF;
		SEM2_GREEN_OFF;
		semaf->stage=0;
		break;
	}
	
}
int Semaf_AutoReal(semafors*semaf){
		switch(semaf->stage){
			case 0:
			semaf->time=0;
			SEM1_GREEN_ON;
			SEM2_RED_ON;
			
			SEM1_RED_OFF;
			SEM2_GREEN_OFF;
			SEM1_YELLOW_OFF;
			SEM2_YELLOW_OFF;
			semaf->stage++;
			semaf->nextstagetime = semaf->semafory[0].timing[GREEN];
			break;
			
			case 1:
			SEM1_YELLOW_ON;
			SEM1_GREEN_OFF;
			semaf->stage++;
			semaf->nextstagetime += semaf->semafory[0].timing[YELLOW];
			break;
			
			case 2:
			SEM1_RED_ON;			
			SEM1_YELLOW_OFF;
			semaf->stage++;
			semaf->nextstagetime++;
			break;
			
			case 3:
			SEM2_YELLOW_ON;
			semaf->stage++;
			semaf->nextstagetime += semaf->semafory[1].timing[ORANGE];
			break;
			
			case 4:
			SEM2_YELLOW_OFF;
			SEM2_RED_OFF;
			SEM2_GREEN_ON;
			semaf->stage++;
			semaf->nextstagetime += semaf->semafory[1].timing[GREEN];
			break;
			
			case 5:
			SEM2_GREEN_OFF;
			SEM2_YELLOW_ON;
			semaf->stage++;
			semaf->nextstagetime += semaf->semafory[1].timing[YELLOW];
			break;
			
			case 6:
			SEM2_RED_ON;
			SEM2_YELLOW_OFF;
			semaf->stage++;
			semaf->nextstagetime++;
			break;
			
			case 7:
			SEM1_YELLOW_ON;
			semaf->stage=0;
			semaf->nextstagetime += semaf->semafory[0].timing[ORANGE];
		}
}