Example #1
0
static void taskReadButton(void * a)
{
	
   button_t  button;
   
   //Init the struct
   button.number=0;
   button.state=RELEASE;
   button.time=0;
   
   uint32_t  buttonTime=0;

   while(1)
   {
        //Delay - Who often the task will be entered
        vTaskDelay(UPDATE_BUTTON_TIME/portTICK_RATE_MS); 
        
        //Check if it is press
        if (!ciaaReadInput(button.number))
        {
            button.time+=UPDATE_BUTTON_TIME; //if press add UPDATE_BUTTON_TIME
            if (button.time>2000000000)   //Set the limit
                button.time=2000000000;  
            if (button.time>TIME_NOT_REBOUND) 
              {
                button.state=PRESS;    
              } 
        }
        else
        {
            button.state=RELEASE;
            if (button.time>TIME_NOT_REBOUND)
              {
                //take the time of press in mseg
                buttonTime=button.time;
                xQueueSend( xQueue1, ( void * ) &buttonTime, 0);

              }
            button.time=0;
            
        }

        if(button.state==PRESS)
          {  
            ciaaWriteOutput(0,1);  //Led RED ON
          }
          else
          {
            ciaaWriteOutput(0,0);  //Led RED OFF
          }  
        


   }

}
Example #2
0
static void taskReadButton(void * a)
{
	
   button_t  button;
   
   //Init the struct
   button.number=0;
   button.state=RELEASE;
   button.time=0;
   


   while(1)
   {
        //Delay
        vTaskDelay(TIME_NOT_REBOUND/portTICK_RATE_MS); 
        
        //check if it is press
        if (!ciaaReadInput(button.number))
        {
            button.time++;
            if (button.time>65000)
                button.time=65000;
            if (button.time>TICKS_BUTTON)
                button.state=PRESS; 

        }
        else
        {
            button.state=RELEASE;
            if (button.time>TICKS_BUTTON)
              {
                xSemaphoreGive(xSemaphore);
                //take the time of press in mseg
                buttonTime=(button.time-TICKS_BUTTON)*TIME_NOT_REBOUND;
              }
            button.time=0;
            
        }

        if(button.state==PRESS)
          {  
            ciaaWriteOutput(0,1);  //Led RED ON
          }
          else
          {
            ciaaWriteOutput(0,0);  //Led RED OFF
          }  
        


   }

}