Example #1
0
/*********************************************************************
 * @fn          zllSampleLight_Init
 *
 * @brief       Initialization function for the Sample Light App Task.
 *
 * @param       task_id
 *
 * @return      none
 */
void zllSampleLight_Init( byte task_id )
{
  zllSampleLight_TaskID = task_id;

  // Register the ZCL General Cluster Library callback functions
  zclGeneral_RegisterCmdCallbacks( SAMPLELIGHT_ENDPOINT, &zllSampleLight_GenCmdCBs );

#ifdef ZLL_HW_LED_LAMP
  HalTimer1Init(0);
#endif //ZLL_HW_LED_LAMP

  zllEffects_Init(zllSampleLight_TaskID, zllSampleLight_OnOffCB);

#ifdef ZCL_LEVEL_CTRL
  zclLevel_init(zllSampleLight_TaskID, zllSampleLight_OnOffCB);
#else
  #ifdef ZLL_HW_LED_LAMP
    halTimer1SetChannelDuty (WHITE_LED, PWM_FULL_DUTY_CYCLE); //initialize on/off LED to full power
  #endif
#endif //ZCL_LEVEL_CTRL

#ifdef ZCL_COLOR_CTRL
  // Register the ZCL Lighting Cluster Library callback functions
  zclLighting_RegisterCmdCallbacks( SAMPLELIGHT_ENDPOINT, &zllSampleLight_LightingCmdCBs );
  zclColor_init(zllSampleLight_TaskID);
#endif //#ifdef ZCL_COLOR_CTRL

  // Register the application's attribute list
  zcl_registerAttrList( SAMPLELIGHT_ENDPOINT, SAMPLELIGHT_NUM_ATTRIBUTES, zllSampleLight_Attrs );

  // Register the application's callback function to read the Scene Count attribute.
  zcl_registerReadWriteCB( SAMPLELIGHT_ENDPOINT, zllSampleLight_AttrReadWriteCB, NULL );

  // Register for all key events - This app will handle all key events
  RegisterForKeys( zllSampleLight_TaskID );

  zllTarget_RegisterApp( &zllSampleLight_SimpleDesc, &zllSampleLight_DeviceInfo );

  zllTarget_RegisterIdentifyCB( zllSampleLight_IdentifyCB );

  zllTarget_InitDevice();

  zllSampleLight_OnOffCB( zllSampleLight_OnOff );

#ifdef ZLL_1_0_HUB_COMPATIBILITY
  zclGeneral_RegisterCmdCallbacks( SAMPLELIGHT_ENDPOINT2, &zllSampleLight_GenCmdCBs );
#ifdef ZCL_COLOR_CTRL
  zclLighting_RegisterCmdCallbacks( SAMPLELIGHT_ENDPOINT2, &zllSampleLight_LightingCmdCBs );
#endif //ZCL_COLOR_CTRL
  zcl_registerAttrList( SAMPLELIGHT_ENDPOINT2, SAMPLELIGHT_NUM_ATTRIBUTES, zllSampleLight_Attrs );
  zll_RegisterSimpleDesc( &zllSampleLight_SimpleDesc2 );
#endif //ZLL_1_0_HUB_COMPATIBILITY

#ifdef THERMAL_SHUTDOWN
  hwThermal_Init( zllSampleLight_TaskID, TRUE );
#endif
}
/*********************************************************************
 * @fn          zclCCServer_Init
 *
 * @brief       Initialization function for the ZCL Commissioing Cluster
 *              Server Application.
 *
 * @param       task_id - task id
 *
 * @return      none
 */
void zclCCServer_Init( uint8 task_id )
{
  zclCCServer_TaskID = task_id;

  leaveInitiated = FALSE;

  // This app is part of the Home Automation Profile
  zba_Init( &zclCCServer_SimpleDesc );

  // Register the ZCL Commissioning Cluster Library callback functions
  zclCC_RegisterCmdCallbacks( CCSERVER_ENDPOINT, &zclCCServer_CmdCallbacks );

  // Register the application's attribute list
  zcl_registerAttrList( CCSERVER_ENDPOINT, CCSERVER_MAX_ATTRIBUTES, zclCCServer_Attrs );

  // Register the application's attribute data validation callback function
  zcl_registerValidateAttrData( zclCCServer_ValidateAttrDataCB );

  // Register the application's callback function to read/write attribute data
  zcl_registerReadWriteCB( CCSERVER_ENDPOINT, zclCCServer_ReadWriteCB, zclCCServer_AuthorizeCB );

  // Register for Initiator to receive Leave Confirm
  ZDO_RegisterForZdoCB( ZDO_LEAVE_CNF_CBID, zclCCServer_ZdoLeaveCnfCB );

  // Register for all key events - This app will handle all key events
  RegisterForKeys( zclCCServer_TaskID );

  // Initialize ZBA Startup Attributes Set (SAS)
  zclCCServer_InitStartupParameters( TRUE );

  // See if the device is factory new
  if ( !ZDApp_DeviceConfigured() )
  {
    osal_nv_item_init( ZCD_NV_NWKMGR_ADDR, sizeof( zclCCServer_NwkManagerAddr ),
                       (void *)&zclCCServer_NwkManagerAddr );

    // On startup, attempt to join the network specified by the startup SAS
    // on all channels at least once

    // ZBA Default Settings with the default ZBA Key Material and ZBA EPID
    if ( nullExtendedPANID( zgApsUseExtendedPANID ) )
    {
      osal_cpyExtAddr( zgApsUseExtendedPANID, zbaGlobalCommissioningEPID );
    }

    // Default Network Key and Pre-configured Link Key should already be set
  }
}