/* start the main program */
void main() 
{
   UART_Init(9600);
   UART_TxString("\n\rTest menu Utra x51 v1.1\r\n 1:GPIO Blink\r\n 2:LCD \n\r 3:7-Segment\n\r 4:RTC\n\r 5:EEPROM\n\r 6:ADC\n\r 7:Keypad \n\r Enter option:");
   UART_TxString("\n\rReset the board after test is done");
   mm_option = UART_RxChar();
   while(1)
    {
 	  	switch(mm_option)
		{
		 case '1': gpio_test(); break;
		 case '2': LCD_test(); break;
		 case '3': seg_test(); break;
		 case '4': rtc_test(); break; 
		 case '5': eeprom_test(); break; //eeprom
		 case '6': adc_test(); break;
		 case '7': keypad_test();break;
		 default:break;
		}
	}
}
void Interpreter(void)    // just a prototype, link to your interpreter
{
	uint32_t stringSize;
	uint32_t adcVoltage;
	uint8_t deviceChosen;
	uint8_t taskAddedBefore = 0;
	uint8_t commandChosen = -1;
	char message[MESSAGELENGTH] = "";
	OutCRLF();
	UART_OutString("Input Command: ");
	while(1){
		OutCRLF();
		//UART_OutString("Commands: 0 - ADC, 1 - LCD, 2 - Time");
		OutCRLF();
		commandChosen = UART_InChar();
		switch(commandChosen)
		{
			case '0':
				OutCRLF();
				UART_OutString("ADC Voltage = ");
				//ADC_Open(4);
				adcVoltage = (ADC_In() *3300) / 4095; //convert to mV
				UART_OutUDec(adcVoltage);
				OutCRLF();
				break;
			case '1':
				OutCRLF();
				UART_OutString("Enter LCD device 0 or 1: ");
				deviceChosen = UART_InUDec();
				OutCRLF();
				UART_OutString("Enter message: ");
				UART_InString(message, MESSAGELENGTH);
				OutCRLF();
				stringSize = strlen(message);
				if(stringSize > 20)
				{
					OutCRLF();
					UART_OutString("String too long...");
					OutCRLF();
				}
				LCD_test(deviceChosen, message); //prints to lcd
				OutCRLF();
				break;
			case '2':
				if(!taskAddedBefore){
					OS_AddPeriodicThread(dummy, 5, 1);
					taskAddedBefore = 1;
				}
				OutCRLF();
				UART_OutUDec(OS_ReadPeriodicTime());
				OutCRLF();
				break;
			case '3':
				UART_OutString("NumSamples: ");
				UART_OutUDec(NumSamples);
				OutCRLF();
				break;
			case '4':
				UART_OutString("Jitter: ");
				UART_OutUDec(MaxJitter);
				OutCRLF();
				break;
			case '5':
				UART_OutString("DataLost: ");
				UART_OutUDec(DataLost);
				OutCRLF();
				break;
			case '6':
				UART_OutString("FilterWork: ");
				UART_OutUDec(FilterWork);
				OutCRLF();
				break;
			case '7':
				UART_OutString("NumCreated: ");
				UART_OutUDec(NumCreated);
				OutCRLF();
				break;
			case '8':
				for(int i = 0; i<64; i++)
				{
					UART_OutUDec(x[i]);
					OutCRLF();
				}
				break;
			default:
				UART_OutString("Incorrect command!");
				break;
		}

		//adcSample = ADC_In();
		//ST7735_SetCursor(0,0);
		//ST7735_OutUDec(adcSample);
	
	}
}