diff --git a/Source/zcl_freepadapp.c b/Source/zcl_freepadapp.c index d5dda2e..e810875 100644 --- a/Source/zcl_freepadapp.c +++ b/Source/zcl_freepadapp.c @@ -132,19 +132,17 @@ void zclFreePadApp_Init(byte task_id) { zclFreePadApp_InitClusters(); zclGeneral_RegisterCmdCallbacks(1, &zclFreePadApp_CmdCallbacks); - for (int i = 0; i < zclFreePadApp_SimpleDescsCount; i++) { - SimpleDescriptionFormat_t descriptor = zclFreePadApp_SimpleDescs[i]; - if (i == 0) { - zcl_registerAttrList(descriptor.EndPoint, zclFreePadApp_AttrsFirstEPCount, zclFreePadApp_AttrsFirstEP); - } else { - // take one lower [i-1], since first ep handled by zclFreePadApp_AttrsFirstEP - zcl_registerAttrList(descriptor.EndPoint, FREEPAD_ATTRS_COUNT, zclFreePadApp_Attrs[i - 1]); - } - - bdb_RegisterSimpleDescriptor(&zclFreePadApp_SimpleDescs[i]); - zcl_registerReadWriteCB(descriptor.EndPoint, NULL, zclFreePadApp_ReadWriteAuthCB); + zcl_registerAttrList(zclFreePadApp_SimpleDescs[0].EndPoint, zclFreePadApp_AttrsFirstEPCount, zclFreePadApp_AttrsFirstEP); + bdb_RegisterSimpleDescriptor(&zclFreePadApp_SimpleDescs[0]); + zcl_registerReadWriteCB(zclFreePadApp_SimpleDescs[0].EndPoint, NULL, zclFreePadApp_ReadWriteAuthCB); +#if FREEPAD_BUTTONS_COUNT > 1 + for (uint8 i = 0; i < FREEPAD_BUTTONS_COUNT; i++) { + zcl_registerAttrList(zclFreePadApp_SimpleDescs[i + 1].EndPoint, FREEPAD_ATTRS_COUNT, zclFreePadApp_Attrs[i]); + bdb_RegisterSimpleDescriptor(&zclFreePadApp_SimpleDescs[i + 1]); + zcl_registerReadWriteCB(zclFreePadApp_SimpleDescs[i + 1].EndPoint, NULL, zclFreePadApp_ReadWriteAuthCB); } +#endif zcl_registerForMsg(zclFreePadApp_TaskID); // Register for all key events - This app will handle all key events @@ -156,7 +154,6 @@ void zclFreePadApp_Init(byte task_id) { touchLinkInitiator_RegisterNotifyTLCB(zclFreePadApp_TL_NotifyCb); #endif - LREP("Started build %s \r\n", zclFreePadApp_DateCodeNT); osal_start_reload_timer(zclFreePadApp_TaskID, FREEPADAPP_REPORT_EVT, FREEPADAPP_REPORT_DELAY); // this allows power saving, PM2 diff --git a/Source/zcl_freepadapp.h b/Source/zcl_freepadapp.h index a808617..fde24ba 100644 --- a/Source/zcl_freepadapp.h +++ b/Source/zcl_freepadapp.h @@ -69,13 +69,14 @@ extern uint8 zclFreePadApp_SwitchTypes[]; extern SimpleDescriptionFormat_t zclFreePadApp_SimpleDescs[]; -extern uint8 zclFreePadApp_SimpleDescsCount; extern uint8 zclFreePadApp_BatteryVoltage; extern uint8 zclFreePadApp_BatteryPercentageRemainig; // attribute list +#if FREEPAD_BUTTONS_COUNT > 1 extern CONST zclAttrRec_t zclFreePadApp_Attrs[][FREEPAD_ATTRS_COUNT]; +#endif extern CONST zclAttrRec_t zclFreePadApp_AttrsFirstEP[]; extern CONST uint8 zclFreePadApp_AttrsFirstEPCount; diff --git a/Source/zcl_freepadapp_data.c b/Source/zcl_freepadapp_data.c index a8e365c..dfcd4e3 100644 --- a/Source/zcl_freepadapp_data.c +++ b/Source/zcl_freepadapp_data.c @@ -80,16 +80,19 @@ CONST zclAttrRec_t zclFreePadApp_AttrsFirstEP[] = { {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[0]}}, {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[0]}}}; + +#if FREEPAD_BUTTONS_COUNT > 1 CONST zclAttrRec_t zclFreePadApp_Attrs[][FREEPAD_ATTRS_COUNT] = { {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[1]}}, {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[1]}}} - #if FREEPAD_BUTTONS_COUNT > 2 , {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[2]}}, - {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[2]}}}, - + {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[2]}}} +#endif +#if FREEPAD_BUTTONS_COUNT > 3 +, {{SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_TYPE, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchTypes[3]}}, {SWITCH_CONFIG, {ATTRID_ON_OFF_SWITCH_ACTIONS, ZCL_DATATYPE_ENUM8, RW, (void *)&zclFreePadApp_SwitchActions[3]}}}, @@ -147,7 +150,7 @@ CONST zclAttrRec_t zclFreePadApp_Attrs[][FREEPAD_ATTRS_COUNT] = { #endif }; - +#endif uint8 CONST zclFreePadApp_AttrsFirstEPCount = (sizeof(zclFreePadApp_AttrsFirstEP) / sizeof(zclFreePadApp_AttrsFirstEP[0])); const cId_t zclSampleSw_InClusterList[] = {ZCL_CLUSTER_ID_GEN_BASIC}; @@ -193,7 +196,7 @@ void zclFreePadApp_InitClusters(void) { } } } -uint8 zclFreePadApp_SimpleDescsCount = FREEPAD_BUTTONS_COUNT; + byte zclFreePadApp_KeyCodeToButton(byte key) { switch (key) {