📄 leddim.c
字号:
/* should be used to access the fields */
BYTE cmdLength) /* IN Number of command bytes including the command */
{
BYTE classcmd = pCmd->ZW_Common.cmdClass;
BYTE cmd = pCmd->ZW_Common.cmd;
BYTE param1 = *((BYTE*)pCmd + OFFSET_PARAM_1);
BYTE param2 = *((BYTE*)pCmd + OFFSET_PARAM_2);
#if defined(ZW010x) || defined(ZW020x) || defined(ZW030x)
BYTE param3 = *((BYTE*)pCmd + OFFSET_PARAM_3);
BYTE param4 = *((BYTE*)pCmd + OFFSET_PARAM_4);
#endif
BYTE status = dimmerNodeStatus.status;
txOption = ((rxStatus & RECEIVE_STATUS_LOW_POWER) ?
TRANSMIT_OPTION_LOW_POWER : 0) | TRANSMIT_OPTION_ACK;
if ((classcmd == COMMAND_CLASS_SWITCH_MULTILEVEL) ||
(classcmd == COMMAND_CLASS_BASIC))
{
/* Single switch command */
switch(cmd)
{
/* Start dimming */
case SWITCH_MULTILEVEL_START_LEVEL_CHANGE:
DIMStart(param2, (param1 & (M_DS_UP_DOWN | M_DS_ROLLOVER)));
break;
/* Stop dimming */
case SWITCH_MULTILEVEL_STOP_LEVEL_CHANGE:
DIMStop(TRUE);
break;
/* Controller wants the level */
case SWITCH_MULTILEVEL_GET:
{
BYTE level = (status & M_DS_ON_OFF) ? dimmerNodeStatus.level : SWITCHED_OFF;
SendReport(sourceNode, classcmd, level);
}
break;
/* Jump to the specified level param1 */
case SWITCH_MULTILEVEL_SET:
if (param1 == SWITCHED_ON)
{
SetLightLevel(CURRENT_LEVEL, LEVEL_DONTCARE);
}
else if (param1<100) /* Check for valid level */
{
SetLightLevel(LEVEL, param1);
}
break;
} /* switch */
} /* if */
else if (classcmd == COMMAND_CLASS_SWITCH_ALL)
{
switch(cmd)
{
case SWITCH_ALL_ON:
if ((ignoreAllOnOff != SWITCH_ALL_EXCLUDE_ON_OFF) && (ignoreAllOnOff != SWITCH_ALL_EXCLUDE_ONLY_ON))
{
SetLightLevel(ON, LEVEL_DONTCARE);
}
break;
case SWITCH_ALL_OFF:
if ((ignoreAllOnOff != SWITCH_ALL_EXCLUDE_ON_OFF) && (ignoreAllOnOff != SWITCH_ALL_EXCLUDE_ONLY_OFF))
{
SetLightLevel(OFF, LEVEL_DONTCARE);
}
break;
case SWITCH_ALL_SET:
ignoreAllOnOff = param1;
/* Store it in the EEPROM */
ZW_MEM_PUT_BYTE(EEOFFSET_IGNORE_ALL_ON_OFF, ignoreAllOnOff);
break;
case SWITCH_ALL_GET:
SendReport(sourceNode, COMMAND_CLASS_SWITCH_ALL, ignoreAllOnOff);
break;
default:
break;
} /* switch */
} /* else if == COMMAND_CLASS_SWITCH_ALL */
else if (classcmd == COMMAND_CLASS_PROTECTION)
{
switch (cmd)
{
case PROTECTION_SET:
protected_On_Off = param1;
if (protected_On_Off != PROTECTION_OFF)
{
SetLightLevel(OFF, LEVEL_DONTCARE);
}
else
{
/* We now go from child protected to no protection */
/* and because we send node info frames on every key release */
/* then we must reset the buttonPress and pollState so */
/* we don't send a redundant node info frame */
buttonPress = 0;
pollState = POLLIDLE;
}
/* Store it in the EEPROM */
ZW_MEM_PUT_BYTE(EEOFFSET_PROTECTED, protected_On_Off);
break;
case PROTECTION_GET:
SendReport(sourceNode, COMMAND_CLASS_PROTECTION, protected_On_Off);
break;
default:
break;
} /* switch */
} /* else if == COMMAND_CLASS_PROTECTION */
#if defined(ZW010x) || defined(ZW020x) || defined(ZW030x)
else if (classcmd == COMMAND_CLASS_POWERLEVEL)
{
switch (cmd)
{
case POWERLEVEL_SET:
if (param2 || (param1 == normalPower)) /* Only if timeout defined or powerlevel is normalPower */
{
param1 = ZW_RF_POWERLEVEL_SET(param1); /* Set powerlevel according to command */
if (timerPowerLevelHandle)
{
PowerLevelTimerCancel();
timerPowerLevelSec = 0;
}
if (param1 != normalPower) /* If normalPower then no timer is started */
{
timerPowerLevelSec = param2;
timerPowerLevelHandle = ZW_TIMER_START(PowerLevelTimeout, TIMER_ONE_SECOND, FOREVER);
}
}
break;
case POWERLEVEL_GET:
txBuf.ZW_PowerLevelReportFrame.cmdClass = COMMAND_CLASS_POWERLEVEL;
txBuf.ZW_PowerLevelReportFrame.cmd = POWERLEVEL_REPORT;
txBuf.ZW_PowerLevelReportFrame.powerLevel = ZW_RF_POWERLEVEL_GET();
txBuf.ZW_PowerLevelReportFrame.timeout = timerPowerLevelSec;
ZW_SEND_DATA(sourceNode, (BYTE *)&txBuf, sizeof(txBuf.ZW_PowerLevelReportFrame), txOption, NULL);
break;
case POWERLEVEL_TEST_NODE_SET:
if (testState != ZW_TEST_INPROGRESS)
{
testSourceNodeID = sourceNode;
testNodeID = param1;
testPowerLevel = param2;
testFrameCount = (WORD)((WORD)param3 << 8) + param4;
testFrameSuccessCount = 0;
if (testFrameCount)
{
StartTest();
}
else
{
testState = ZW_TEST_FAILED;
SendTestReport();
}
}
break;
case POWERLEVEL_TEST_NODE_GET:
SendTestReport();
break;
default:
break;
} /* switch */
} /* else if == COMMAND_CLASS_POWERLEVEL */
else if (classcmd == COMMAND_CLASS_MANUFACTURER_SPECIFIC)
{
switch (cmd)
{
case MANUFACTURER_SPECIFIC_GET:
txBuf.ZW_ManufacturerSpecificReportFrame.cmdClass = COMMAND_CLASS_MANUFACTURER_SPECIFIC;
txBuf.ZW_ManufacturerSpecificReportFrame.cmd = MANUFACTURER_SPECIFIC_REPORT;
txBuf.ZW_ManufacturerSpecificReportFrame.manufacturerID1 = 0x00; // Zensys manufacturer ID
txBuf.ZW_ManufacturerSpecificReportFrame.manufacturerID2 = 0x00;
txBuf.ZW_ManufacturerSpecificReportFrame.productType1 = 0x00; // Assigned by manufacturer
txBuf.ZW_ManufacturerSpecificReportFrame.productType2 = 0x00;
txBuf.ZW_ManufacturerSpecificReportFrame.productID1 = 0x00; // Assigned by manufacturer
txBuf.ZW_ManufacturerSpecificReportFrame.productID2 = 0x00;
ZW_SEND_DATA(sourceNode, (BYTE *)&txBuf, sizeof(txBuf.ZW_ManufacturerSpecificReportFrame), txOption, NULL);
break;
}
}
else if (classcmd == COMMAND_CLASS_VERSION)
{
switch (cmd)
{
case VERSION_GET:
txBuf.ZW_VersionReportFrame.cmdClass = COMMAND_CLASS_VERSION;
txBuf.ZW_VersionReportFrame.cmd = VERSION_REPORT;
txBuf.ZW_VersionReportFrame.libType = ZW_TYPE_LIBRARY();
#ifdef ZW_VERSION_BETA
txBuf.ZW_VersionReportFrame.proVersion = ZW_VERSION_MAJOR+(ZW_VERSION_BETA-0x60)*10;
#else
txBuf.ZW_VersionReportFrame.proVersion = ZW_VERSION_MAJOR;
#endif
txBuf.ZW_VersionReportFrame.proSubVersion = ZW_VERSION_MINOR;
txBuf.ZW_VersionReportFrame.appVersion = LED_DIM_VERSION;
txBuf.ZW_VersionReportFrame.appSubVersion = LED_DIM_REVISION;
ZW_SEND_DATA(sourceNode, (BYTE *)&txBuf, sizeof(txBuf.ZW_VersionReportFrame), txOption, NULL);
break;
case VERSION_COMMAND_CLASS_GET:
txBuf.ZW_VersionCommandReportFrame.cmdClass = COMMAND_CLASS_VERSION;
txBuf.ZW_VersionCommandReportFrame.cmd = VERSION_COMMAND_CLASS_REPORT;
txBuf.ZW_VersionCommandReportFrame.cmdReq = param1;
switch (param1)
{
case COMMAND_CLASS_BASIC:
txBuf.ZW_VersionCommandReportFrame.cmdVersion = BASIC_VERSION;
break;
case COMMAND_CLASS_SWITCH_MULTILEVEL:
txBuf.ZW_VersionCommandReportFrame.cmdVersion = SWITCH_MULTILEVEL_VERSION;
break;
case COMMAND_CLASS_SWITCH_ALL:
txBuf.ZW_VersionCommandReportFrame.cmdVersion = SWITCH_ALL_VERSION;
break;
case COMMAND_CLASS_MANUFACTURER_SPECIFIC:
txBuf.ZW_VersionCommandReportFrame.cmdVersion = MANUFACTURER_SPECIFIC_VERSION;
break;
case COMMAND_CLASS_VERSION:
txBuf.ZW_VersionCommandReportFrame.cmdVersion = VERSION_VERSION;
break;
case COMMAND_CLASS_PROTECTION:
txBuf.ZW_VersionCommandReportFrame.cmdVersion = PROTECTION_VERSION;
break;
case COMMAND_CLASS_POWERLEVEL:
txBuf.ZW_VersionCommandReportFrame.cmdVersion = POWERLEVEL_VERSION;
break;
default:
txBuf.ZW_VersionCommandReportFrame.cmdVersion = UNKNOWN_VERSION;
break;
}
ZW_SEND_DATA(sourceNode, (BYTE *)&txBuf, sizeof(txBuf.ZW_VersionCommandReportFrame), txOption, NULL);
break;
}
}
#endif
}
/****************************************************************************/
/* EXPORTED FUNCTIONS */
/****************************************************************************/
#ifdef ZW030x
/*=========================== ApplicationRfNotify ===========================
** Notify the application when the radio switch state
** Called from the Z-Wave PROTOCOL When radio switch from Rx to Tx or from Tx to Rx
** or when the modulator PA (Power Amplifier) turn on/off
**---------------------------------------------------------------------------------*/
void /*RET Nothing */
ApplicationRfNotify(
BYTE rfState) /* IN state of the RF, the available values is as follow:
ZW_RF_TX_MODE: The RF switch from the Rx to Tx mode, the modualtor is started and PA is on
ZW_RF_PA_ON: The RF in the Tx mode, the modualtor PA is turned on
ZW_RF_PA_OFF: the Rf in the Tx mode, the modulator PA is turned off
ZW_RF_RX_MODE: The RF switch from Tx to Rx mode, the demodulator is started.*/
{
}
#endif
/*============================ ApplicationInitHW ========================
** Non Z-Wave hardware initialization
**
** This is an application function example
**
**--------------------------------------------------------------------------*/
#ifdef ZW010x
BYTE /*RET TRUE */
ApplicationInitHW() /* IN Nothing */
#else
BYTE /*RET TRUE */
ApplicationInitHW( BYTE bStatus ) /* IN Nothing */
#endif
{
#ifdef APPL_PROD_TEST
IBYTE i;
SET_PRODUCTIONTEST_PIN;
for (i = 0; i < 10; i++) ; /* Short delay... */
if (IN_PRODUCTIONTEST) /* Anyone forcing it into productiontest mode ? */
{
return(FALSE); /*Enter production test mode*/
}
#endif /* APPL_PROD_TEST */
/* hardware initialization */
PIN_IN(Button, 1);
/* Setup specifics for current dim module */
PIN_OUT(LED1);
PIN_OUT(LED2);
PIN_OUT(LED3);
#if !defined(ZW020x) && !defined(ZW030x)
PIN_OUT(LED4);
#endif
return(TRUE);
}
/*=========================== ApplicationInitSW =========================
** Initialization of the Application Software
**
** This is an application function example
**
**--------------------------------------------------------------------------*/
BYTE /*RET TRUE */
ApplicationInitSW( void ) /* IN Nothing */
{
/* get stored values */
if (ZW_MEM_GET_BYTE(EEOFFSET_MAGIC) == MAGIC_VALUE)
{
dimmerNodeStatus.level = ZW_MEM_GET_BYTE(EEOFFSET_LEVEL);
if (dimmerNodeStatus.level > LEVEL_MAX)
{
dimmerNodeStatus.level = LEVEL_MAX;
}
dimmerNodeStatus.status = ZW_MEM_GET_BYTE(EEOFFSET_STATUS);
/* Get Ignore all On/Off frames state */
ignoreAllOnOff = ZW_MEM_GET_BYTE(EEOFFSET_IGNORE_ALL_ON_OFF);
/* Get protection state */
protected_On_Off = ZW_MEM_GET_BYTE(EEOFFSET_PROTECTED);
}
else
{ /* Its alive */
ZW_MEM_PUT_BYTE(EEOFFSET_LEVEL, LEVEL_MAX); /* Full light */
ZW_MEM_PUT_BYTE(EEOFFSET_STATUS, 0); /* Switch OFF */
ZW_MEM_PUT_BYTE(EEOFFSET_IGNORE_ALL_ON_OFF, SWITCH_ALL_ENABLE_ON_OFF);
ZW_MEM_PUT_BYTE(EEOFFSET_PROTECTED, PROTECTION_OFF); /* Not protected */
ZW_MEM_PUT_BYTE(EEOFFSET_MAGIC, MAGIC_VALUE); /* Now EEPROM should be OK */
dimmerNodeStatus.status = SWITCHED_OFF;
dimmerNodeStatus.level = LEVEL_MAX; /* Set level to full light */
/* ignoreAllOnOff and protected_On_Off are initialized on startup */
}
// ZW_DEBUG_CMD_INIT(1152);
LEDUpdate();
OneButtonInit();
return(TRUE);
}
/*============================ ApplicationTestPoll ======================
** Function description
** This function is called when the dimmer enters test mode.
** Side effects:
** Code will not exit until it is reset
**--------------------------------------------------------------------------*/
void ApplicationTestPoll(void)
{
#ifdef APPL_PROD_TEST
/*Send constant out*/
ZW_SEND_CONST();
while(1);
#endif
}
/*====================== ApplicationNodeInformation =====================
** Request Node information and current status
** Called by the the Z-Wave application layer before transmitting a
** "Node Information" frame.
**
** This is an application function example
**
**--------------------------------------------------------------------------*/
extern void /*RET Nothing */
ApplicationNodeInformation(
BYTE *deviceOptionsMask, /*OUT Bitmask with application options */
APPL_NODE_TYPE *nodeType, /*OUT Device type Generic and Specific */
BYTE **nodeParm, /*OUT Device parameter buffer pointer */
BYTE *parmLength) /*OUT Number of Device parameter bytes */
{
/* this is a listening node and it supports optional CommandClasses*/
*deviceOptionsMask = APPLICATION_NODEINFO_LISTENING|APPLICATION_NODEINFO_OPTIONAL_FUNCTIONALITY;
nodeType->generic = GENERIC_TYPE_SWITCH_MULTILEVEL; /* Generic device type */
nodeType->specific = SPECIFIC_TYPE_POWER_SWITCH_MULTILEVEL; /* Specific class */
*nodeParm = (BYTE *)&nodeInfo; /* Send list of known command classes. */
*parmLength = sizeof(nodeInfo); /* Set length*/
}
/*========================== ApplictionSlaveUpdate =======================
** Inform a slave application that a node information is received.
** Called from the slave command handler when a node information frame
** is received and the Z-Wave protocol is not in a state where it is needed.
**
**--------------------------------------------------------------------------*/
void
ApplicationSlaveUpdate(
BYTE bStatus, /*IN Status event */
BYTE bNodeID, /*IN Node id of the node that send node info */
BYTE* pCmd, /*IN Pointer to Application Node information */
BYTE bLen) /*IN Node info length */
{
}
/*============================ LearnCompleted ========================
** Function description
** Called from learnmode.c when learnmode completed
**
** Side effects:
**
**--------------------------------------------------------------------------*/
void /*RET Nothing */
LearnCompleted(
BYTE nodeID) /* IN resulting nodeID */
{
if (nodeID == 0) /* Was it reset? */
{
ignoreAllOnOff = SWITCH_ALL_ENABLE_ON_OFF;
protected_On_Off = PROTECTION_OFF;
/* Store it in the EEPROM */
ZW_MEM_PUT_BYTE(EEOFFSET_IGNORE_ALL_ON_OFF, ignoreAllOnOff);
ZW_MEM_PUT_BYTE(EEOFFSET_PROTECTED, protected_On_Off);
}
#ifdef DEBUG_STRESS
if (!debugStress)
{
debugStress = TRUE;
debugStressHandle = ZW_TIMER_START(SendBasicSet, DEBUG_STRESS_TIMEOUT_START, ONE_SHOT);
}
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -