Exemplo n.º 1
0
/******************************************************

***┏┓           ┏┓
**┏┛┻━━━━━━━━━━━┛┻┓
**┃               ┃
**┃      ━━━      ┃
**┃  ┳┛       ┗┳  ┃
**┃               ┃
**┃ '''   ┻   ''' ┃
**┃               ┃
**┗━━━┓       ┏━━━┛
******┃       ┃
******┃       ┃
******┃       ┃
******┃       ┗━━━━━━━━━━━━┓
******┃                    ┃━━┓
******┃      NO BUG        ┏━━┛
******┃                    ┃
******┗━┓  ┓  ┏━━━━┏━━┓  ━━┛
********┃  ┛  ┛    ┃  ┛  ┛
********┃  ┃  ┃    ┃  ┃  ┃
********┗━━┛━━┛    ┗━━┛━━┛

This part is added by project ESDC2014 of CUHK team.
All the code with this header are under GPL open source license.
******************************************************/
int Omni4WD::setCarRotateLeftDegree(float degree, int speedMMPS)
{
	setCarStat(STAT_ROTATELEFT);
    
	float pi = 3.1415926;
	int d = 500; //mm
    int ms = round(((degree * pi * d / 360) / speedMMPS) * 1000);
    
	wheelULSetSpeedMMPS(-speedMMPS);
	wheelLRSetSpeedMMPS(-speedMMPS);
	wheelLLSetSpeedMMPS(-speedMMPS);
	wheelURSetSpeedMMPS(-speedMMPS);
    
	delayMS(ms);

	setCarStop();
}
Exemplo n.º 2
0
int Omni4WD::setCarSpeedMMPS(int speedMMPS,unsigned int ms) {
	unsigned int carStat=getCarStat();
	int currSpeed=getCarSpeedMMPS();

	int (Omni4WD::*carAction)(int speedMMPS);
	switch(carStat) {
		case STAT_UNKNOWN:	// no break here
		case STAT_STOP:
			return currSpeed;
		case STAT_ADVANCE:
			carAction=&Omni4WD::setCarAdvance; break;
		case STAT_BACKOFF:
			carAction=&Omni4WD::setCarBackoff; break;
		case STAT_LEFT:
			carAction=&Omni4WD::setCarLeft; break;
		case STAT_RIGHT:
			carAction=&Omni4WD::setCarRight; break;
		case STAT_ROTATELEFT:
			carAction=&Omni4WD::setCarRotateLeft; break;
		case STAT_ROTATERIGHT:
			carAction=&Omni4WD::setCarRotateRight; break;
		case STAT_UPPERLEFT:
			carAction=&Omni4WD::setCarUpperLeft; break;
		case STAT_LOWERLEFT:
			carAction=&Omni4WD::setCarLowerLeft; break;
		case STAT_LOWERRIGHT:
			carAction=&Omni4WD::setCarLowerRight; break;
		case STAT_UPPERRIGHT:
			carAction=&Omni4WD::setCarUpperRight; break;
	}

	if(ms<100 || abs(speedMMPS-currSpeed)<10) {
		(this->*carAction)(speedMMPS);
		return getCarSpeedMMPS();
	}

	for(int time=20,speed=currSpeed;time<=ms;time+=20) {
		speed=map(time,0,ms,currSpeed,speedMMPS);
		(this->*carAction)(speed);
		delayMS(20);
	}

	(this->*carAction)(speedMMPS);
	return getCarSpeedMMPS();
}
Exemplo n.º 3
0
static long sendAPDU(SCARDHANDLE hCard, const char *apdu,
	unsigned char *recvBuf, DWORD *recvBufLen,
	const char *chipNr, int idx, bool doDump)
{
	unsigned char sendBuf[280];
	size_t        sendBufLen = sizeof(sendBuf);

	// Hex string -> byte array
	if (0 == hex2bin(apdu, sendBuf, &sendBufLen))
	{
		// Check the APDU
		if (sendBufLen < 4)
			printf("ERR: APDU should be at least 4 bytes\n");
		else if (sendBufLen > 5 && ((size_t) (5 + sendBuf[4]) != sendBufLen))
			printf("ERR: wrong P3 byte in case 3 APDU\n");
		else
		{
			if (doDump)
				dumphex("  - sending ", sendBuf, sendBufLen);

			delayMS(50);

			long ret = SCardTransmit(hCard,
				&g_rgSCardT0Pci, sendBuf, (DWORD) sendBufLen,
				NULL, recvBuf, recvBufLen);
			CHECK_PCSC_RET("SCardTransmit", ret);

			if (SCARD_S_SUCCESS == ret)
			{
				if (doDump)
				{
					dumphex("    received ", recvBuf, *recvBufLen);
					printf("\n");
				}

				if (NULL != chipNr)
					StoreAPDUs(chipNr, idx, sendBuf, sendBufLen, recvBuf, *recvBufLen);

				return 0; // success
			}
		}
	}

	return -1; // failed
}
Exemplo n.º 4
0
void doGame(void)
{
	isPause = 0;
	while (!isOver)
	{
		if (!isPause)
    {
		moveSnake();
		if (!isFood)            
			drawFood();
    }
    delayMS(ms - snakeLength*2);
    if (jkHasKey()) ///异步检测按键
    {
		switch (jkGetKey())
		{
			case JK_UP:
				if (snakeDir != DIR_DOWN)
				snakeDir = DIR_UP;
			break;
			case JK_DOWN:
				if (snakeDir != DIR_UP)
				snakeDir = DIR_DOWN;
			break;
			case JK_LEFT:
				if (snakeDir != DIR_RIGHT)
				snakeDir = DIR_LEFT;
			break;
			case JK_RIGHT:
				if (snakeDir != DIR_LEFT)
				snakeDir = DIR_RIGHT;
			break;
			case JK_ESC: //游戏结束
				isOver = !isOver;
			break;
			case JK_SPACE: //暂停
				isPause = !isPause;
				break;
			default:
			break;
      }
    }
  }
}
Exemplo n.º 5
0
static int testTransaction(SCARDCONTEXT ctx, const char *readerName)
{
	int         returnValue = 0;
	SCARDHANDLE hCard;
	DWORD       protocol;

	long        ret = SCardConnectA(ctx, readerName,
		SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &protocol);
	CHECK_PCSC_RET_PASS(0x1) //-------1
	if (SCARD_S_SUCCESS == ret)
	{
		delayMS(200);

		ret = SCardBeginTransaction(hCard);
		CHECK_PCSC_RET_PASS(0x2) //------1-
		ret = SCardEndTransaction(hCard, SCARD_LEAVE_CARD);
		CHECK_PCSC_RET_PASS(0x2) //-----1--
		ret = SCardEndTransaction(1111, SCARD_LEAVE_CARD);
		CHECK_PCSC_RET_FAIL(0x2) //-----1--
	}
Exemplo n.º 6
0
/*********************************************************************************************
函数名:bsp_sendDate_595
作  用: 串行发送数据,按位发送
参  数:要发送的数据
返回值:无
**********************************************************************************************/
void bsp_sendDate_595(unsigned char date)
{
	unsigned char i;

	for(i = 8; i > 0; i--)
	{
		if((date >> (i - 1)) & 0x01)
		{
			HC595_SI = 1;
		}
		else
		{
			HC595_SI = 0;
		}

		//上升发送
		HC595_SCK = 0;
		delayMS(2);
		
		
		HC595_SCK = 1;
	}
Exemplo n.º 7
0
static int testConnect(SCARDCONTEXT ctx, const char *readerName)
{
	int         returnValue = 0;
	SCARDHANDLE hCard;
	DWORD       protocol;

	long        ret = SCardConnectA(ctx, readerName,
		SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &protocol);

	if (SCARD_S_SUCCESS != ret)
		returnValue |= 0x1; //-------1

	if (SCARD_S_SUCCESS == ret)
	{
		delayMS(200);

		unsigned char recvBuf[258];
		DWORD         recvBufLen;
		recvBufLen = (DWORD) sizeof(recvBuf);
		sendAPDU(hCard, "00:A4:04:0C:0C:A0:00:00:01:77:50:4B:43:53:2D:31:35", recvBuf, &recvBufLen, NULL, 0, true);

		if (!(recvBufLen == 2))
			returnValue |= 0x2; //------1-
		if (!(recvBuf[0] == 0x90 && recvBuf[1] == 0x00))
			returnValue |= 0x2; //------1-

		ret = SCardDisconnect(hCard, SCARD_LEAVE_CARD);
		if (SCARD_S_SUCCESS != ret)
			returnValue |= 0x4; //-----1--

		ret = SCardDisconnect(1111, SCARD_LEAVE_CARD);
		if (SCARD_S_SUCCESS == ret)
			returnValue |= 0x4; //-----1--
	}

	return returnValue;
}
unsigned char F54_RxOpenReport(void)
{
#ifdef F54_Porting
#else
   unsigned char ImageBuffer[CFG_F54_TXCOUNT*CFG_F54_RXCOUNT*2];
   short ImageArray[CFG_F54_RXCOUNT][CFG_F54_RXCOUNT];
#endif   
   //char Result[CFG_F54_RXCOUNT][CFG_F54_RXCOUNT];
   int Result=0;

   short OthersLowerLimit = -100;
   short OthersUpperLimit = 100;

   int i, j, k;
   int length;

   unsigned char command;

#ifdef F54_Porting
	memset(buf, 0, sizeof(buf));
	ret = sprintf(buf, "\nBin #: 8		Name: Receiver Open Test\n");
	ret += sprintf(buf+ret, "\n\t");
#else
	printk("\nBin #: 8		Name: Receiver Open Test\n");
	printk("\n\t");
#endif
	for (j = 0; j < numberOfRx; j++) 
#ifdef F54_Porting
		ret += sprintf(buf+ret, "R%d\t", j);
#else
		printk("R%d\t", j);
#endif

#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n");
#else
	printk("\n");
#endif	

   length =  numberOfRx * numberOfTx*2;

   // Set report mode
   command = 0x0E;
   writeRMI(F54_Data_Base, &command, 1);

   // Disable CBC
   command = 0x00;
   writeRMI(F54_CBCSettings, &command, 1);
   
   //NoCDM4
   command = 0x01;
   writeRMI(NoiseMitigation, &command, 1);

   // Force update
   command = 0x04;
   writeRMI(F54_Command_Base, &command, 1);

   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);

   command = 0x02;
   writeRMI(F54_Command_Base, &command, 1);

   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);

   //  command = 0x00;
   //	writeRMI(0x0113, &command, 1);

   command = 0x00;
   writeRMI(F54_Data_LowIndex, &command, 1);
   writeRMI(F54_Data_HighIndex, &command, 1);
   
   // Set the GetReport bit
   command = 0x01;
   writeRMI(F54_Command_Base, &command, 1);

   // Wait until the command is completed
   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);

   readRMI(F54_Data_Buffer, &ImageBuffer[0], length);

   k = 0;     
   for (i = 0; i < numberOfTx; i++)
   {
       for (j = 0; j < numberOfRx; j++)
	   {
			ImageArray[i][j] = (ImageBuffer[k] | (ImageBuffer[k+1] << 8));
			k = k + 2;
	   }  	  
   }
   
   // Set report mode
   length = numberOfRx* (numberOfRx-numberOfTx) * 2;
   command = 0x12;
   writeRMI(F54_Data_Base, &command, 1);

   command = 0x00;
   writeRMI(F54_Data_LowIndex, &command, 1);
   writeRMI(F54_Data_HighIndex, &command, 1);
   
   // Set the GetReport bit to run Tx-to-Tx
   command = 0x01;
   writeRMI(F54_Command_Base, &command, 1);

   // Wait until the command is completed
   do {
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);

   readRMI(F54_Data_Buffer, &ImageBuffer[0], length);

   k = 0;     
   for (i = 0; i < (numberOfRx-numberOfTx); i++)
   {
       for (j = 0; j < numberOfRx; j++)
	   {
			ImageArray[numberOfTx+i][j] = ImageBuffer[k] | (ImageBuffer[k+1] << 8);
			k = k + 2;
	   }  	  
   }

   /*
   // Check against test limits
   printk("\nRxToRx Short Test Result :\n");
	for (i = 0; i < numberOfRx; i++)
	{   
		for (j = 0; j < numberOfRx; j++)
		{
			if (i == j)
			{
				if((ImageArray[i][j] <= DiagonalUpperLimit) && (ImageArray[i][j] >= DiagonalUpperLimit))
					Result[i][j] = 'P'; //Pass
				else
					Result[i][j] = 'F'; //Fail
				//printk("%3d", ImageArray[i][j]);
			}
			else
			{
				if(ImageArray[i][j] <= OthersUpperLimit)
					Result[i][j] = 'P'; //Fail
				else
					Result[i][j] = 'F'; //Fail
			}
			printk("%4d", ImageArray[i][j]);
		}
		printk("\n");
	}
	printk("\n");
	*/

   	for (i = 0; i < numberOfRx; i++)
	{   
#ifdef F54_Porting
		ret += sprintf(buf+ret, "R%d\t", i);
#else
		printk("R%d\t", i);
#endif
		for (j = 0; j < numberOfRx; j++)
		{
			if((ImageArray[i][j] <= OthersUpperLimit) && (ImageArray[i][j] >= OthersLowerLimit))
			{
				Result++; //Pass
#ifdef F54_Porting
				ret += sprintf(buf+ret, "%d\t", ImageArray[i][j]);
#else
				printk("%d\t", ImageArray[i][j]);
#endif
			}
			else
			{
#ifdef F54_Porting
				ret += sprintf(buf+ret, "%d(*)\t", ImageArray[i][j]);
#else
				printk("%d(*)\t", ImageArray[i][j]);
#endif
			}
		}
#ifdef F54_Porting
		ret += sprintf(buf+ret, "\n");
#else
		printk("\n");
#endif
	}

   // Set the Force Cal
   command = 0x02;
   writeRMI(F54_Command_Base, &command, 1);

   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);

   //enable all the interrupts
