📄 leddim.c
字号:
switch (cmd)
{
case 0x03:
break;
case 0x04:
if (metadocount)
{
if (metarecount)
{
metaframerecount++;
if (timespan <= tickTime - timestamp)
{
SendMetaTestReport(metaDataReportNode);
metarecount = FALSE;
metadocount = FALSE; /* We are done... */
}
}
else
{
metaframecount++;
}
}
break;
default:
break;
}
}
#endif
#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
**
**--------------------------------------------------------------------------*/
BYTE /*RET TRUE */
ApplicationInitHW( BYTE bStatus ) /* IN Nothing */
{
// #define P_RESET RXDpin // P1.1
// #define P_MISO MISO //P1.2
// #define P_MOSI MOSI // P1.3
// #define P_SCK SCK // P1.4
// #define P_CS SSN // P1.5
#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);
PIN_IN(Button, 1);
PIN_IN(P_MISO, 1);
PIN_OUT(P_Relay);
PIN_OUT(P_RESET);
PIN_OUT(P_MOSI);
PIN_OUT(P_SCK);
PIN_OUT(P_CS);
PIN_OUT(P_LED);
SET_0(P_RESET);
delay(236);
return(TRUE);
}
/*=========================== ApplicationInitSW =========================
** Initialization of the Application Software
**
** This is an application function example
**
**--------------------------------------------------------------------------*/
BYTE /*RET TRUE */
ApplicationInitSW( void ) /* IN Nothing */
{
DWORD ReadPower;
LED_ON(2);
SET_0(P_SCK);
// SET_0(P_MISO);
SET_0(P_MOSI);
SET_1(P_CS);
CS5460_Reset();
// LongDelay();
#ifdef ZW_DEBUG
ZW_UART_INIT(1152);
#endif
// PIN_OUT(P_RESET);
ZW_UART_SEND_STRING("Heguijin Init Start \n");
LED_OFF(2);
if(Test_Mode()==1) //enter Test Mode ,exit .
return(TRUE);
/* 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);
User_Load_CS5460_Configraiton();
}
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_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 */
}
// F_ReadCS5460(CMD_Read_Config_DRDY,&((BYTE_P)&ReadPower)[1],&((BYTE_P)&ReadPower)[2],&((BYTE_P)&ReadPower)[3]); // Command_Read_Power Read Power Value
// F_WriteCS5460(CMD_Write_Config_DRDY,((BYTE_P)&ReadPower)[1],((BYTE_P)&ReadPower)[2],((BYTE_P)&ReadPower)[3]); // Command_Read_Power Read Power Value
F_WriteCS5460(CMD_Write_Config_DRDY,0xff,0xff,0xff);
F_Write_CMD_CS5460(CMD_Start_ADC);
LEDUpdate();
OneButtonInit();
/* Check if we have a node id */
MemoryGetID(NULL, &bMyNodeID);
/* Set Nwtwork wide inclusion active if we dont have aa node ID */
if (bMyNodeID)
bNWIStartup = FALSE;
else
bNWIStartup = TRUE;
delay(100);
// ZW_TIMER_START(User_Read_Power_Value, 100, TIMER_FOREVER);
ZW_TIMER_START(F_Calculate_KWH_Power, 100, TIMER_FOREVER);
return(TRUE);
}
void CS5460_Reset()
{
SET_0(P_RESET);
Relay_0 ;
LongDelay();
LongDelay();
SET_1(P_RESET);
Relay_1 ;
LongDelay();
LongDelay();
}
BYTE Test_Mode()
{
int i=0;
T_Calibration_Cnt=0 ;
for(i=0;i<100;i++)
{
delay(100);
if (!BUTTON_PRESSED())
return 0;
}
LED_ON(2);
Relay_1;
LedTimerPollHandle=ZW_TIMER_START(BlinkLEDPoll, 5, TIMER_FOREVER);
ZW_TIMER_START(F_Enter_Calibrate_Task, 100, TIMER_FOREVER);
Calibration_Task_Mode=0;
return 1;
}
/*============================ 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*/
}
#ifdef ZW_SLAVE
/*========================== 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 */
{
}
#endif
#ifdef ZW_CONTROLLER
/*===================== ApplicationControllerUpdate =====================
** Inform the controller of node information update done through
** the network managment.
**
**--------------------------------------------------------------------------*/
void
ApplicationControllerUpdate(
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 */
{
}
#endif
/*============================ 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);
}
}
//==============================================================================
//================User New Add Code=================================================
// ZW_METER_REPORT_3BYTE_FRAME ZW_MeterReport3byteFrame;
void User_RF_Send_ZW_Data(DWORD Dword_Data)
{
txBuf.ZW_MeterReport4byteFrame.cmdClass = COMMAND_CLASS_METER ;
txBuf.ZW_MeterReport4byteFrame.cmd = METER_REPORT;
txBuf.ZW_MeterReport4byteFrame.meterType = 0x01;
txBuf.ZW_MeterReport4byteFrame.properties1 = 0x64 ; // Precision=3 bit,scale = 2 bit 00,size =3 bit =0x02
txBuf.ZW_MeterReport4byteFrame.meterValue1 = ((BYTE_P)&Dword_Data)[0];
txBuf.ZW_MeterReport4byteFrame.meterValue2 = ((BYTE_P)&Dword_Data)[1];
txBuf.ZW_MeterReport4byteFrame.meterValue3 = ((BYTE_P)&Dword_Data)[2] ;
txBuf.ZW_MeterReport4byteFrame.meterValue4 = ((BYTE_P)&Dword_Data)[3];
ZW_SEND_DATA(NODE_BROADCAST, (BYTE *)&txBuf, sizeof(txBuf.ZW_MeterReport4byteFrame), TRANSMIT_OPTION_NO_ROUTE, NULL);
}
//----------------------------------------------------------------------------------------------------------
void F_Calculate_KWH_Power()
{
BYTE Data_H,Data_M,Data_L;
DWORD ReadPower ;
double double_P_Temp;
DWORD D_Test0 =0xeeeeee;
DWORD D_Test1 =0xeeeeee ;
DWORD D_Test2 ;
D_Test2=(DWORD)((D_Test0*D_Test1)/0xeeeeee);
if(Wait_DRDY_High())
{
F_ReadCS5460(Command_ReadCalib_Lgn,&((BYTE_P)&G_Calibration_Max_Ign)[1],&((BYTE_P)&G_Calibration_Max_Ign)[2],&((BYTE_P)&G_Calibration_Max_Ign)[3]);
F_ReadCS5460(Command_ReadCalib_Vgn,&((BYTE_P)&G_Calibration_Max_Vgn)[1],&((BYTE_P)&G_Calibration_Max_Vgn)[2],&((BYTE_P)&G_Calibration_Max_Vgn)[3]);
User_Heguijin_SEND("Read_From_CS5460_G_Calibration_Max_Ign=",(BYTE_P)&G_Calibration_Max_Ign,sizeof(G_Calibration_Max_Ign));
User_Heguijin_SEND("Read_From_CS5460_G_Calibration_Max_Vgn=",(BYTE_P)&G_Calibration_Max_Vgn,sizeof(G_Calibration_Max_Vgn));
F_ReadCS5460(Command_Read_Power,&((BYTE_P)&ReadPower)[1],&((BYTE_P)&ReadPower)[2],&((BYTE_P)&ReadPower)[3]);
User_Heguijin_SEND("ReadPower AD=",(BYTE_P)&ReadPower,sizeof(ReadPower));
if(((BYTE_P)&ReadPower)[1]&0x80)
{
ReadPower=0x00;
}
F_WriteCS5460(CMD_Write_Config_DRDY,0xff,0xff,0xff);
double_P_Temp=(double)(((double)C_Standard_Powr*(double)ReadPower)/(double)G_Calibration_Max_Power);
G_SUM_KWH_Power=(double)G_SUM_KWH_Power+(double)(((double)C_Standard_Powr*(double)ReadPower)/(double)G_Calibration_Max_Power);
G_KWH_Power=(double)(((double)G_SUM_KWH_Power+(double)(((double)C_Standard_Powr*(double)ReadPower)/(double)G_Calibration_Max_Power))/(double)3600);
DWORD_Temp=(DWORD)double_P_Temp;
User_Heguijin_SEND("Real Power =",(BYTE_P)&DWORD_Temp,sizeof(DWORD_Temp));
DWORD_Temp=(DWORD)G_Calibration_Max_Power;
User_Heguijin_SEND("G_Calibration_Max_Power=",(BYTE_P)&DWORD_Temp,sizeof(DWORD_Temp));
UART_SendNL();
}
}
void F_Calculate_KW_NOT_H_Power()
{
BYTE Data_H,Data_M,Data_L;
DWORD ReadPower ;
if(Wait_DRDY_High())
{
ReadPower=00;
F_ReadCS5460(Command_Read_Power,&((BYTE_P)&ReadPower)[1],&((BYTE_P)&ReadPower)[2],&((BYTE_P)&ReadPower)[3]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -