This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2530: Sensitive Push Button Part#2

Part Number: CC2530


Hi Guys, 

I working to implement a sensitive push button based on existent OSAL timer and I have to understand how to increase and decrease dimmer level. As I have posted the main algorithm I have done before.

- Normal press just turn on or off

- Press and hold more than 3 seconds the first time will increase the level,

- Press and hold more than 3 seconds will decrease level,

my last threads for references: https://e2e.ti.com/support/wireless-connectivity/zigbee-and-thread/f/158/p/830526/3072158#3072158

We have two existent LEVEL CONTROL functions, as I described below. I do not know each one I can use, maybe I need to create a new one.

zclTTa0003_LevelControlMoveToLevelCB, // Level Control Move to Level command
zclTTa0003_LevelControlMoveCB, // Level Control Move command

Part of my BtnHOLD_EVT code:

  if ( events & TTa0003_BtnHOLD_EVT )
  {
   uint8  UPLevel;
   uint8  DOWNLevel;
     if ( HAL_PUSH_BUTTON1())//Btn long press
	 {
     // BtnHoldCnt++;
			       
			if(BtnHoldCnt >=30)
			{ 
				BtnHoldCnt=0;
				HalLedSet (HAL_LED_3, HAL_LED_MODE_ON);  
				    if ( ( zclTTa0003_LevelCurrentLevel >= LEVEL_MIN && zclTTa0003_LevelCurrentLevel < LEVEL_MAX ) || ( zclTTa0003_OnOff == LIGHT_OFF ) ) {
							UPLevel = zclTTa0003_LevelCurrentLevel + 30;
							// start the dimmer LEVEL UP Command ???
					   } else if ( zclTTa0003_LevelCurrentLevel == LEVEL_MAX ){
							DOWNLevel = zclTTa0003_LevelCurrentLevel - 30;
							// start the dimmer LEVEL DOWN Command ???
					   }
			} else {
				BtnHoldCnt++;
				HalLedSet ( HAL_LED_3, HAL_LED_MODE_OFF);
				osal_start_timerEx( zclTTa0003_TaskID, TTa0003_BtnHOLD_EVT, 100);}
		
    } else // Btn short press
		{ret=osal_start_timerEx( zclTTa0003_TaskID, TTa0003_BtnHOLD_EVT, 100);} // return to handle key
    
	return ( events ^ TTa0003_BtnHOLD_EVT );
  }

Please, someone can give an idea?

BR,