//   SetPage(0x00);
   //Reset
   command= 0x01;
   writeRMI(F01_Cmd_Base, &command, 1);
   delayMS(200);
   readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high

   //printk("Result = %d, Rx*Rx= %d\n", Result, numberOfRx * numberOfRx);
   if(Result == numberOfRx * numberOfRx)
	{
#ifdef F54_Porting
		ret += sprintf(buf+ret, "Test Result: Pass\n");
		//write_log(buf);
#else
		printk("Test Result: Pass\n");
#endif
		return 1; //Pass
	}
   else
	{
#ifdef F54_Porting
		ret += sprintf(buf+ret, "Test Result: Fail\n");
		//write_log(buf);
#else
		printk("Test Result: Fail\n");
#endif
		return 0; //Fail
	}
}
void main(void)
{    
	//uint16_t adc_count;
	float adc_count;
    /* Initialize LCD */
    lcd_initialize();
	S12ADC_init();
    //UART initialization
	sci_uart_init();
	sci_tx_int_enable();
	sci_rx_int_enable();
	
	
    /* Clear LCD */
    lcd_clear();
    
    /* Display message on LCD */
    //Message will be on Position 1 and it will be stopped
    lcd_display(LCD_LINE1, " Mitch and  ");
	lcd_display(LCD_LINE2, "    Paul    ");
	lcd_display(LCD_LINE3, "Train Track ");
	lcd_display(LCD_LINE4, "  STOPPED   ");
	lcd_display(LCD_LINE5, "       _oo_");
	lcd_display(LCD_LINE6, " Pos1 |[][]|");
	lcd_display(LCD_LINE7, "      |O  O|");
	lcd_display(LCD_LINE8, "      |____|");

    /* 
        STDOUT is routed through the virtual console window tunneled through the JTAG debugger.
        Open the console window in HEW to see the output 
    */
    printf("This is the debug console\r\n");
    
    /* The three pushbuttons on the YRDK board are tied to interrupt lines, set them up here */
    R_SWITCHES_Init();
    
    //Intitalize all global variables
	count=0;
    Forward=0;
	Backword=0;
	Enable=0;
	
	//Character to input from putty
	char new_char;
	
	//Initialize Local variables
	int toggle=0;
	
	//Initialize all LED's starting at position 1
	LED4=LED_ON;
	LED5=LED_ON;
	LED6=LED_ON;
	LED7=LED_ON;
	LED8=LED_OFF;
	LED9=LED_OFF;
	LED10=LED_OFF;
	LED11=LED_OFF;
	LED12=LED_OFF;
	LED13=LED_OFF;
	LED14=LED_OFF;
	LED15=LED_OFF;
	
	while (1)
    {
		S12ADC_start();
		while(false==S12ADC_conversion_complete())
		{}
		new_char= sci_get_char();
		
		//Through the serial communication
		if(new_char =='F' ||new_char=='f')	//If inputted 'F' or 'f' move Forward
		{
			lcd_display(LCD_LINE4, "  FORWARD ");
			Forward=1;
			Enable=1;
			Backword=0;
			sci_put_string("Remote: Forward\n\r");
		}
		if(new_char =='S' ||new_char=='s')	//If inputted 'S' or 's' stop movement
		{
			lcd_display(LCD_LINE4, "  STOPPED   ");
			//Forward=0;
			Enable=0;
			//Backward=0;
			sci_put_string("Remote: Stop\n\r");

		}
		if(new_char =='R' ||new_char=='r')	//If inputted 'R' or 'r' move in reverse
		{
			lcd_display(LCD_LINE4, "  REVERSE  ");
			Forward=0;
			Enable=1;
			Backword=1;
			sci_put_string("Remote: Reverse\n\r");
		}
		
		
		
		adc_count= S12ADC_read();
		
		adc_count=adc_count/4095;
		int adccount=adc_count*100;
		char result[20];
		sprintf(result, "sp%3d%|____|", adccount);
		lcd_display(LCD_LINE8, (const uint8_t *) result);
	//	lcd_display(LCD_LINE8, adc_count);
		if(new_char=='D'||new_char=='d')	//If inputted 'D' or 'd' diplay the current speed
		{
			char speed[20];
			sprintf(speed,"Current Speed: %3d \n\r",adccount);
			sci_put_string(speed);
		}
		
		if(adc_count<=.01 & Enable==1)
		{
			lcd_display(LCD_LINE4, "  STOPPED   ");
			//Forward=0;
			Enable=0;
			//Backward=0;
			sci_put_string("Remote: Stop\n\r");
			while(adc_count<=0.05)
			{
				inloop=1;
				S12ADC_start();
				while(false==S12ADC_conversion_complete())
				{}
				adc_count= S12ADC_read();
				adc_count=adc_count/4095;
				
			}
			if(LastDir==1)
			{
				lcd_display(LCD_LINE4, "  FORWARD ");
				Forward=1;
				Enable=1;
				Backword=0;
				sci_put_string("Forward\n\r");
			}
			else if(LastDir==-1)
			{
				lcd_display(LCD_LINE4, "  REVERSE  ");
				Forward=0;
				Enable=1;
				Backword=1;
				sci_put_string("Reverse\n\r");
			}
			
			inloop=0;
		}
		else if(adc_count<=.25)
		{
			delayMS(1000);
		}
		else if(adc_count<=.5)
		{
			delayMS(500);
		}
		else if(adc_count<=.75)
		{
			delayMS(100);
		}		
		else if(adc_count<=1.0)
		{
			delayMS(10);
		}
		
		
		if(Enable==1)
		{
			trainMove();
			if(toggle==1 && Backword==1)
			{
				lcd_display(LCD_LINE5, "       _**_");
				lcd_display(LCD_LINE7, "      |*  *|");
				toggle=0;
			}
			else if(toggle==0 && Backword==1)
			{
				lcd_display(LCD_LINE5, "       _oo_");
				lcd_display(LCD_LINE7, "      |O  O|");
				toggle=1;
			}
			if(Forward==1)
			{
				lcd_display(LCD_LINE5, "       _oo_");
				lcd_display(LCD_LINE7, "      |*  *|");
			}
		}
		else
		{
			lcd_display(LCD_LINE5, "       _oo_");
			lcd_display(LCD_LINE7, "      |O  O|");
		}
		
		if(Forward==1 && Enable==1)	{count++; 	if(count==12){count=0;}}
		if(Backword==1 && Enable==1){count--;	if(count==-1){count=11;}}
    }
}
Exemplo n.º 10
0
// The following #defines are just needed to define an Image Report BUffer in memory
unsigned char F54_TxToGndReport(void)
{
   unsigned char ImageBuffer[CFG_F54_TXCOUNT];
   unsigned char ImageArray[CFG_F54_TXCOUNT];
   //unsigned char Result[CFG_F54_TXCOUNT];
   unsigned char Result=0;

   int i, k;
   int shift;

   unsigned char command;

#ifdef F54_Porting
	char buf[512] = {0};
	int ret = 0;

	ret += sprintf(buf+ret, "\nInfo: Tx=%d\n", numberOfTx);
	ret += sprintf(buf+ret, "=====================================================\n");
	ret += sprintf(buf+ret, "\tTransmitter To Ground Short Test\n");
	ret += sprintf(buf+ret, "=====================================================\n");
#else
	printk("\nBin #: 10		Name: Transmitter To Ground Short Test\n");
#endif
	for (i = 0; i < CFG_F54_TXCOUNT; i++)
		 ImageArray[i] = 0;
	
   // Set report mode to run Tx-to-GND
   command = 0x10;
   writeRMI(F54_Data_Base, &command, 1);

   command = 0x00;
   writeRMI(F54_Data_LowIndex, &command, 1);
   writeRMI(F54_Data_HighIndex, &command, 1);
   
   // Set the GetReport bit to run Tx-to-Tx
   command = 0x01;
   writeRMI(F54_Command_Base, &command, 1);

   // Wait until the command is completed
   do {
      delayMS(1); //wait 1ms
      readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);

   readRMI(F54_Data_Buffer, &ImageBuffer[0], 4);

   // One bit per transmitter channel
   k = 0;      
   for (i = 0; i < CFG_F54_TXCOUNT; i++)
   {
		k = i / 8;
		shift = i % 8;
		if(ImageBuffer[k] & (1 << shift)) ImageArray[i] = 1;
   }

#ifdef F54_Porting
	ret += sprintf(buf+ret, " UsedTx:");
#else
	printk("Column:\t");
#endif
	for (i = 0; i < numberOfTx; i++)
	{	
#ifdef F54_Porting
		ret += sprintf(buf+ret, "%5d", TxChannelUsed[i]);
#else	
		printk("Tx%d,\t", TxChannelUsed[i]);
#endif
	}
#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n 1 :    ");
#else	
	printk("\n");
	
	printk("0:\t");
#endif	
	for (i = 0; i < numberOfTx; i++)
	{   
		if(ImageArray[TxChannelUsed[i]])
		{
			Result++;
#ifdef F54_Porting
			ret += sprintf(buf+ret, "%5d", ImageArray[TxChannelUsed[i]]);
#else
			printk("%d,\t", ImageArray[TxChannelUsed[i]]);
#endif
		}
		else
		{
#ifdef F54_Porting
			ret += sprintf(buf+ret, "%2d(*)", ImageArray[TxChannelUsed[i]]);
#else
			printk("%d(*),\t", ImageArray[TxChannelUsed[i]]);
#endif
		}
	}
#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n-----------------------------------------------------\n");
#else	
	printk("\n");
#endif

   /*
   // Check against test limits
   printk("TxToGND Result\n");
   for (i = 0; i < numberOfTx; i++)
   {   
	    if(ImageArray[TxChannelUsed[i]] == TxGNDLimit)
   			Result[i] = 'P'; //Pass
	    else
		    Result[i] = 'F'; //Fail
	    printk("Tx%d = %c\n", TxChannelUsed[i], Result[i]);
   }
	*/
   
   //enable all the interrupts
//	SetPage(0x00);
   //Reset
	command= 0x01;
	writeRMI(F01_Cmd_Base, &command, 1);
	delayMS(200);
	readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high

	if(Result == numberOfTx)
	{
#ifdef F54_Porting
		ret += sprintf(buf+ret, "RESULT: Pass\n");
		write_log(buf);
#else		
		printk("Test Result: Pass\n");
#endif
		return 1; //Pass
	}
	else
	 {
#ifdef F54_Porting
		ret += sprintf(buf+ret, "RESULT: Fail\n");
		write_log(buf);
#else	 
		 printk("Test Result: Fail\n");
#endif
		 return 0; //Fail
	 }
}
Exemplo n.º 11
0
static void beepOn()
{
	controlLedSp(1, 1, 1);
	delayMS(60);
	controlLedSp(0, 0, 0);
}
unsigned char F54_HighResistance(void)
{
	unsigned char imageBuffer[6];
	short resistance[3];
	int i, Result=0;
	unsigned char command;

#ifdef F54_Porting
	int resistanceLimit[3][2] = { {-1000, 450}, {-1000, 450}, {-400, 20} };	//base value * 1000
	char buf[512] = {0};
	int ret = 0;
#else
	float resistanceLimit[3][2] = {-1, 0.45, -1, 0.45, -0.4, 0.02};
#endif

#ifdef F54_Porting
	ret = sprintf(buf, "\nBin #: 12		Name: High Resistance Test\n");
#else
	printk("\nBin #: 12		Name: High Resistance Test\n");
#endif

   // Set report mode
   command = 0x04;
   writeRMI(F54_Data_Base, &command, 1);

   // Force update
   command = 0x04;
   writeRMI(F54_Command_Base, &command, 1);

   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);
	  
   command = 0x02;
   writeRMI(F54_Command_Base, &command, 1);

   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);

   command = 0x00;
   writeRMI(F54_Data_LowIndex, &command, 1);
   writeRMI(F54_Data_HighIndex, &command, 1);
   
   // Set the GetReport bit
   command = 0x01;
   writeRMI(F54_Command_Base, &command, 1);

   // Wait until the command is completed
   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);

	readRMI(F54_Data_Buffer, imageBuffer, 6);

#ifdef F54_Porting
	ret += sprintf(buf+ret, "Parameters:\t");
#else
	printk("Parameters:\t");	
#endif
	for(i=0; i<3; i++)
	{
		resistance[i] = (short)((imageBuffer[i*2+1] << 8) | imageBuffer[i*2]);
#ifdef F54_Porting
		ret += sprintf(buf+ret, "%d,\t\t", (resistance[i]));
#else
		printk("%1.3f,\t\t", (float)(resistance[i])/1000);
#endif

#ifdef F54_Porting
		if((resistance[i] >= resistanceLimit[i][0]) && (resistance[i] <= resistanceLimit[i][1]))	Result++;
#else
		if((resistance[i]/1000 >= resistanceLimit[i][0]) && (resistance[i]/1000 <= resistanceLimit[i][1]))	Result++;
#endif		
	}
#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n");
	ret += sprintf(buf+ret, "Limits:\t\t");
#else
	printk("\n");

	printk("Limits:\t\t");
#endif
	for(i=0; i<3; i++)
	{
#ifdef F54_Porting	
		ret += sprintf(buf+ret, "%d,%d\t", resistanceLimit[i][0], resistanceLimit[i][1]);
#else
		printk("%1.3f,%1.3f\t", resistanceLimit[i][0], resistanceLimit[i][1]);
#endif
	}
#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n");
#else
	printk("\n");
