/****************************************************************************
 *
 * NAME:		vStartNonSleepPreventingTimers
 *
 * DESCRIPTION: Start the timers that wont stop us in vAttemptToSleep
 *
 ****************************************************************************/
PRIVATE void vStartNonSleepPreventingTimers(void)
{
#ifndef DEEP_SLEEP_ENABLE
	if (OS_eGetSWTimerStatus(APP_TickTimer) != OS_E_SWTIMER_RUNNING)
		OS_eStartSWTimer(APP_TickTimer, ZCL_TICK_TIME, NULL);
#endif
}
Exemple #2
0
/****************************************************************************
 *
 * NAME: vResetATimer
 *
 * DESCRIPTION:
 * tool function for stop and then start a software timer
 *
 * PARAMETERS: Name         RW  Usage
 *             hSWTimer     R   handler to sw timer
 *             u32Ticks     R   ticks of cycle
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PUBLIC void vResetATimer(OS_thSWTimer hSWTimer, uint32 u32Ticks)
{
    if (OS_eGetSWTimerStatus(hSWTimer) != OS_E_SWTIMER_STOPPED)
    {
        OS_eStopSWTimer(hSWTimer);
    }
    OS_eStartSWTimer(hSWTimer, u32Ticks, NULL);
}
/****************************************************************************
 *
 * NAME:		vStopNonSleepPreventingTimers
 *
 * DESCRIPTION: The timers in this function should not stop us from sleep.
 * Stop the timers to reduce the activity count which will prevent sleep.
 *
 ****************************************************************************/
PRIVATE void vStopNonSleepPreventingTimers()
{
#ifndef DEEP_SLEEP_ENABLE
	if (OS_eGetSWTimerStatus(APP_TickTimer) != OS_E_SWTIMER_STOPPED)
		OS_eStopSWTimer(APP_TickTimer);
#endif

}
/****************************************************************************
 *
 * NAME: vManageIndividualControlMode
 *
 * DESCRIPTION:
 * Manage the Individual control modes for the lights in unicast mode
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vManageIndividualControlMode(te_SwitchState *peSwitchState, te_TransitionCode eTransitionCode )
{
      /* Calls individual function
       * Changes state
       * Addressing for individual functions
       *               Individual or group ? - well the address will be taken based on the state */
    DBG_vPrintf(TRACE_SWITCH_STATE,"\nIn vManageIndividualControlMode(Mode = %d) TransitionCode = %d -> ", *peSwitchState,eTransitionCode);
    switch(eTransitionCode)
    {
        /* Fall through for the button presses as there will be a delayed action*/
          case ON_PRESSED:

          case OFF_PRESSED:

          case UP_PRESSED:

          case DOWN_PRESSED:
              vQButtonPress(eTransitionCode);
              break;

          case UP_AND_ON_TOGETHER_PRESSED:
              vDQButtonPress();
              DBG_vPrintf(TRACE_SWITCH_STATE," vAppStoreSceneById = 1 \n");
              vAppStoreSceneById(SCENE_1, u16GroupId);
              *peSwitchState = LIGHT_CONTROL_MODE;
              break;

          case DOWN_AND_OFF_TOGETHER_PRESSED:
              vDQButtonPress();
              DBG_vPrintf(TRACE_SWITCH_STATE," vAppStoreSceneById = 2 \n");
              vAppStoreSceneById(SCENE_2, u16GroupId);
              *peSwitchState = LIGHT_CONTROL_MODE;
              break;

         case COMM_BUTTON_PRESSED:
              *peSwitchState = IDENTIFY_MODE;
              vAppDiscover();
              break;

          case DOWN_RELEASED:
          case UP_RELEASED:
              vDQButtonPress();
			  DBG_vPrintf(TRACE_SWITCH_STATE," vAppLevelStop \n");
			  vAppLevelStop();
              break;

          default :
              break;
    }
    /*Restart the Timer from expiring */
    if( OS_eGetSWTimerStatus(App_ChangeModeTimer) == OS_E_SWTIMER_EXPIRED )
    {
        OS_eStopSWTimer(App_ChangeModeTimer);
        *peSwitchState = LIGHT_CONTROL_MODE;
    }
    else
    	vStopStartModeChangeTimer(APP_TIME_MS(30000));
}
/****************************************************************************
 *
 * NAME: vStopStartModeChangeTimer
 *
 * DESCRIPTION:
 * Stops and starts the commissioning timer with required ticks
 *
 * PARAMETERS:
 * u32Ticks     Ticks for timer start
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vStopStartModeChangeTimer( uint32 u32Ticks )
{
    if( OS_eGetSWTimerStatus(App_ChangeModeTimer) != OS_E_SWTIMER_STOPPED )
    {
        OS_eStopSWTimer(App_ChangeModeTimer);
    }
    #ifdef SLEEP_ENABLE
        if( FALSE == bWatingToSleep())
        {
            OS_eStartSWTimer(App_ChangeModeTimer, u32Ticks, NULL );
        }
    #else
        OS_eStartSWTimer(App_ChangeModeTimer, u32Ticks, NULL );
    #endif
}
/****************************************************************************
 *
 * NAME:		u8NumberOfTimersTaskTimers
 *
 * DESCRIPTION: Checks to see if any timers are running that shouldn't be
 * interrupted by sleeping.
 *
 ****************************************************************************/
PRIVATE uint8 u8NumberOfTimersTaskTimers(void)
{
	uint8 u8NumberOfRunningTimers = 0;

	if (OS_eGetSWTimerStatus(APP_ButtonsScanTimer) == OS_E_SWTIMER_RUNNING)
	{
		DBG_vPrintf(TRACE_SLEEP_HANDLER, "\nAPP Sleep Handler: APP_ButtonsScanTimer");
		u8NumberOfRunningTimers++;
	}

	if (OS_eGetSWTimerStatus(APP_JoinTimer) == OS_E_SWTIMER_RUNNING)
	{
		DBG_vPrintf(TRACE_SLEEP_HANDLER, "\nAPP Sleep Handler: APP_JoinTimer");
		u8NumberOfRunningTimers++;
	}

	if (OS_eGetSWTimerStatus(App_EZFindAndBindTimer) == OS_E_SWTIMER_RUNNING)
	{
		DBG_vPrintf(TRACE_SLEEP_HANDLER, "\nAPP Sleep Handler: App_EZFindAndBindTimer");
		u8NumberOfRunningTimers++;
	}

	if (OS_eGetSWTimerStatus(APP_PollTimer) == OS_E_SWTIMER_RUNNING)
	{
		DBG_vPrintf(TRACE_SLEEP_HANDLER, "\nAPP Sleep Handler: APP_PollTimer");
		u8NumberOfRunningTimers++;
	}

	if (OS_eGetSWTimerStatus(APP_BlinkTimer) == OS_E_SWTIMER_RUNNING)
	{
		DBG_vPrintf(TRACE_SLEEP_HANDLER, "\nAPP Sleep Handler: APP_JoinBlinkTimer");
		u8NumberOfRunningTimers++;
	}

	if (OS_eGetSWTimerStatus(APP_BackOffTimer) == OS_E_SWTIMER_RUNNING)
	{
		DBG_vPrintf(TRACE_SLEEP_HANDLER, "\nAPP Sleep Handler: APP_BackOffTimer");
		u8NumberOfRunningTimers++;
	}

	return u8NumberOfRunningTimers;
}
/****************************************************************************
 *
 * NAME: vHandleNetworkScreenEvent
 *
 * DESCRIPTION:
 * Handles stack events when the Controller is in its "network" display mode state
 *
 * PARAMETERS: Name         RW  Usage
 *             sStackEvent  R   Contains details of the stack event
 *
 * RETURNS:
 * Sequence number
 *
 ****************************************************************************/
PRIVATE void vHandleNetworkScreenEvent(ZPS_tsAfEvent sStackEvent, APP_tsEvent sAppEvent)
{
//	uint8 *u8Char;
//	string u8Char1;
//	uint8 *u8String;
    /* respond to button presses when in "network" display mode */
    if (APP_E_EVENT_BUTTON_DOWN == sAppEvent.eType)
    {
        if (APP_E_BUTTONS_BUTTON_1 == sAppEvent.sButton.u8Button)
        {
            DBG_vPrintf(TRACE_APP, "Starting join toggle timer\n");
            OS_eStopSWTimer(APP_tmrJoiningButton);
            OS_eStartSWTimer(APP_tmrJoiningButton, APP_TIME_MS(2000), NULL);
        }
    }

    if (APP_E_EVENT_BUTTON_UP == sAppEvent.eType)
    {
        if (APP_E_BUTTONS_BUTTON_1 == sAppEvent.sButton.u8Button)
        {
            if (OS_E_SWTIMER_RUNNING == OS_eGetSWTimerStatus(APP_tmrJoiningButton))
            {
                /*
                 * Button press was too short to trigger permit-join toggling
                 * therefore it was pressed in order to switch to the node
                 * display screen.
                 *
                 * Stop timer to prevent toggling from occurring.
                 */
                OS_eStopSWTimer(APP_tmrJoiningButton);

                /* If at least one sensor has joined, then it is valid to go
                 * to the node display screen
                 */
                if (0 < APP_u8ControllerNodeNumDataSensors())
                {
                    APP_vDisplaySetState(APP_E_DISPLAY_STATE_NODE);
                    APP_vDisplayUpdate();
                    s_sDevice.eState = E_NODE_SCREEN;
                }
            }
        }
        else if (APP_E_BUTTONS_BUTTON_2 == sAppEvent.sButton.u8Button)
        {
            /*
             * perform select temperature sensors action
             */
            APP_vDisplaySetSensor(APP_E_SENSOR_TEMP);
            APP_vDisplayUpdate();
            vSerial_QData();
        }
        else if (APP_E_BUTTONS_BUTTON_3 == sAppEvent.sButton.u8Button)
        {
            /* perform select humidity sensors action */
            APP_vDisplaySetSensor(APP_E_SENSOR_HTS);
            APP_vDisplayUpdate();
            vSerial_SensorData();
        }
        else if (APP_E_BUTTONS_BUTTON_4 == sAppEvent.sButton.u8Button)
        {
            /* perform select humidity sensors action */
            APP_vDisplaySetSensor(APP_E_SENSOR_ALS);
            APP_vDisplayUpdate();
            Rfid_Getprotocol();
        }
    }
    vCheckStackEvent(sStackEvent);
}