コード例 #1
0
ファイル: mbed_usbserial.cpp プロジェクト: kphannan/openmrn
 /** Transmits count bytes from the txData buffer. Sets txPending and
     bytesLost as needed. @return true if we consumed some data from the tx
     buffer. */
 bool TxHelper()
 {
     size_t count;
     bool signal = false;
     for (count = 0; count < MAX_TX_PACKET_LENGTH;)
     {
         uint8_t *data;
         size_t max_count = std::min(txBuf->data_read_pointer(&data),
                                     MAX_TX_PACKET_LENGTH - count);
         if (max_count)
         {
             memcpy(&txData[count], data, max_count);
             count += max_count;
             txBuf->consume(max_count);
             signal = true;
         }
         else
         {
             break;
         }
     }
     if (!count)
     {
         txPending = false;
         return signal;
     }
     if (!configured())
     {
         // An error occured, data was lost.
         txPending = false;
         overrunCount += count;
         return signal;
     }
     txPending = true;
     sendNB(txData, count);
     return signal;
 }
コード例 #2
0
ファイル: main.c プロジェクト: nixphix/Tron
int main(void)
{

	USART_Init(103);
	TIMSK=(1<<TOIE1); // enabled global and timer overflow interrupt;
	TCNT1=0xBDB; // set initial value to remove time error (16bit counter register)
	TCCR1B = (1<<CS12)|(0<<CS11)|(0<<CS10); // start timer/ set clock
	DDRA=0x0F;
	PORTA=0X0F;
	DDRC=0xFF;
	PORTC=0xFF;
	DDRB=0x00;
	DDRD=0xFF;
	
	GLCD_Init128();	
	picture(&sportronix[0]);
	sei();
	
	
	while(1)
	{
		_av=keypad_4keys();
		
		// get into this loop only when the home button is pressed, also clear the existing team names since there s no option for backspace		
		
		if(menu == 3)
		{
		 USART_RxIntEN();
		 lcdputs2(46,2,ar3);		//score 
	     lcdputs2(5,6,ar4);
	     lcdputs2(110,6,ar4);		//FOUL
	     lcdputs2(58,6,ar6);
	     
	     lcdnumdata(25,3,AS);
	     lcdnumdata(85,3,BS);
	     lcdnumdata(55,7,QT);
	     lcdnumdata(5,7,AF);
	     lcdnumdata(110,7,BF);
		  menu++;
		}
		else if(menu == 1)
		{
			// for displaying teama name
			lcdputs2(16,3,ar7);		
			setcolumn(40);
			setpage(4);
			 
			for(int k=0;((k<6));k++)
			{
				if(teama[k]!=0x01)
				{
					lcdsim_chardata((40+(k*8)),4,teama[k]);
				}
				else
				{
					lcd_bs(6);
				}
			}
		}		
		else if(menu == 2)  // for displaying teamb name
		{
			lcdputs2(16,3,ar8);		
			setcolumn(40);
			setpage(4);
         
			for(int k=0;((k<6));k++)	//&(teamb[k]!=0x01)
			{
				if(teamb[k]!=0x01)
				{
					lcdsim_chardata((40+(k*8)),4,teamb[k]);
				}
				else
				{
					lcd_bs(6);
				}
			}
		}
		
		
		
		// now analyze the team names and put them into a PROPER array format.
		
		
		if(_av==2) // home button
		{
			//_ch=0;
			menu++;
			sendNB(); // Send the data to main board
			if(menu!=0)
			{
				clrlcd();
				_delay_ms(5);
			}
			if(menu>3)
			{
				menu=1;			// exit out of the menu and capture the team names
				_ch=0;
				USART_RxIntDE();
			}
			//USART_Transmit(2);
		}
		else if((_av == 0)&(menu == 1)) // buzzer USART_Transmit(0);
		{
			if(indexA>=0)
			{
				indexA--;
				if(indexA<0)
				{
					indexA=0;
				}
				teama[indexA]=0x01;
			}
		}	
		else if((_av == 0)&(menu == 2))	// buzzer USART_Transmit(0);
		{
			if(indexB>=0)
			{
				indexB--;
				if(indexB<0)
				{
					indexB=0;
				}
				teamb[indexB]=0x01;
			}
		}	
		else if((_av==1) & (menu == 1))   // A-Z
		{
			if(o_sec==1)
			{
				_ch=0;
			}
			 
			if(_ch<0)
			{
			    _ch=37;
			}	
            if(_ch>37)
			{
			    _ch=0;
			}
			 
			km = keymap[_ch];
			_ch++;
			if(o_sec==0)
			{
				if(indexA>0)
				{
					indexA--; 
					if(indexA<0)
					{
						indexA=0;
					}
				}
			}
			 
			teama[indexA]=(km);
			 
			indexA++;
			if(indexA>=6)
			{
			  indexA=6;
			}
			//USART_Transmit(1);
			
			t1_rst();
		}
		else if((_av == 1) & (menu == 2))   // A-Z
		{
			if(o_sec==1)
			{
				_ch=0;
			}
			 
			if(_ch<0)
			{
			    _ch=37;
			}	
            if(_ch>37)
			{
			    _ch=0;
			}
			 
			km = keymap[_ch];
			_ch++;
			if(o_sec==0)
			{
				if(indexB>0)
				{
					indexB--; 
					if(indexB<0)
					{
						indexB=0;
					}
				}
			}
			 
			teamb[indexB]=(km);	
           		
			indexB++;
			if(indexB>=6)
			{
			  indexB=6;
			}
			//USART_Transmit(1);
			
			t1_rst();
		}
		else if((_av == 3) & (menu == 1))		// Z-A
		{
			//USART_Transmit(3);
			if(o_sec==1)
			{
				_ch=0;
			}
			
			_ch--;
			if(_ch<0)
			{
			    _ch=37;
			}
			 
			if(_ch<0)
			{
			    _ch=37;
			}	
            if(_ch>37)
			{
			    _ch=0;
			}
			km = keymap[_ch];
			 
			if(o_sec==0)
			{
				if(indexA>0)
				{
					indexA--; 
					if(indexA<0)
					{
						indexA=0;
					}
				}
			}
			 
			teama[indexA]=(km);
			 
			indexA++;
			if(indexA>=6)
			{
			  indexA=6;
			}
			//USART_Transmit(1);
			t1_rst();
		}
		else if((_av == 3) & (menu == 2))		// Z-A
		{
			//USART_Transmit(3);
			if(o_sec==1)
			{
				_ch=0;
			}
			
			_ch--;
			if(_ch<0)
			{
			    _ch=37;
			}
			 
			if(_ch<0)
			{
			    _ch=37;
			}	
            if(_ch>37)
			{
			    _ch=0;
			}
			km = keymap[_ch];
			 
			if(o_sec==0)
			{
				if(indexB>0)
				{
					indexB--; 
					if(indexB<0)
					{
						indexB=0;
					}
				}
			}
			 
			teamb[indexB]=(km);
			 
			indexB++;
			if(indexB>=6)
			{
			  indexB=6;
			}
			//USART_Transmit(1);
			
			t1_rst();
		}
		
	}
}