#endif
	
   // Set the Force Cal
   command = 0x02;
   writeRMI(F54_Command_Base, &command, 1);

   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);
	  
   //enable all the interrupts
   //Reset
   command= 0x01;
   writeRMI(F01_Cmd_Base, &command, 1);
   delayMS(200);
   readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high

   if(Result == 3)
	{
#ifdef F54_Porting
		ret += sprintf(buf+ret, "Test Result: Pass\n");
		write_log(buf);
#else
		printk("Test Result: Pass\n");
#endif
		return 1; //Pass
	}
   else
	{
#ifdef F54_Porting
		ret += sprintf(buf+ret, "Test Result: Fail, Result = %d\n", Result);
		write_log(buf);
#else	
		printk("Test Result: Fail, Result = %d\n", Result);
#endif
		return 0; //Fail
	}
}
Exemplo n.º 13
0
//主函数
int main()
{ clock_t start,finish;
   int isPause = 1;
   int chance=0;
   float RewardTime=0;
   int z;
   
   setCursorVisible(0);
   setConsoleTitle("贪吃蛇--D_Y。 2010.1.11");        //标题
   ch=menu();
   ch2=menuDouble();               
   if(ch2=='1')
    z=0;
   if(ch2=='2')
    z=1;
   initSnake(SNAKE_MIN_LEN,z);
   drawMap();
   drawSnake(z);
   //PlaySound("d:\\泡泡堂轻松欢快音乐音效WAV.wav",NULL, SND_ASYNC|SND_NODEFAULT|SND_LOOP );   
   switch(ch)                 //不同的难度对应不同的奖励食物消失时间
   {
   case '1':
       RewardTime=2500;
   case '2':
    RewardTime=3000;
   case '3':
    RewardTime=3500;
   }
   while (!isOver[0]&&!isOver[1])             //当两条蛇任意一条死亡则游戏结束
   {   
    srand((uint32)time(NULL));
      if (!isPause)                           
      {
         moveSnake(z);
         if (!isFood)
            drawFood();
    while(((point[1]+point[0])%4==0)&&((point[1]+point[0])>3)&&p==1)        
                                                          //规定在得分大于三分时每吃掉四个常规食物产生一个奖励食物
    { 
     if (!isReward)
    drawReward();
       start=clock();                                        //画出食物,记录此刻时间
      break;  
    }

    finish=start+RewardTime ;                                //结束时间为开始时间加规定的奖励食物出现时间
            if((isReward==1)&&(finish<=clock()))
    {
             drawBlock(myReward.x, myReward.y, BS_SPACE); //超出规定时间则将奖励食物用背景方框覆盖
    myReward.x=-1;
    myReward.y=-1;
    isReward=0;                                           
    }
    if(((point[1]+point[0])%3==0)&&((point[1]+point[0])>2)&&q==0)                         
    {
    
      clearBar();
    
                    drawBar();
    }
           
    setTextColor(myColors[4]);                                    //规定出输出分数等信息
    gotoTextPos(MAP_BASE_X*2 -14 , MAP_BASE_Y + 2);
    printf("Player 1");
   gotoTextPos(MAP_BASE_X*2 -14 , MAP_BASE_Y + 4);
   
            printf("Score: %d.", point[0]);
    if(z==1)
    {
   gotoTextPos(MAP_BASE_X*2 + MAP_WIDTH*2+4 , MAP_BASE_Y + 2);
            printf("Player 2");
   gotoTextPos(MAP_BASE_X*2 + MAP_WIDTH*2+4 , MAP_BASE_Y + 4);
            printf("Score: %d.", point[1]);
    }                                                          
   
    
      }
      DELAY(ch); //赋予游戏速度
   delayMS(80- snakeLength[0]*2); //游戏速度随着蛇身增长而增加
      if (jkHasKey()) //键盘控制
      {
         switch (jkGetKey())
         {
      
            case JK_UP:
               if (snakeDir[0] != DIR_DOWN)
                  snakeDir[0] = DIR_UP;
      break;
    case 'w': 
               if (snakeDir[1] != DIR_DOWN)
                  snakeDir[1] = DIR_UP;
               
               break;
  
            case JK_DOWN:
               if (snakeDir[0] != DIR_UP)
                  snakeDir[0] = DIR_DOWN;
      break;
      case 's': 
      if (snakeDir[1] != DIR_UP)
                  snakeDir[1] = DIR_DOWN;
               break;
  
            case JK_LEFT:
               if (snakeDir[0] != DIR_RIGHT)
                  snakeDir[0] = DIR_LEFT;
      break;
      case 'a': 
       if (snakeDir[1] != DIR_RIGHT)
                  snakeDir[1] = DIR_LEFT;
               break;
  
            case JK_RIGHT:
               if (snakeDir[0] != DIR_LEFT)
                  snakeDir[0] = DIR_RIGHT;
      case 'd': 
        if (snakeDir[1] != DIR_LEFT)
                  snakeDir[1] = DIR_RIGHT;
               break;
            case JK_ENTER:
            case JK_SPACE:
               isPause = !isPause;
               break;
      case JK_ESC:
       isOver[0]=1;
       break;
            default:
               break;
         }

      }
   }
   PlaySound("d:\\超级马里奥兄弟 死掉音.wav",NULL, SND_ASYNC|SND_NODEFAULT );
   gotoTextPos(MAP_BASE_X + MAP_WIDTH - 7, MAP_BASE_Y + MAP_HEIGHT + 1);
   if(isOver[0]==1&&z==0)
printf("Game Over!!");
   if(isOver[0]==1&&z==1)
printf("Player 2 win!!");   
   if(isOver[1]==1)
   printf("Player 1 win!!");//游戏结束,在规定处显示分数
   getch();
   return 0;
}
// mode - 0:For sensor, 1:For FPC, 2:CheckTSPConnection, 3:Baseline, 4:Delta image
int F54_GetFullRawCap(int mode, char *buf) {
    signed short temp=0;
    //int Result = 0;
    int ret = 0;
    unsigned char product_id[11];
    int TSPCheckLimit=700;
    // short Flex_LowerLimit = -100;
    // short Flex_UpperLimit = 500;

    int i, j, k;
    unsigned short length;

    unsigned char command;

    int waitcount;

    if (mode < 0 && mode > 4)
        return ret;

    length = numberOfTx * numberOfRx * 2;

    //check product id to set basecap array
    readRMI(F01_Query_Base + 11, &product_id[0], sizeof(product_id));

    if(!strncmp(product_id, "PLG245", 6)) {
        pr_info("set limit array to PLG245 value.\n");
        //memcpy(Limit, Limit_PLG245, sizeof(Limit_PLG245));
    } else if(!strncmp(product_id, "PLG260", 6)) {
        pr_info("set limit array to PLG260 value.\n");
        //memcpy(Limit, Limit_PLG260, sizeof(Limit_PLG260));
    } else {
        pr_info("set limit array to LGIT value.\n");
    }

    //set limit array
    if (call_cnt == 0)
    {
        pr_info("Backup Limit to LimitBack array\n");
        memset(LimitBack, 0, sizeof(LimitBack));
//        memcpy(LimitBack, Limit, sizeof(LimitBack));
#if defined(LGE_USE_DOME_KEY)
        memcpy(LimitBack, Limit_PLG260, sizeof(LimitBack));
#else
        memcpy(LimitBack, Limit_PLG245, sizeof(LimitBack));
#endif
    }

    if (get_limit(numberOfTx, numberOfRx) > 0) {
        pr_info("Get limit from file success!!Use Limit array from file data.\n");
//        memcpy(Limit, LimitFile, sizeof(Limit));
#if defined(LGE_USE_DOME_KEY)
        memcpy(Limit_PLG260, LimitFile, sizeof(Limit_PLG260));
#else
        memcpy(Limit_PLG245, LimitFile, sizeof(Limit_PLG245));
#endif
    } else {
        pr_info("Get limit from file fail!!Use Limit array from image data\n");
//        memcpy(Limit, LimitBack, sizeof(Limit));
#if defined(LGE_USE_DOME_KEY)
        memcpy(Limit_PLG260, LimitBack, sizeof(Limit_PLG260));
#else
        memcpy(Limit_PLG245, LimitBack, sizeof(Limit_PLG245));
#endif
    }

    call_cnt++;

    if (call_cnt > 0)
        call_cnt = 1;

    // No sleep
    command = 0x04;
    writeRMI(F01_Ctrl_Base, &command, 1);

    // Set report mode to to run the AutoScan
    command = (mode == 4) ? 0x02 : 0x03;
    writeRMI(F54_Data_Base, &command, 1);

#if 0
    if (mode == 3 || mode == 4) {
        /*        //NoCDM4
                command = 0x01;
                writeRMI(NoiseMitigation, &command, 1);
         */
    }


    if (mode != 3 && mode != 4) {
        // Force update & Force cal
        command = 0x06;
        writeRMI(F54_Command_Base, &command, 1);

        waitcount = 0;
        do {
            if (++waitcount > 100) {
                pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
                break;
            }
            delayMS(1); //wait 1ms
            readRMI(F54_Command_Base, &command, 1);
        } while (command != 0x00);
    }
#endif

    // Enabling only the analog image reporting interrupt, and turn off the rest
    readRMI(F01_Cmd_Base+1, &command, 1);
    command |= 0x08;
    writeRMI(F01_Cmd_Base+1, &command, 1);

    command = 0x00;
    writeRMI(F54_Data_LowIndex, &command, 1);
    writeRMI(F54_Data_HighIndex, &command, 1);

    // Set the GetReport bit to run the AutoScan
    command = 0x01;
    writeRMI(F54_Command_Base, &command, 1);

    // Wait until the command is completed
    waitcount = 0;
    do {
        if (++waitcount > 100) {
            pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
            break;
        }
        delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
    } while (command != 0x00);

    //readRMI(F54_Data_Buffer, &ImageBuffer[0], length);
    longReadRMI(F54_Data_Buffer, &ImageBuffer[0], length);

    readRMI(F01_Cmd_Base+1, &command, 1);
    command &= ~0x08;
    writeRMI(F01_Cmd_Base+1, &command, 1);

    if ( (numberOfTx > 29) || (numberOfRx > 45) ) {
        ret = sprintf(buf, "ERROR: Limit Index overflow. Test result: Fail\n");
        return ret;
    }

    *buf = 0;

    ret = sprintf(buf, "Info: Tx=%d Rx=%d\n", numberOfTx, numberOfRx);

    switch(mode) {
    case 0:
    case 1:
        //ret += sprintf(buf+ret, "Full raw capacitance Test\n");
        k = 0;
        for (i = 0; i < numberOfTx; i++) {
            // ret += sprintf(buf+ret, "%d\t", i);
            for (j = 0; j < numberOfRx; j++) {
                temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
                /*
                if(CheckButton[i][j] != 1) {
                    if(mode==0) {
                        if ((temp >= Limit[i][j*2]) && (temp <= Limit[i][j*2+1]))
                            Result++;
                    } else {
                        if ((temp >= Flex_LowerLimit) && (temp <= Flex_UpperLimit))
                            Result++;
                    }
                } else {
                    Result++;
                }
                */
                ret += sprintf(buf+ret, "%d", temp); //It's for getting log for limit set

                if(j < (numberOfRx-1))
                    ret += sprintf(buf+ret, " ");

                k = k + 2;
            }
            ret += sprintf(buf+ret, "\n");
        }
        break;

    case 2:
        k = 0;
        for (i = 0; i < numberOfTx; i++) {
            for (j = 0; j < numberOfRx; j++) {
                temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));

                if (temp > TSPCheckLimit) {
                    ret += sprintf(buf+ret, "1");
                    //Result++;
                } else {
                    ret += sprintf(buf+ret, "0");
                }

                if(j < (numberOfRx-1))
                    ret += sprintf(buf+ret, " ");

                k = k + 2;
            }
            ret += sprintf(ret+buf, "\n");
        }
        break;

    case 3:
    case 4:
        k = 0;

        for (i = 0; i < numberOfTx; i++) {
            for (j = 0; j < numberOfRx; j++) {
                ImageArray[i][j] = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
                k = k + 2;
            }
        }

        for (i = 0; i < numberOfTx; i++) {
            //ret += sprintf(buf+ret, "TX%d\t", TxChannelUsed[i]);
            for (j = 0; j < numberOfRx; j++) {
                ret += sprintf(buf+ret, "%d", ((mode == 3) ? (ImageArray[i][j] / 1000) : (ImageArray[i][j])));

                if(j < (numberOfRx - 1))
                    ret += sprintf(buf+ret, " ");
            }
            ret += sprintf(ret+buf, "\n");
        }
        break;

    default:
        break;
    }
    //if (mode < 3)
    /*
    {
        //Reset
        command = 0x01;
        writeRMI(F01_Cmd_Base, &command, 1);
        //delayMS(200);
        delayMS(1);
        readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high
    }
    */
    return ret;
}
Exemplo n.º 15
0
static int testCardFunctionality(SCARDCONTEXT ctx, const char *readerName)
{
	SCARDHANDLE hCard;
	DWORD       protocol;
	int         errCount = 0;

	printf("Using reader \"%s\"\n\n", readerName);
	printf("NOTE: make sure no-one else is accessing the card!\n\n");

	long ret = SCardConnectA(ctx, readerName,
		SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &protocol);

	CHECK_PCSC_RET("SCardConnect", ret);
	if (SCARD_S_SUCCESS == ret)
	{
		delayMS(200);

        printf("--- SCardReconnect tests ---\n");
        errCount += testScardReconnect(hCard, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0);

#ifdef _WIN32
		printf("\n--- SCardState tests ---\n");
		errCount += testSCardState(hCard);
#endif

		printf("\n--- SCardStatus tests ---\n");
		errCount += testSCardStatus(hCard);

#ifndef MAC_OS_X
		printf("\n--- SCardGetAttrib tests ---\n");
		errCount += testSCardGetAttrib(ctx, hCard);
#endif

		printf("\n--- Get Response tests ---\n");
		errCount += testGetResponse(hCard);

		printf("\n--- Get Response tests within a transaction ---\n");
		ret = SCardBeginTransaction(hCard);
		CHECK_PCSC_RET("SCardBeginTransaction", ret);
		errCount += testGetResponse(hCard);
		ret       = SCardEndTransaction(hCard, SCARD_LEAVE_CARD);
		CHECK_PCSC_RET("SCardBeginTransaction", ret);

		printf("\n--- Test reading a long file ---\n");
		errCount += testLongFileRead(hCard);

		printf("\n--- Test reading a long file within a transaction ---\n");
		ret = SCardBeginTransaction(hCard);
		CHECK_PCSC_RET("SCardBeginTransaction", ret);
		errCount += testLongFileRead(hCard);
		ret       = SCardEndTransaction(hCard, SCARD_LEAVE_CARD);
		CHECK_PCSC_RET("SCardBeginTransaction", ret);

		printf("\n--- Misc tests ---\n");
		errCount += testMisc(hCard);

		printf("\n--- Test ListReaders ---\n");
		errCount += testListReaders(ctx);

		ret = SCardDisconnect(hCard, SCARD_LEAVE_CARD);
		CHECK_PCSC_RET("SCardDisconnect", ret);
	}

	if (errCount == 0)
		printf("\nFunctional tests done, no errors\n");
	else
		printf("\nFunctional tests done, %d errors\n", errCount);

	return 0;
}
int F54_GetTxOpenReport(char *buf)
{
	unsigned char ImageBuffer[CFG_F54_TXCOUNT];
	unsigned char ImageArray[CFG_F54_TXCOUNT];
	unsigned char Result = 0;
	/* unsigned char Result[CFG_F54_TXCOUNT]; */

	int i, k;
	int shift;

	unsigned char command;

	int ret = 0;

	for (i = 0; i < CFG_F54_TXCOUNT; i++)
		ImageArray[i] = 1;

	/* Set report mode */
	command = 0x0F;
	writeRMI(F54_Data_Base, &command, 1);

	command = 0x00;
	writeRMI(F54_Data_LowIndex, &command, 1);
	writeRMI(F54_Data_HighIndex, &command, 1);

	/* Set the GetReport bit */
	command = 0x01;
	writeRMI(F54_Command_Base, &command, 1);

	/* Wait until the command is completed */
	do {
		delayMS(1);	/* wait 1ms */
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	readRMI(F54_Data_Buffer, &ImageBuffer[0], 4);

	k = 0;
	for (i = 0; i < CFG_F54_TXCOUNT; i++) {
		k = i / 8;
		shift = i % 8;
		if (!(ImageBuffer[k] & (1 << shift)))
			ImageArray[i] = 0;
	}

	ret += sprintf(buf + ret, "Info: Tx=%d\n", numberOfTx);
	ret += sprintf(buf + ret, "UsedTx: ");
	for (i = 0; i < numberOfTx; i++) {
		ret += sprintf(buf + ret, "%d", TxChannelUsed[i]);

		if (i < (numberOfTx - 1))
			ret += sprintf(buf + ret, " ");
	}
	ret += sprintf(buf + ret, "\n");
	ret += sprintf(buf + ret, "        ");
	for (i = 0; i < numberOfTx; i++) {
		if (!ImageArray[TxChannelUsed[i]]) {
			Result++;
			ret += sprintf(buf + ret, "%d", ImageArray[TxChannelUsed[i]]);
		} else {
			ret += sprintf(buf + ret, "%d(*)", ImageArray[TxChannelUsed[i]]);
		}

		if (i < (numberOfTx - 1))
			ret += sprintf(buf + ret, " ");
	}
	ret += sprintf(buf + ret, "\n");

	/*
	   // Check against test limits
	   pr_err("\nTx-Tx short test result:\n");
	   for (i = 0; i < numberOfTx; i++)
	   {
	   if (ImageArray[i]== TxTxLimit)
	   Result[i] = 'P'; //Pass
	   else
	   Result[i] = 'F'; //Fail
	   pr_err("Tx[%d] = %c\n", TxChannelUsed[i], Result[i]);
	   }
	 */

	/*
	   // Check against test limits
	   pr_err("\nTx-Tx short test result:\n");
	   for (i = 0; i < numberOfTx; i++)
	   {
	   if (ImageArray[i]== TxTxLimit)
	   Result[i] = 'P'; //Pass
	   else
	   Result[i] = 'F'; //Fail
	   pr_err("Tx[%d] = %c\n", TxChannelUsed[i], Result[i]);
	   }
	 */

	if (Result == numberOfTx)
		ret += sprintf(buf + ret, "RESULT: Pass\n");
	else
		ret += sprintf(buf + ret, "RESULT: Fail\n");

	/* enable all the interrupts */
	/* SetPage(0x00); */
	/* Reset */
	command = 0x01;
	writeRMI(F01_Cmd_Base, &command, 1);
	delayMS(200);
	/* Read Interrupt status register to Interrupt line goes to high */
	readRMI(F01_Data_Base + 1, &command, 1);

	return ret;
}
int F54_GetRxToRxReport(char *buf)
{
    int Result=0;
    int ret = 0;

    short DiagonalLowerLimit = 900;
    short DiagonalUpperLimit = 1100;
    short OthersLowerLimit = -100;
    short OthersUpperLimit = 100;

    int i, j, k;
    int length;

    unsigned char command;
    int waitcount;

    ret += sprintf(buf+ret, "Info: Rx=%d\n", numberOfRx);

    length =  numberOfRx * numberOfTx*2;

    // Set report mode to run Rx-to-Rx 1st data
    command = 0x07;
    writeRMI(F54_Data_Base, &command, 1);

    // Disable CBC
    command = 0x00;
    writeRMI(F54_CBCSettings, &command, 1);

    //NoCDM4
    command = 0x01;
    writeRMI(NoiseMitigation, &command, 1);

    // Force update
    command = 0x04;
    writeRMI(F54_Command_Base, &command, 1);

    waitcount = 0;
    do {
        if(++waitcount > 500)
        {
            pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
            return ret;
        }
        delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
    } while (command != 0x00);

    command = 0x02;
    writeRMI(F54_Command_Base, &command, 1);

    waitcount = 0;
    do {
        if(++waitcount > 1000)
        {
            pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
            return ret;
        }
        delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
    } while (command != 0x00);

    //  command = 0x00;
    //    writeRMI(0x0113, &command, 1);

    command = 0x00;
    writeRMI(F54_Data_LowIndex, &command, 1);
    writeRMI(F54_Data_HighIndex, &command, 1);

    // Set the GetReport bit to run Tx-to-Tx
    command = 0x01;
    writeRMI(F54_Command_Base, &command, 1);

    // Wait until the command is completed
    waitcount = 0;
    do {
        if(++waitcount > 500)
        {
            pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
            return ret;
        }
        delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
    } while (command != 0x00);

    //readRMI(F54_Data_Buffer, &ImageBuffer[0], length);
    longReadRMI(F54_Data_Buffer, &ImageBuffer[0], length);

    k = 0;
    for (i = 0; i < numberOfTx; i++)
    {
        for (j = 0; j < numberOfRx; j++)
        {
            ImageArray[i][j] = (ImageBuffer[k] | (ImageBuffer[k+1] << 8));
            k = k + 2;
        }
    }

    // Set report mode to run Rx-to-Rx 2nd data
    length = numberOfRx* (numberOfRx-numberOfTx) * 2;
    command = 0x11;
    writeRMI(F54_Data_Base, &command, 1);

    command = 0x00;
    writeRMI(F54_Data_LowIndex, &command, 1);
    writeRMI(F54_Data_HighIndex, &command, 1);

    // Set the GetReport bit to run Tx-to-Tx
    command = 0x01;
    writeRMI(F54_Command_Base, &command, 1);

    // Wait until the command is completed
    waitcount = 0;
    do {
        if(++waitcount > 500)
        {
            pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
            return ret;
        }
        delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
    } while (command != 0x00);

    //readRMI(F54_Data_Buffer, &ImageBuffer[0], length);
    longReadRMI(F54_Data_Buffer, &ImageBuffer[0], length);

    k = 0;
    for (i = 0; i < (numberOfRx-numberOfTx); i++)
    {
        for (j = 0; j < numberOfRx; j++)
        {
            ImageArray[numberOfTx+i][j] = ImageBuffer[k] | (ImageBuffer[k+1] << 8);
            k = k + 2;
        }
    }

    /*
    // Check against test limits
    printk("\nRxToRx Short Test Result :\n");
    for (i = 0; i < numberOfRx; i++)
    {
    for (j = 0; j < numberOfRx; j++)
    {
    if (i == j)
    {
    if((ImageArray[i][j] <= DiagonalUpperLimit) && (ImageArray[i][j] >= DiagonalUpperLimit))
    Result[i][j] = 'P'; //Pass
    else
    Result[i][j] = 'F'; //Fail
    //printk("%3d", ImageArray[i][j]);
    }
    else
    {
    if(ImageArray[i][j] <= OthersUpperLimit)
    Result[i][j] = 'P'; //Fail
    else
    Result[i][j] = 'F'; //Fail
    }
    printk("%4d", ImageArray[i][j]);
    }
    printk("\n");
    }
    printk("\n");
     */

    for (i = 0; i < numberOfRx; i++)
    {
        for (j = 0; j < numberOfRx; j++)
        {
            if (i == j)
            {
                if((ImageArray[i][j] <= DiagonalUpperLimit) && (ImageArray[i][j] >= DiagonalLowerLimit))
                {
                    Result++; //Pass
                    ret += sprintf(buf+ret, "%d", ImageArray[i][j]);
                }
                else
                {
                    ret += sprintf(buf+ret, "%d(*)", ImageArray[i][j]);
                }
            }
            else
            {
                if((ImageArray[i][j] <= OthersUpperLimit) && (ImageArray[i][j] >= OthersLowerLimit))
                {
                    Result++; //Pass
                    ret += sprintf(buf+ret, "%d", ImageArray[i][j]);
                }
                else
                {
                    ret += sprintf(buf+ret, "%d(*)", ImageArray[i][j]);
                }
            }

            if(j < (numberOfRx-1))
                ret += sprintf(buf+ret, " ");
        }
        ret += sprintf(buf+ret, "\n");
    }

    // Set the Force Cal
    command = 0x02;
    writeRMI(F54_Command_Base, &command, 1);

    waitcount = 0;
    do {
        if(++waitcount > 500)
        {
            pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
            break;
        }
        delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
    } while (command != 0x00);


    //printk("Result = %d, Rx*Rx= %d\n", Result, numberOfRx * numberOfRx);
    if(Result == numberOfRx * numberOfRx)
    {
        ret += sprintf(buf+ret, "RESULT: Pass\n");
    }
    else
    {
        ret += sprintf(buf+ret, "RESULT: Fail\n");
    }

    //enable all the interrupts
    //   SetPage(0x00);
    //Reset
    command= 0x01;
    writeRMI(F01_Cmd_Base, &command, 1);
    delayMS(200);
    readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high
    return ret;
}
Exemplo n.º 18
0
void startupLightSequence(){
	setRGB(100,0,0); delayMS(100); setRGB(0,100,0); delayMS(100); setRGB(0,0,100); delayMS(100); ledOff();
	setRGB(100,0,0); delayMS(100); setRGB(0,100,0); delayMS(100); setRGB(0,0,100); delayMS(100); ledOff();
	setRGB(100,0,0); delayMS(100); setRGB(0,100,0); delayMS(100); setRGB(0,0,100); delayMS(100); ledOff();
}
unsigned char F54_HighResistance(int mfts_enable)
{
	unsigned char imageBuffer[6];
	short resistance[3];
	int i, Result=0;
	unsigned char command;
	int read_count = 0;

#ifdef F54_Porting
	int resistanceLimit[3][2] ;//= { {-1000, 450}, {-1000, 450}, {-400, 20} };	//base value * 1000
	int resistanceLimit_target[3][2] = { {-1000, 450}, {-1000, 450}, {-400, 20} };
	int resistanceLimit_jig[3][2] = { {-1000, 450}, {-1000, 450}, {-500, 20} };
	char buf[512] = {0};
	int ret = 0;
	if(mfts_enable)
		memcpy(resistanceLimit, resistanceLimit_jig, sizeof(resistanceLimit));
	else
		memcpy(resistanceLimit, resistanceLimit_target, sizeof(resistanceLimit));
#else
	float resistanceLimit[3][2] = {-1, 0.45, -1, 0.45, -0.4, 0.02};
#endif

#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n=====================================================\n");
	ret += sprintf(buf+ret, "\tHigh Resistance Test\n");
	ret += sprintf(buf+ret, "=====================================================");
#else
	TOUCH_INFO_MSG("\nBin #: 12		Name: High Resistance Test\n");
#endif

	// Set report mode
	command = 0x04;
	writeRMI(F54_Data_Base, &command, 1);

	// Force update
	command = 0x04;
	writeRMI(F54_Command_Base, &command, 1);

	do {
		if(++read_count > 10) {
			TOUCH_INFO_MSG("%s[%d], command = %d\n", __func__, __LINE__, command);
			return 0;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	command = 0x02;
	writeRMI(F54_Command_Base, &command, 1);

	read_count = 0;
	do {
		if(++read_count > 10) {
			TOUCH_INFO_MSG("%s[%d], command = %d\n", __func__, __LINE__, command);
			return 0;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	command = 0x00;
	writeRMI(F54_Data_LowIndex, &command, 1);
	writeRMI(F54_Data_HighIndex, &command, 1);

	// Set the GetReport bit
	command = 0x01;
	writeRMI(F54_Command_Base, &command, 1);

   // Wait until the command is completed
   	read_count = 0;
	do {
		if(++read_count > 10) {
			TOUCH_INFO_MSG("%s[%d], command = %d\n", __func__, __LINE__, command);
			return 0;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	readRMI(F54_Data_Buffer, imageBuffer, 6);

#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n Parameters: ");
#else
	TOUCH_INFO_MSG("Parameters:\t");
#endif
	for(i=0; i<3; i++) {
		resistance[i] = (short)((imageBuffer[i*2+1] << 8) | imageBuffer[i*2]);
#ifdef F54_Porting
		ret += sprintf(buf+ret, "%5d ", (resistance[i]));
#else
		TOUCH_INFO_MSG("%1.3f,\t\t", (float)(resistance[i])/1000);
#endif

#ifdef F54_Porting
		if((resistance[i] >= resistanceLimit[i][0]) && (resistance[i] <= resistanceLimit[i][1]))
			Result++;
#else
		if((resistance[i]/1000 >= resistanceLimit[i][0]) && (resistance[i]/1000 <= resistanceLimit[i][1]))
			Result++;
#endif
	}
#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n\n Limits(+) : ");
#else
	TOUCH_INFO_MSG("\n");

	TOUCH_INFO_MSG("Limits:\t\t");
#endif
	for(i=0; i<3; i++) {
#ifdef F54_Porting
		ret += sprintf(buf+ret, "%5d ", resistanceLimit[i][1]);
#else
		printk("%1.3f,%1.3f\t", resistanceLimit[i][0], resistanceLimit[i][1]);
#endif
	}

	ret += sprintf(buf+ret, "\n Limits(-) : ");

	for(i=0; i<3; i++) {
#ifdef F54_Porting
		ret += sprintf(buf+ret, "%5d ", resistanceLimit[i][0]);
#else
		printk("%1.3f,%1.3f\t", resistanceLimit[i][0], resistanceLimit[i][1]);
#endif
	}

#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n-----------------------------------------------------\n");
#else
	printk("\n");
#endif

	// Set the Force Cal
	command = 0x02;
	writeRMI(F54_Command_Base, &command, 1);

	read_count = 0;
	do {
		if(++read_count > 10) {
			TOUCH_INFO_MSG("%s[%d], command = %d\n", __func__, __LINE__, command);
			return 0;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	//enable all the interrupts
	//Reset
	command= 0x01;
	writeRMI(F01_Cmd_Base, &command, 1);
	delayMS(200);
	readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high

	if(Result == 3) {
#ifdef F54_Porting
		ret += sprintf(buf+ret, "RESULT: Pass\n");
		write_log(buf);
#else
		TOUCH_INFO_MSG("Test Result: Pass\n");
#endif
		return 1; //Pass
	} else {
#ifdef F54_Porting
		ret += sprintf(buf+ret, "RESULT: Fail\n");
		write_log(buf);
#else
		TOUCH_INFO_MSG("Test Result: Fail, Result = %d\n", Result);
#endif
		return 0; //Fail
	}
}
int F54_GetHighResistance(char *buf)
{
	unsigned char imageBuffer[6];
	short resistance[3];
	int i, Result=0;
	unsigned char command;

	int resistanceLimit[3][2] = { {-1000, 450}, {-1000, 450}, {-400, 20} };	//base value * 1000
	int ret = 0;
	int waitcount;

	// Set report mode
	command = 0x04;
	writeRMI(F54_Data_Base, &command, 1);

	// Force update
	command = 0x04;
	writeRMI(F54_Command_Base, &command, 1);

	waitcount = 0;
	do {
		if(++waitcount > 500)
		{
			pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
			return ret;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	command = 0x02;
	writeRMI(F54_Command_Base, &command, 1);

	waitcount = 0;
	do {
		if(++waitcount > 500)
		{
			pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
			return ret;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	command = 0x00;
	writeRMI(F54_Data_LowIndex, &command, 1);
	writeRMI(F54_Data_HighIndex, &command, 1);

	// Set the GetReport bit
	command = 0x01;
	writeRMI(F54_Command_Base, &command, 1);

	// Wait until the command is completed
	waitcount = 0;
	do {
		if(++waitcount > 500)
		{
			pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
			return ret;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	readRMI(F54_Data_Buffer, imageBuffer, 6);

	ret += sprintf(buf+ret, "Params: ");
	for(i=0; i<3; i++)
	{
		resistance[i] = (short)((imageBuffer[i*2+1] << 8) | imageBuffer[i*2]);
		ret += sprintf(buf+ret, "%d", (resistance[i]));
		if((resistance[i] >= resistanceLimit[i][0]) && (resistance[i] <= resistanceLimit[i][1]))
			Result++;

		if(i < 2)
			ret += sprintf(buf+ret, " ");
	}
	ret += sprintf(buf+ret, "\n");
	ret += sprintf(buf+ret, "Limits: ");

	for(i=0; i<3; i++)
	{
		ret += sprintf(buf+ret, "%d,%d", resistanceLimit[i][0], resistanceLimit[i][1]);

		if(i < 2)
			ret += sprintf(buf+ret, " ");
	}
	ret += sprintf(buf+ret, "\n");

	// Set the Force Cal
	command = 0x02;
	writeRMI(F54_Command_Base, &command, 1);

	waitcount = 0;
	do {
		if(++waitcount > 100)
		{
			pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
			break;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	if (Result == 3)
	{
		ret += sprintf(buf+ret, "RESULT: Pass\n");
	}
	else
	{
		ret += sprintf(buf+ret, "RESULT: Fail\n");
	}

	//enable all the interrupts
	//	SetPage(0x00);
	//Reset
	command= 0x01;
	writeRMI(F01_Cmd_Base, &command, 1);
	delayMS(200);
	readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high

	return ret;
}
unsigned char F54_TxOpenReport(void)
{
   unsigned char ImageBuffer[CFG_F54_TXCOUNT];
   unsigned char ImageArray[CFG_F54_TXCOUNT];
   unsigned char Result = 0; 
   //unsigned char Result[CFG_F54_TXCOUNT];
   
   int i, k;
   int shift;

   unsigned char command;

#ifdef F54_Porting
	char buf[256] = {0};
	int ret = 0;

	ret = sprintf(buf, "\nBin #: 6		Name: Transmitter Open Test\n");
#else   
   printk("\nBin #: 6		Name: Transmitter Open Test\n");
#endif
   for (i = 0; i < 30; i++)
		ImageArray[i] = 1;

   // Set report mode
   command = 0x0F;
   writeRMI(F54_Data_Base, &command, 1);

   command = 0x00;
   writeRMI(F54_Data_LowIndex, &command, 1);
   writeRMI(F54_Data_HighIndex, &command, 1);
   
   // Set the GetReport bit
   command = 0x01;
   writeRMI(F54_Command_Base, &command, 1);

   // Wait until the command is completed
   do {
   	delayMS(1); //wait 1ms
      readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);

   readRMI(F54_Data_Buffer, &ImageBuffer[0], 4);

//	printk("Buffer : 0x%x 0x%x 0x%x 0x%x \n", ImageBuffer[0], ImageBuffer[1], ImageBuffer[2], ImageBuffer[3]);
	
	// One bit per transmitter channel
	k = 0;		
	for (i = 0; i < 32; i++)
	{
		 k = i / 8;
		 shift = i % 8;
		 if(!(ImageBuffer[k] & (1 << shift))) ImageArray[i] = 0;
	}

#ifdef F54_Porting
	ret += sprintf(buf+ret, "Column:\t");
#else
   printk("Column:\t");
#endif
   for (i = 0; i < numberOfTx; i++)
   {
#ifdef F54_Porting
		ret += sprintf(buf+ret, "Tx%d,\t", TxChannelUsed[i]);
#else
	   printk("Tx%d,\t", TxChannelUsed[i]);
#endif
   }
#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n");
	ret += sprintf(buf+ret, "0:\t");
#else
   printk("\n");
   
   printk("0:\t");
#endif   
   for (i = 0; i < numberOfTx; i++)
   {   
	   if(!ImageArray[TxChannelUsed[i]])
	   {
		   Result++;
#ifdef F54_Porting
			ret += sprintf(buf+ret, "%d,\t", ImageArray[TxChannelUsed[i]]);
#else
		   printk("%d,\t", ImageArray[TxChannelUsed[i]]);
#endif
	   }
	   else
	   {
#ifdef F54_Porting
			ret += sprintf(buf+ret, "%d(*),\t", ImageArray[TxChannelUsed[i]]);
#else	   
		   printk("%d(*),\t", ImageArray[TxChannelUsed[i]]);
#endif
	   }
   }
#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n");
#else
   printk("\n");
#endif

   /*
   // Check against test limits
   printk("\nTx-Tx short test result:\n");
   for (i = 0; i < numberOfTx; i++)
   {   
	    if (ImageArray[i]== TxTxLimit)
   			Result[i] = 'P'; //Pass
		else
		    Result[i] = 'F'; //Fail
		printk("Tx[%d] = %c\n", TxChannelUsed[i], Result[i]);
   }
   */
   
   //enable all the interrupts
//	SetPage(0x00);
   //Reset
	command= 0x01;
	writeRMI(F01_Cmd_Base, &command, 1);
	delayMS(200);
	readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high

	if(Result == numberOfTx)
	{
#ifdef F54_Porting
		ret += sprintf(buf+ret, "Test Result: Pass\n");
		//write_log(buf);
#else
		printk("Test Result: Pass\n");
#endif
		return 1; //Pass
	}
	else
	 {
#ifdef F54_Porting
		ret += sprintf(buf+ret, "Test Result: Fail\n");
		//write_log(buf);
#else
		 printk("Test Result: Fail\n");
#endif
		 return 0; //Fail
	 }
}
Exemplo n.º 22
0
unsigned char F54_FullRawCap(int mode)
// mode - 0:For sensor, 1:For FPC, 2:CheckTSPConnection, 3:Baseline, 4:Delta image
{
   signed short temp=0;
   int Result = 0;
#ifdef F54_Porting
	int ret = 0;
	unsigned char product_id[11];
#endif
    int TSPCheckLimit=700;
	short Flex_LowerLimit = -100;
	short Flex_UpperLimit = 500;

	int i, j, k;
	unsigned short length;
	
	unsigned char command;

	length = numberOfTx * numberOfRx* 2;

	//check product id to set basecap array
	readRMI(F01_Query_Base+11, &product_id[0], sizeof(product_id));
	
	if(!strncmp(product_id, "TM2369", 6)) {
		printk("set limit array to TPK value.\n");
		memcpy(Limit, Limit_TPK, sizeof(Limit_TPK));
	} else if(!strncmp(product_id, "PLG192", 6)) {
		printk("set limit array to PLG192 value.\n");
		memcpy(Limit, Limit_PLG192, sizeof(Limit_PLG192));
	} else if(!strncmp(product_id, "PLG193", 6)) {
		printk("set limit array to PLG193 value.\n");
		memcpy(Limit, Limit_PLG193, sizeof(Limit_PLG193));
	} else if(!strncmp(product_id, "PLG121", 6)) {
		printk("set limit array to PLG121 value.\n");
		memcpy(Limit, Limit_PLG121, sizeof(Limit_PLG121));
	} else {
		printk("set limit array to LGIT value.\n");
	}
	
	//set limit array
	if(call_cnt == 0){
		printk("Backup Limit to LimitBack array\n");
		memset(LimitBack, 0, sizeof(LimitBack));
		memcpy(LimitBack, Limit, sizeof(LimitBack));
	}
	if(get_limit(numberOfTx, numberOfRx) > 0) {
		printk("Get limit from file success!!Use Limit array from file data.\n");
		memcpy(Limit, LimitFile, sizeof(Limit));
	} else {
		printk("Get limit from file fail!!Use Limit array from image data\n");
		memcpy(Limit, LimitBack, sizeof(Limit));
	}
	call_cnt++;
	if(call_cnt > 0) call_cnt = 1;

	if(mode == 3 || mode == 4)
	{
/*		// Disable CBC
		command = 0x00;
		writeRMI(F54_CBCSettings, &command, 1);
		writeRMI(F54_CBCPolarity, &command, 1);
*/	}

	// No sleep
	command = 0x04;
	writeRMI(F01_Ctrl_Base, &command, 1);

	// Set report mode to to run the AutoScan
	if(mode >= 0 && mode < 4)	command = 0x03;
	if(mode == 4)				command = 0x02;
	writeRMI(F54_Data_Base, &command, 1);

	if(mode == 3 || mode == 4)
	{
/*		//NoCDM4
		command = 0x01;
		writeRMI(NoiseMitigation, &command, 1);
*/	}

	if(mode != 3 && mode != 4)
	{
		// Force update & Force cal
		command = 0x06;
		writeRMI(F54_Command_Base, &command, 1);

		do {
			delayMS(1); //wait 1ms
			readRMI(F54_Command_Base, &command, 1);
		} while (command != 0x00);
	}

	// Enabling only the analog image reporting interrupt, and turn off the rest
	command = 0x08;
	writeRMI(F01_Cmd_Base+1, &command, 1);

	command = 0x00;
	writeRMI(F54_Data_LowIndex, &command, 1);
	writeRMI(F54_Data_HighIndex, &command, 1);
 
	// Set the GetReport bit to run the AutoScan
	command = 0x01;
	writeRMI(F54_Command_Base, &command, 1);
 
	// Wait until the command is completed
	do {
	 delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);
 
	readRMI(F54_Data_Buffer, &ImageBuffer[0], length);

	if( (numberOfTx > 29) || (numberOfRx > 45) ) {
		printk("Limit Index overflow. Test result: Fail\n");
		return 0;
	}

	switch(mode)
	{
		case 0:
		case 1:
#ifdef F54_Porting
			memset(buf, 0, sizeof(buf));
			ret = sprintf(buf, "#ofTx\t%d\n", numberOfTx);
			ret += sprintf(buf+ret, "#ofRx\t%d\n", numberOfRx);

			ret += sprintf(buf+ret, "\n#3.03	Full raw capacitance Test\n");
#else
			printk("#ofTx\t%d\n", numberOfTx);
			printk("#ofRx\t%d\n", numberOfRx);

			printk("\n#3.03	Full raw capacitance Test\n");
#endif
			k = 0;	   
			for (i = 0; i < numberOfTx; i++)
			{
#ifdef F54_Porting
				ret += sprintf(buf+ret, "%d\t", i);
#else
				printk("%d\t", i);
#endif
				for (j = 0; j < numberOfRx; j++)
				{
						temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
						if(CheckButton[i][j] != 1)
						{
							if(mode==0)
							{
#ifdef F54_Porting
								if ((temp >= Limit[i][j*2]) && (temp <= Limit[i][j*2+1]))
#else
								if ((temp >= Limit[i][j*2]*1000) && (temp <= Limit[i][j*2+1]*1000))
#endif
								{
									Result++;
#ifdef F54_Porting									
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif
								}
								else {
#ifdef F54_Porting
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif
								}
							}
							else
							{
								if ((temp >= Flex_LowerLimit) && (temp <= Flex_UpperLimit))
								{
									Result++;
#ifdef F54_Porting
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif									
								}
								else {
#ifdef F54_Porting
									ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
									printk("%d\t", temp); //It's for getting log for limit set
#endif
								}
							}
						}
						else
						{
							Result++;
#ifdef F54_Porting
							ret += sprintf(buf+ret, "%d\t", temp); //It's for getting log for limit set
#else
							printk("%d\t", temp); //It's for getting log for limit set
#endif							
						}
				  k = k + 2;
				}
#ifdef F54_Porting
				ret += sprintf(buf+ret, "\n");
#else
				printk("\n"); //It's for getting log for limit set
#endif				
			}

#ifdef F54_Porting
			ret += sprintf(buf+ret, "#3.04	Full raw capacitance Test END\n");
			ret += sprintf(buf+ret, "\n#3.01	Full raw capacitance Test Limit\n");

			// Print Capacitance Imgae for getting log for Excel format
			ret += sprintf(buf+ret, "\t");
#else
			printk("#3.04	Full raw capacitance Test END\n");

			printk("\n#3.01	Full raw capacitance Test Limit\n");
			// Print Capacitance Imgae for getting log for Excel format
			printk("\t");
#endif			
			for (j = 0; j < numberOfRx; j++) {
#ifdef F54_Porting
				ret += sprintf(buf+ret, "%d-Min\t%d-Max\t", j, j);
#else
				printk("%d-Min\t%d-Max\t", j, j);
#endif
			}

#ifdef F54_Porting
			ret += sprintf(buf+ret, "\n");
#else
			printk("\n");
#endif

			for (i = 0; i < numberOfTx; i++)
			{
#ifdef F54_Porting
				ret += sprintf(buf+ret, "%d\t", i);
#else
				printk("%d\t", i);
#endif
				for (j = 0; j < numberOfRx; j++)
				{
					if(mode==0) {
#ifdef F54_Porting
						//printk("%d\t%d\t", Limit[i][j*2], Limit[i][j*2+1]);
						ret += sprintf(buf+ret, "%d\t%d\t", Limit[i][j*2], Limit[i][j*2+1]);
#else
						printk("%d\t%d\t", Limit[i][j*2]*1000, Limit[i][j*2+1]*1000);
#endif
					} else {
#ifdef F54_Porting
						ret += sprintf(buf+ret, "%d\t%d\t", Flex_LowerLimit, Flex_UpperLimit);
#else
						printk("%d\t%d\t", Flex_LowerLimit, Flex_UpperLimit);
#endif
					}
				}
#ifdef F54_Porting
				ret += sprintf(buf+ret, "\n");
#else
				printk("\n");
#endif
			}
#ifdef F54_Porting
			ret += sprintf(buf+ret, "#3.02	Full raw cap Limit END\n");
#else
			printk("#3.02	Full raw cap Limit END\n");
#endif
			break;

		case 2:
			k = 0;	   
			for (i = 0; i < numberOfTx; i++)
			{
				for (j = 0; j < numberOfRx; j++)
				{
						temp = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
						   if (temp > TSPCheckLimit)
						   Result++;
				  k = k + 2;
				}	   
			}
			break;

		case 3:
		case 4:
			k = 0;	   
			for (i = 0; i < numberOfTx; i++)
			{
				for (j = 0; j < numberOfRx; j++)
				{
						ImageArray[i][j] = (short)(ImageBuffer[k] | (ImageBuffer[k+1] << 8));
				  k = k + 2;
				}	   
			}
#ifdef F54_Porting
				 // Print Capacitance Imgae for getting log for Excel format
				 ret += sprintf(ret+buf, "\n\t");
#else
				 // Print Capacitance Imgae for getting log for Excel format
				 printk("\n\t");
#endif
				 for (j = 0; j < numberOfRx; j++) {
#ifdef F54_Porting
					ret += sprintf(ret+buf, "RX%d\t", RxChannelUsed[j]);
#else
				 	printk("RX%d\t", RxChannelUsed[j]);
#endif
				 }
				 
#ifdef F54_Porting
				 ret += sprintf(buf+ret, "\n");
#else
				 printk("\n");
#endif
				 
				 for (i = 0; i < numberOfTx; i++)
				 {
#ifdef F54_Porting
					 ret += sprintf(buf+ret, "TX%d\t", TxChannelUsed[i]);
#else
					 printk("TX%d\t", TxChannelUsed[i]);
#endif
					 for (j = 0; j < numberOfRx; j++)
					 {
#ifdef F54_Porting					 
						if(mode == 3)		ret += sprintf(buf+ret, "%d\t", (ImageArray[i][j]) / 1000);
						else if(mode == 4)	ret += sprintf(buf+ret, "%d\t", ImageArray[i][j]);
#else
						if(mode == 3)	   printk("%d\t", (ImageArray[i][j]) / 1000);
						else if(mode == 4) printk("%d\t", ImageArray[i][j]);
						//if(mode == 3)	   printk("%1.3f\t", (float)(ImageArray[i][j]) / 1000);
						//else if(mode == 4) printk("%d\t", ImageArray[i][j]);
#endif
						 
					  }
#ifdef F54_Porting
				  ret += sprintf(ret+buf, "\n");
#else
				  printk("\n");
#endif
				 }
			break;

		default:
			break;
	}

	if(mode != 3 && mode != 4)
	{
		//Reset
		command= 0x01;
		writeRMI(F01_Cmd_Base, &command, 1);
		delayMS(200);
		readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high
	}
	
	if(mode >= 0 && mode < 2)
	{
		if(Result == numberOfTx * numberOfRx)
		{
#ifdef F54_Porting
			ret += sprintf(buf+ret, "Test Result: Pass\n");
			write_log(buf);
#else
			printk("Test Result: Pass\n");
#endif
			return 1; //Pass
		}
		else
		{
#ifdef F54_Porting
			ret += sprintf(buf+ret, "Test Result: Fail\n");
			write_log(buf);
#else
			printk("Test Result: Fail\n");
#endif
			return 0; //Fail
		}
	}
	else if(mode == 2)
	{
		if(Result == 0) return 0; //TSP Not connected
		else return 1; //TSP connected 
	 }
	else
	{
#ifdef F54_Porting
		write_log(buf);
#endif
		return 0;
	}
 }
//Clear LCD and return home
void LCD_Clear(void){
	HD44780_WriteByte(COMMAND, CMD_CLEARDISPLAY);
	cursorPosition=1; //cursor is positioned at home
	delayMS(15);//delay 15ms
}
Exemplo n.º 24
0
int F54_GetTxToGndReport(char *buf)
{
	unsigned char ImageBuffer[CFG_F54_TXCOUNT];
	unsigned char ImageArray[CFG_F54_TXCOUNT];
	unsigned char Result=0;

	int i, k;
	int shift;

	unsigned char command;
	int ret = 0;

	int waitcount;

	for (i = 0; i < CFG_F54_TXCOUNT; i++)
		ImageArray[i] = 0;

	// Set report mode to run Tx-to-GND
	command = 0x10;
	writeRMI(F54_Data_Base, &command, 1);

	command = 0x00;
	writeRMI(F54_Data_LowIndex, &command, 1);
	writeRMI(F54_Data_HighIndex, &command, 1);

	// Set the GetReport bit to run Tx-to-Tx
	command = 0x01;
	writeRMI(F54_Command_Base, &command, 1);

	// Wait until the command is completed
	waitcount = 0;
	do {
		if(++waitcount > 100)
		{
			pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
			return ret;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	readRMI(F54_Data_Buffer, &ImageBuffer[0], 4);

	// One bit per transmitter channel
	k = 0;
	for (i = 0; i < CFG_F54_TXCOUNT; i++)
	{
		k = i / 8;
		shift = i % 8;
		if(ImageBuffer[k] & (1 << shift)) ImageArray[i] = 1;
	}
/*
	ret += sprintf(buf+ret, "\n\nInfo: Tx=%d\n", numberOfTx);
	ret += sprintf(buf+ret, "\n=====================================================\n");
	ret += sprintf(buf+ret, "\tTransmitter To Ground Short Test\n");
	ret += sprintf(buf+ret, "=====================================================\n");
	ret += sprintf(buf+ret, " UsedTx:");

	for (i = 0; i < numberOfTx; i++) {
		ret += sprintf(buf+ret, "%5d", TxChannelUsed[i]);
	}
	ret += sprintf(buf+ret, "\n 1 :    ");
*/
	for (i = 0; i < numberOfTx; i++) {
		if(ImageArray[TxChannelUsed[i]]) {
			Result++;
			//ret += sprintf(buf+ret, "%5d", ImageArray[TxChannelUsed[i]]);
		}
/*		else {
			ret += sprintf(buf+ret, "%2d(*)", ImageArray[TxChannelUsed[i]]);
		}
*/
	}
	/*
	// Check against test limits
	printk("TxToGND Result\n");
	for (i = 0; i < numberOfTx; i++) {
		if(ImageArray[TxChannelUsed[i]] == TxGNDLimit)
			Result[i] = 'P'; //Pass
		else
			Result[i] = 'F'; //Fail
		printk("Tx%d = %c\n", TxChannelUsed[i], Result[i]);
	}
	 */

	if (Result == numberOfTx) {
		ret += sprintf(buf+ret, "RESULT: Pass\n");
	} else {
		ret += sprintf(buf+ret, "RESULT: Fail\n");
	}

	//enable all the interrupts
	//	SetPage(0x00);
	//Reset
	command= 0x01;
	writeRMI(F01_Cmd_Base, &command, 1);
	delayMS(200);
	readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high


	return ret;

}
Exemplo n.º 25
0
int main(void){
    int c;
    int b;
    int counterNewPassword = 0;
    int counterInputPassword = 0;
    int counterOldPassword = 0;
    initPins();
    initCounterValues();
    initTimers();
    initSerial();

    while (1) {
        c = getchar();
        if (isdigit(c)) {
            previousChar = c;
            if (c == '6') {
                if (strcmp(password, inputPassword) == 0) {
                    allowEntry();
                }
                else {
                    prohibitEntry();
                }
                delayMS(counterDelay);
                disableLedsAndRelay();
                memset(inputPassword, 0, 9);
                memset(oldPassword, 0, 9);
                previousChar = '~';
                counterInputPassword = 0;
                counterOldPassword = 0;
            }
            else if (c == '7') {
                if (strlen(newPassword) > 0 & strcmp(oldPassword, password) == 0) {
                    memset(password, 0, 9);
                    strcpy(password, newPassword);
                    memset(newPassword, 0, 9);
                    previousChar = '~';
                    counterNewPassword = 0;
                    blinkGreenLeds();
                }
                else {
                    blinkRedLeds();
                }
                memset(oldPassword, 0, 9);
                counterOldPassword = 0;
            }
            else {
                memset(inputPassword, 0, 9);
                memset(newPassword, 0, 9);
                counterNewPassword = 0;
                counterInputPassword = 0;
            }
        }
        else if (c >= 'A' & c <= '|') {
            switch (previousChar) {
            case '1':
                if (c >= 'A' & c <= 'J' & counterInputPassword < 8) {
                    //unosimo password u string inputPassword
                    inputPassword[counterInputPassword] = c;
                    counterInputPassword++;
                }
                if (c >= 'a' & c <= 'j' & counterInputPassword < 8) {
                    newPassword[counterNewPassword] = c - 32;
                    counterNewPassword++;
                }
                break;
            case '2':
                if (islower(c)) {
                    if (c <= 'm') {
                        //dozvoli paljenje ledica
                        ledStatus = 1;
                    }
                    else {
                        //blokiraj paljene ledica
                        ledStatus = 0;
                    }
                }
                else {
                    if (c <= 'M') {
                        //dozvoli koristenje senzora
                        sensorStatus = 1;
												blinkGreenLeds();
                    }
                    else {
                        //blokiraj koristenje senzora
                        sensorStatus = 0;
												blinkGreenLeds();
                    }
                }
                break;
            case '3':
                if (islower(c)) {
                    if (c <= 'x') {
                        //radno vrijeme u satima, npr. 1,2,3...
                        workingHours = c - 'a';
                    }
                }
                else {
                    if (c <= 'X') {
                        //sati koji ovise o trenutnoj vrijednosti brojaca; droid aplikacija ih racuna te salje ovdje
                        currentCounterHours = c - 'A';
                    }
                }
                break;
            case '4':
                //trenutne minute
                counterMinutes = c - 'A';
                break;
            case '5':
                if (islower(c)) {
                    if (c <= 'm') {
                        for (b = 0; b < 3; b++) {
                            blinkGreenLeds();
                        }
                    }
                    else {
                        for (b = 0; b < 3; b++) {
                            blinkRedLeds();
                        }
                    }
                }
                else {
                    if (c >= 'D' & c <= 'K') {
                        //kasnjenje ulaza u milisekundama, npr.1000,2000....10000
                        counterDelay = 1000 * (c - 'A');
                    }
                }
                break;
            case '8':
                if (c >= 'A' & c <= 'J' & counterOldPassword < 8) {
                    //unosimo password u string oldPassword
                    oldPassword[counterOldPassword] = c;
                    counterOldPassword++;
                }
                break;
                ;
            default:
                disableLedsAndRelay();
                break;
            }
        }
        if (sensorStatus) {
            if (IO0PIN & (1 << sensorPin)) {
                if (currentCounterHours < workingHours) {
                    allowEntry();
                }
                else {
                    prohibitEntry();
                }
            }
            else {
                disableLedsAndRelay();
            }
        }
        else {
            disableLedsAndRelay();
        }
    }
}
Exemplo n.º 26
0
static int testAPDUS(SCARDCONTEXT ctx, const char *readerName, const char *chipnrForCompare)
{
	SCARDHANDLE hCard;
	DWORD       protocol;
	int         err      = 0;
	int         errCount = 0;

	printf("Using reader \"%s\"\n\n", readerName);

	long ret = SCardConnectA(ctx, readerName,
		SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &protocol);

	CHECK_PCSC_RET("SCardConnect", ret);
	if (SCARD_S_SUCCESS == ret)
	{
		delayMS(200);

		unsigned char recvBuf[258];
		DWORD         recvBufLen = sizeof(recvBuf);

		// If chipnrForCompare == NULL then we retrieve the chip number
		// of this card to store all APDUs
		const char *thisChipNr = NULL;
		char       chipNrBuf[2 * CHIP_NR_LEN + 1];
		if (NULL == chipnrForCompare)
		{
			thisChipNr = GetChipNrFromCard(hCard, chipNrBuf);
			if (NULL == thisChipNr)
			{
				SCardDisconnect(hCard, SCARD_LEAVE_CARD);
				return -1;
			}
		}

		// Send all APDUs
		for (int i = 0; fixedTestAPDUS[i] != NULL; i++)
		{
			recvBufLen = (DWORD) sizeof(recvBuf);
			ret        = sendAPDU(hCard, fixedTestAPDUS[i],
				recvBuf, &recvBufLen, thisChipNr, i, NULL == chipnrForCompare);

			if (0 == ret && NULL != chipnrForCompare)
			{
				err = compareAPDUS(fixedTestAPDUS[i], recvBuf, recvBufLen,
					chipnrForCompare, i);
				if (err < 0)
					break;
				errCount += err;
			}
		}

		ret = SCardDisconnect(hCard, SCARD_LEAVE_CARD);
		CHECK_PCSC_RET("SCardDisconnect", ret);

		if (NULL == chipnrForCompare)
			printf("Done, stored APDUs to files who's names start with %s\n", thisChipNr);
		else if (err >= 0)
			printf("APDU Tests done, %d differences with chip %s)\n", errCount, chipnrForCompare);
	}

	return 0;
}
void main(void){  
	unsigned char i,cmd, param[9]; 
	//unsigned char t[]={"Hello World"};

    init();			//setup the crystal, pins
	usbbufflush();	//setup the USB byte buffer

delayMS(10);	

	HD44780_Reset();//setup the LCD
	HD44780_Init();

    USBDeviceInit();//setup usb

    while(1){

        USBDeviceTasks(); 

    	if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) continue;
		usbbufservice();//load any USB data into byte buffer
		
		cmd=waitforbyte();//wait for a byte from USB

		if(cmd!=MATRIX_ORBITAL_COMMAND){//assume text, if 254 then enter command mode

			LCD_WriteChar(cmd); //not a command, just write it to the display

		}else{//previous byte was 254, now get actual command

			switch(waitforbyte()){//switch on the command
				case BACKLIGHT_ON: //1 parameter (minutes 00=forever)
					param[0]=waitforbyte();
					LCD_Backlight(1);//turn it on, we ignore the parameter
					break;
				case BACKLIGHT_OFF:
					LCD_Backlight(0);//backlight off
					break;
				case CLEAR:
					LCD_Clear();
					break;
				case HOME:
					LCD_Home();
					break;
				case POSITION: //2 parameters (col, row)
					param[0]=waitforbyte();
					param[1]=waitforbyte();
					cmd=( ((param[1]-1)*20) + param[0] ); //convert to 20x4 layout (used defined lines, add rows...)
					LCD_CursorPosition(cmd);
					break;
				case UNDERLINE_CURSER_ON:
					LCD_UnderlineCursor(1);
					break;
				case UNDERLINE_CURSER_OFF:
					LCD_UnderlineCursor(0);
					break;
				case BLOCK_CURSER_ON:
					LCD_BlinkCursor(1);
					break;
				case BLOCK_CURSER_OFF:
					LCD_BlinkCursor(0);
					break;
				case BACKLIGHT_BRIGHTNESS://1 parameter (brightness)
					param[0]=waitforbyte();					
					break;
				case CUSTOM_CHARACTER: //9 parameters (character #, 8 byte bitmap)
					LCD_WriteCGRAM(waitforbyte());//write character address
					for(i=1; i<9; i++){
						LCD_WriteRAM(waitforbyte()); //send 8 bitmap bytes
					}
					break;
				default: //error
					break;
			}
		}
	    CDCTxService();
	}

}//end main
//return cursor to home
void LCD_Home(void){
	HD44780_WriteByte(COMMAND,CMD_RETURNHOME);
	cursorPosition=1; //cursor is positioned at home
	delayMS(2);//delay 15ms
}
Exemplo n.º 29
0
// Initialisation sequence to start LCD
void Init_LCD(void)
{
	
	//reset lcd and turn on back light
	LCD_RESET = 0xFF;
	delayMS(5);
	LCD_RESET = 0x00;
	delayMS(15);
	LCD_RESET = 0xFF;
	LCD_CS=0xFF;
	LCD_RD=0xFF;
	LCD_WR=0xFF;
	delayMS(20);
	
	
	//backlight
	LCD_BL = 0xFF;
	
	writeReg(0x0000,0x0001);    delayMS(5);   /* Enable LCD Oscillator */
	writeReg(0x0003,0xA8A4);    delayMS(5);   // Power control(1)
	writeReg(0x000C,0x0000);    delayMS(5);   // Power control(2)
	writeReg(0x000D,0x080C);    delayMS(5);   // Power control(3)
	writeReg(0x000E,0x2B00);    delayMS(5);   // Power control(4)
	writeReg(0x001E,0x00B0);    delayMS(5);   // Power control(5)
	writeReg(0x0001,0x2B3F);    delayMS(5);   // Driver Output Control /* 320*240 0x2B3F */
	writeReg(0x0002,0x0600);    delayMS(5);   // LCD Drive AC Control
	writeReg(0x0010,0x0000);    delayMS(5);   // Sleep Mode off
	writeReg(0x0011,0x6070);    delayMS(5);   // Entry Mode
	writeReg(0x0005,0x0000);    delayMS(5);   // Compare register(1)
	writeReg(0x0006,0x0000);    delayMS(5);   // Compare register(2)
	writeReg(0x0016,0xEF1C);    delayMS(5);   // Horizontal Porch
	writeReg(0x0017,0x0003);    delayMS(5);   // Vertical Porch
	writeReg(0x0007,0x0233);    delayMS(5);   // Display Control     // 0x0133 - 0x0233
	writeReg(0x000B,0x0000);    delayMS(5);   // Frame Cycle control
	writeReg(0x000F,0x0000);    delayMS(5);   // Gate scan start position
	writeReg(0x0041,0x0000);    delayMS(5);   // Vertical scroll control(1)
	writeReg(0x0042,0x0000);    delayMS(5);   // Vertical scroll control(2)
	writeReg(0x0048,0x0000);    delayMS(5);   // First window start
	writeReg(0x0049,0x013F);    delayMS(5);   // First window end
	writeReg(0x004A,0x0000);    delayMS(5);   // Second window start
	writeReg(0x004B,0x0000);    delayMS(5);   // Second window end
	writeReg(0x0044,0xEF00);    delayMS(5);   // Horizontal RAM address position
	writeReg(0x0045,0x0000);    delayMS(5);   // Vertical RAM address start position
	writeReg(0x0046,0x013F);    delayMS(5);   // Vertical RAM address end position
	writeReg(0x0030,0x0707);    delayMS(5);   // gamma control(1)
	writeReg(0x0031,0x0204);    delayMS(5);   // gamma control(2)
	writeReg(0x0032,0x0204);    delayMS(5);   // gamma control(3)
	writeReg(0x0033,0x0502);    delayMS(5);   // gamma control(4)
	writeReg(0x0034,0x0507);    delayMS(5);   // gamma control(5)
	writeReg(0x0035,0x0204);    delayMS(5);   // gamma control(6)
	writeReg(0x0036,0x0204);    delayMS(5);   // gamma control(7)
	writeReg(0x0037,0x0502);    delayMS(5);   // gamma control(8)
	writeReg(0x003A,0x0302);    delayMS(5);   // gamma control(9)
	writeReg(0x003B,0x0302);    delayMS(5);   // gamma control(10)
	writeReg(0x0023,0x0000);    delayMS(5);   // RAM write data mask(1)
	writeReg(0x0024,0x0000);    delayMS(5);   // RAM write data mask(2)
	writeReg(0x0025,0x8000);    delayMS(5);   // Frame Frequency
	writeReg(0x004f,0);                       // Set GDDRAM Y address counter
	writeReg(0x004e,0);                       // Set GDDRAM X address counter
	
	delayMS(5);
}