Alex

  • Hi Alex,

    YK has already greatly helped develop your application and I am not sure what this new support request is for.  Based on the code description you are most likely interested in the Move to Level Command (ID 0x00) for a specific level at a given transition time.  The Move Command (0x01) alternatively would move fully up or down at a specified rate.  You can learn more about the level control cluster through the light/switch examples, ZCL Specification, Zigbee HA Profile, and Zigbee Lighting and Occupancy Device Specification documents.  

    Regards,
    Ryan

  • Hi Ryan,


    I understand I'm flattered by the help YK has given me! otherwise, I always try to document everything to leave material for future reference in the forum!

    @Ryan I have progressed yesterday to using the move command, this command supports my new level variable (UP/DOWN) and I included remaining time to ZERO. I´m right now working on to a better understanding of in my code how to discover the direction (up or down). I´ll let you know it according to my progress.  

    , thank you very much! I really appreciate it!

    BR,

    Alex

  • Hi Mr. Yk and Ryan. I would like to say thanks a lot for your assistance. 

    Mr. Yk, I dedicated this progress for you, especially for your tireless help!

    I was finished the sw_6 algorithm that gives turn-on/off and Levels Up/Down. As they can see below:

      if ( keys & HAL_KEY_SW_6) 
      { osal_start_timerEx( zclTTa0003_TaskID, TTa0003_BtnHOLD_EVT, 100);
    	    	//step 1 UP
    			if (direction ==0) {
    				if (( zclTTa0003_LevelCurrentLevel >= LEVEL_MIN) && (zclTTa0003_LevelCurrentLevel <=0x19)) {
    						zclTTa0003_LevelCurrentLevel =0x20;
    						direction=0;
    						// start the dimmer LEVEL UP Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);
    	//step 2 UP		
    				} else if (( zclTTa0003_LevelCurrentLevel >= 0x20) && ( zclTTa0003_LevelCurrentLevel <=0x32)) {
    						zclTTa0003_LevelCurrentLevel =0x33;
    						direction=0;
    						// start the dimmer LEVEL UP Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);
    	//step 3 UP			
    				} else if (( zclTTa0003_LevelCurrentLevel >= 0x33) && ( zclTTa0003_LevelCurrentLevel <=0x4B))  {
    						zclTTa0003_LevelCurrentLevel =0x4C;
    						direction=0;
    						// start the dimmer LEVEL UP Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);
    	//step 4UP	 			
    				} else if ((zclTTa0003_LevelCurrentLevel >= 0x4C) && (zclTTa0003_LevelCurrentLevel <=0x64)) {
    						zclTTa0003_LevelCurrentLevel =0x65;
    						direction=0;
    						// start the dimmer LEVEL UP Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);
    	//step 5 UP					
    				}else if ((zclTTa0003_LevelCurrentLevel >= 0x65) && (zclTTa0003_LevelCurrentLevel <=0x7D)) {
    						zclTTa0003_LevelCurrentLevel =0x7E;
    						direction=0;
    						// start the dimmer LEVEL UP Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);
    	//step 6 UP					
    				} else if ((zclTTa0003_LevelCurrentLevel >= 0x7E) && (zclTTa0003_LevelCurrentLevel <=0x96)) {
    						zclTTa0003_LevelCurrentLevel =0x97;
    						direction=0;
    						// start the dimmer LEVEL UP Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);				
    	//step 7 UP		
    				} else if ((zclTTa0003_LevelCurrentLevel >= 0x97) && (zclTTa0003_LevelCurrentLevel <=0xAF)) {
    						zclTTa0003_LevelCurrentLevel =0xB0;
    						direction=0;
    						// start the dimmer LEVEL UP Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);					
    	//step 8 UP			
    				}  else if ((zclTTa0003_LevelCurrentLevel >= 0xB0) && (zclTTa0003_LevelCurrentLevel <=0xC8)) {
    						zclTTa0003_LevelCurrentLevel =0xC9;
    						direction=0;
    						// start the dimmer LEVEL UP Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);						
    	//step 9 UP		
    				}  else if ((zclTTa0003_LevelCurrentLevel >= 0xC9) && (zclTTa0003_LevelCurrentLevel <=0xE1)) {
    						zclTTa0003_LevelCurrentLevel =0xE2;
    						direction=0;
    						// start the dimmer LEVEL UP Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);		
    	//step 10 UP	
    				} else if ((zclTTa0003_LevelCurrentLevel >= 0xE2) && (zclTTa0003_LevelCurrentLevel <=LEVEL_MAX)) {
    						zclTTa0003_LevelCurrentLevel =0xFC;
    						direction =1;
    						// start the dimmer LEVEL UP Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);
    				}
    			} else if (direction ==1) {
    						
    	// step 1 DOWN					
    					if (((zclTTa0003_LevelCurrentLevel <= LEVEL_MAX) && (zclTTa0003_LevelCurrentLevel >=0xE2)) && direction) {
    						zclTTa0003_LevelCurrentLevel =0xE1;
    						// start the dimmer LEVEL DOWN Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);	
    	// step 2 DOWN						
    						} else if (((zclTTa0003_LevelCurrentLevel <= 0xE1) && (zclTTa0003_LevelCurrentLevel >=0xC9)) && direction) {
    						zclTTa0003_LevelCurrentLevel =0xC8;
    						// start the dimmer LEVEL DOWN Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);	
    	// step 3 DOWN						
    						} else if (((zclTTa0003_LevelCurrentLevel <= 0xC8) && (zclTTa0003_LevelCurrentLevel >=0xB0)) && direction) {
    						zclTTa0003_LevelCurrentLevel =0xAF;
    						// start the dimmer LEVEL DOWN Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);	
    	// step 4 DOWN						
    						} else if (((zclTTa0003_LevelCurrentLevel <= 0xAF) && (zclTTa0003_LevelCurrentLevel >=0x97)) && direction) {
    						zclTTa0003_LevelCurrentLevel =0x96;
    						// start the dimmer LEVEL DOWN Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);	
    	// step 5 DOWN						
    						} else if ((zclTTa0003_LevelCurrentLevel <= 0x96) && (zclTTa0003_LevelCurrentLevel >=0x7E) && direction) {
    						zclTTa0003_LevelCurrentLevel =0x7D;
    						// start the dimmer LEVEL DOWN Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);	
    	// step 6 DOWN						
    						} else if (((zclTTa0003_LevelCurrentLevel <= 0x7D) && (zclTTa0003_LevelCurrentLevel >=0x65)) && direction) {
    						zclTTa0003_LevelCurrentLevel =0x64;
    						// start the dimmer LEVEL DOWN Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);	
    	// step 7 DOWN												
    						} else if ((zclTTa0003_LevelCurrentLevel <= 0x64) && (zclTTa0003_LevelCurrentLevel >=0x4C) && direction) {
    						zclTTa0003_LevelCurrentLevel =0x4B;
    						// start the dimmer LEVEL DOWN Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);	
    	// step 8 DOWN						
    						} else if (((zclTTa0003_LevelCurrentLevel <= 0x4B) && (zclTTa0003_LevelCurrentLevel >=0x33)) && direction) {
    						zclTTa0003_LevelCurrentLevel =0x32;
    						// start the dimmer LEVEL DOWN Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);	
    	// step 9 DOWN						
    						} else if (((zclTTa0003_LevelCurrentLevel <= 0x32) && (zclTTa0003_LevelCurrentLevel >=0x1A)) && direction) {
    						zclTTa0003_LevelCurrentLevel =0x19;
    						// start the dimmer LEVEL DOWN Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);	
    	// step 10 DOWN						
    						} else if (((zclTTa0003_LevelCurrentLevel <= 0x19) && (zclTTa0003_LevelCurrentLevel >=0x02)) && direction) {
    						zclTTa0003_LevelCurrentLevel =LEVEL_MIN;
    						direction=0;
    						// start the dimmer LEVEL DOWN Command 
    						zclTTa0003_MoveBasedOnTime(zclTTa0003_LevelCurrentLevel,0);	
    	// Step down stage end
    						} 
    			}		
    
      } 
    

    The last one I need to implement is ZCL level response for each one level that was changed, by a mechanical switch (SW_6),  from device to the gateway. I´ll study how to implement it and soon as possible, I´ll share it here!

  • Thanks for sharing!

  • I that need to say thanks for you help Mr. YK!