#include <util/delay.h>

#include "display.h"

void delay(uint16_t ms){
	uint16_t i;
   	for(i=0; i < ms;i++){
		_delay_ms(10);
	}	   
}

void waitForSignal(uint16_t time){
	static uint8_t counter=6;
	static uint16_t timeScaler=1;
	if(time > timeScaler){
		timeScaler++;
		return;
	}
	timeScaler=0;
	if(counter < 6){
		ShowNumber(1<<counter,0,0,0);
	}
	if(counter == 6){
		ShowNumber(0,32,0,0);
	}
	if(counter == 7){
		ShowNumber(0,0,32,0);
	}
	if(counter > 7 && counter < 14){
		ShowNumber(0, 0, 0, 32>>(counter-8));
	}
	if(counter == 14){
		ShowNumber(0,0,1,0);
	}
	if(counter == 15){
		ShowNumber(0,1,0,0);
		counter = 0;
	}
	else{
		counter++;
	}
}

void checkUpDisplay(){
		uint8_t checkUp[] = {1,3,7,15,31,63};
		uint8_t i,sleepTime=250;

		ShowNumber(0,0,0,0);
		for(i=0 ;i < sizeof(checkUp) / checkUp[0];i++){
			delay(sleepTime);
			ShowNumber(i>0 ? checkUp[i-1]:0, i>0 ? checkUp[i-1]:0, i>0 ? checkUp[i-1]:0, checkUp[i]);
			delay(sleepTime);
			ShowNumber(i>0 ? checkUp[i-1]:0, i>0 ? checkUp[i-1]:0, checkUp[i], checkUp[i]);
			delay(sleepTime);
			ShowNumber(i>0 ? checkUp[i-1]:0, checkUp[i], checkUp[i], checkUp[i]);
			delay(sleepTime);
			ShowNumber(checkUp[i], checkUp[i], checkUp[i], checkUp[i]);
		}
		for(i=0;i< sizeof(checkUp)/checkUp[0];i++){
			delay(sleepTime);
			ShowNumber(63 - ( i > 0 ? checkUp[i-1]:0), 63 - ( i > 0 ? checkUp[i-1]:0), 63 - ( i > 0 ? checkUp[i-1]:0), 63 - checkUp[i]);
			delay(sleepTime);
			ShowNumber(63 - ( i > 0 ? checkUp[i-1]:0), 63 - ( i > 0 ? checkUp[i-1]:0), 63 - checkUp[i], 63 - checkUp[i]);
			delay(sleepTime);
			ShowNumber(63 - ( i > 0 ? checkUp[i-1]:0), 63 - checkUp[i], 63 - checkUp[i], 63 - checkUp[i]);
			delay(sleepTime);
			ShowNumber(63 - checkUp[i], 63 - checkUp[i], 63 - checkUp[i], 63 - checkUp[i]);
		}
}
// vim:ts=4
