コード例 #1
0
ファイル: detective.c プロジェクト: Snootlab/Zombadge
int main (void)
{
  configuration();
  sei();
  
 while(1)
    {
 
		  if(state.mode_fct==RECEIVE&&state.alive==TRUE)					//while we are in RECEIVE mode (no action on the button) and still alive, we are waiting to receive IR transmissions
		{	
		  IR_rx_on_tx_off();
		  next_couleur.red=0;next_couleur.green=255;next_couleur.blue=0;	// turn on the green led for half a second
		  rgb_led_on();			
		  while(state.mode_fct==RECEIVE&&state.alive==TRUE)
			{
			  rcv_IR(limit_default_ptr,0);
			  analyse_trame();
			}
		  rgb_led_off();
		}else if(state.mode_fct==EMMIT&&state.alive==TRUE&&state.role==ASSASSIN)	//while the button is pushed, we are alive and allowed to kill, emmit and change the RBG cycle
		  {
			
			IR_rx_off_tx_on();
			next_couleur.red=255;next_couleur.green=0;next_couleur.blue=0;// turn on the red led for half a second
			rgb_led_on();	
			tempo_ten_us(150000);			
			while(state.mode_fct==EMMIT&&state.alive==TRUE)
			  {
				send_NEC(MY_ID,MY_ID_COMP,KILL_ORDER,KILL_ORDER_COMP);
				tempo_ten_us(4000);
			  }
			rgb_led_off();
		  }else if(state.mode_fct==EMMIT&&state.alive==TRUE&&state.role==VICTIM)	//while the button is pushed, we are alive and not allowed to kill, not emmit and change the RBG cycle
		  {
			rgb_led_off();	
			GREEN_ON;
			while(state.mode_fct==EMMIT);
			LED_OFF;
		  }
		  else																		//when we are dead, change the RGB cycle and put the state.alive = FALSE (not allowed to emmit/receive anymore)
			{
				IR_rx_off_tx_on();
				next_couleur.red=0;next_couleur.green=0;next_couleur.blue=255;// turn on the blue led for half a second
				rgb_led_on();		
				while(1);
			}
    }
}
コード例 #2
0
ファイル: commands.c プロジェクト: ohanssen/ArcticTracker
static void cmd_led(Stream *chp, int argc, char* argv[])
{
  if (argc < 4) {
    if (strncasecmp("off", argv[0], 2) == 0)
      rgb_led_off();
    else {
       chprintf(chp, "Usage: LED <R> <G> <B> <off>\r\n");
       chprintf(chp, "       LED OFF \r\n");
    }
    return;
  }
  int r,g,b,off;
  r=atoi(argv[0]);
  g=atoi(argv[1]);
  b=atoi(argv[2]);
  off=atoi(argv[3]);
  rgb_led_mix((uint8_t) r, (uint8_t) g, (uint8_t) b, (uint8_t) off);
}
コード例 #3
0
ファイル: detective.c プロジェクト: Snootlab/Zombadge
/*
After quitting the rcv_IR, this function analyse what we received.
If error = 1, let's reset the reception to his beginning configuration.
If the data frame's lenght is normal and no error encoutered, then do the data error detection (complementarity).
If no error in data received is detected, then do the given action.
*/
void analyse_trame(void)
{
  if(ir_rcv.error_encountered!=FALSE)
    {
      reset_reception();
    }
  else if(ir_rcv.state_count==67 && ir_rcv.mode==END_RCV)
    {
	
      if( (ir_rcv.command1+ir_rcv.command2==0xFF) && (ir_rcv.data1+ir_rcv.data2==0xFF) )
		{
		// If reception encountered no troubles :
		if(ir_rcv.data1==(unsigned char)KILL_ORDER)
			{
			  tempo_ten_us(2000000);
			  rgb_led_off();			//Stop the ISR
			  state.alive=DEAD;		//Z-(ombadge) is dead baby, Z-(ombadge) is dead...
			} 
		}
     
    }
  reset_reception();
}