Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nurikk committed Jun 6, 2020
1 parent 78ad2c7 commit 2d13015
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
21 changes: 9 additions & 12 deletions Source/zcl_freepadapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Source/zcl_freepadapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 8 additions & 5 deletions Source/zcl_freepadapp_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]}}},

Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -193,7 +196,7 @@ void zclFreePadApp_InitClusters(void) {
}
}
}
uint8 zclFreePadApp_SimpleDescsCount = FREEPAD_BUTTONS_COUNT;


byte zclFreePadApp_KeyCodeToButton(byte key) {
switch (key) {
Expand Down

0 comments on commit 2d13015

Please sign in to comment.