📄 prodtestcoord.c
字号:
/* Time to update the display */
vProcessUpdateBlock();
/* Decrement counter for sync loss */
if (sDemoData.sTestData.u8Count != 255)
{
sDemoData.sTestData.u8Count--;
if (sDemoData.sTestData.u8Count == 0)
{
int i;
for (i = 0; i < TEST_ENDPOINTS; i++)
{
uint8 u8SyncLoss = sDemoData.sTestData.au8SyncLoss[i];
if (u8SyncLoss != 0)
{
/* Pass in value + 100 to ensure all 3 digits output, as
we overwrite first digit with node number anyway */
vValToDec(&acAssocFail[3], u8SyncLoss + 100, "");
acAssocFail[3] = '0' + i;
vSendOnUart(acAssocFail);
}
}
vSendOnUart(acAssocComplete);
}
}
break;
case BLOCK_START_TEMP:
/* Time to start read of the temperature sensor. We read sensors
even if we don't use the data, as the coordinator is assumed to
be a device that doesn't have to be particularly economical on
power */
vHTSstartReadTemp();
break;
case BLOCK_READ_TEMP:
/* Time to read the temperature sensor */
u8LocalSensor = (uint8)u16HTSreadTempResult();
if ((sDemoData.sTestData.bSensorsTested == FALSE) && (u8LocalSensor < 40))
{
vSendOnUart(acTemperatureTestPassed);
}
break;
case BLOCK_START_HUMIDITY:
/* Time to start a read of the humidity sensor */
vHTSstartReadHumidity();
break;
case BLOCK_READ_HUMIDITY:
/* Time to read the humidity sensor */
u8LocalSensor = (uint8)u16HTSreadHumidityResult();
if ((sDemoData.sTestData.bSensorsTested == FALSE) && (u8LocalSensor < 100))
{
vSendOnUart(acHumidityTestPassed);
}
break;
case BLOCK_READ_LIGHT:
/* Time to read the light sensor. This sensor automatically starts
a new conversion afterwards so there is no need for a 'start read' */
u8LocalSensor = (uint8)(u16ALSreadChannelResult() >> 6);
if (sDemoData.sTestData.bSensorsTested == FALSE)
{
if (u8LocalSensor < 8)
{
vSendOnUart(acLightTestPassed);
}
sDemoData.sTestData.bSensorsTested = TRUE;
vSendOnUart(acSensorTestsComplete);
}
break;
}
}
/****************************************************************************
*
* NAME: vProcessKeys
*
* DESCRIPTION:
* Gets the latest button presses and detects any change since the last time
* the buttons were checked. If there is a change it is passed to the
* individual handler for the screen currently being displayed (the buttons
* are all 'soft' keys so their meaning changes from screen to screen).
*
* PARAMETERS: Name RW Usage
* pu8Keys RW Persistent value of buttons pressed
*
****************************************************************************/
PRIVATE void vProcessKeys(uint8 *pu8Keys)
{
uint8 u8KeysDown;
uint8 u8NewKeysDown;
u8KeysDown = *pu8Keys;
/* Process key press */
u8NewKeysDown = u8ButtonReadFfd();
if (u8NewKeysDown != u8KeysDown)
{
u8KeysDown = u8NewKeysDown;
/* Key presses depend on mode */
switch (sDemoData.sSystem.eState)
{
case E_STATE_SPLASH:
vProcessSplashKeyPress(u8KeysDown);
break;
case E_STATE_NETWORK:
vProcessNetworkKeyPress(u8KeysDown);
break;
case E_STATE_NODE:
vProcessNodeKeyPress(u8KeysDown);
break;
default:
break;
}
}
/* Store value for use next time */
*pu8Keys = u8KeysDown;
}
/****************************************************************************
*
* NAME: u8UpdateTimeBlock
*
* DESCRIPTION:
* Moves the state machine time block on by one time period.
*
* PARAMETERS: Name RW Usage
* u8TimeBlock R Previous time block
*
* RETURNS:
* uint8 Next time block
*
****************************************************************************/
PRIVATE uint8 u8UpdateTimeBlock(uint8 u8TimeBlock)
{
u8TimeBlock++;
if (u8TimeBlock >= MAX_BLOCKS)
{
u8TimeBlock = 0;
}
return u8TimeBlock;
}
/****************************************************************************
*
* NAME: vSendData
*
* DESCRIPTION:
* Generates and sends a frame consisting of 1 KVP transaction, for the
* setting of the LED at the receiving device. The address is provided in the
* call but the endpoint is fixed.
*
* PARAMETERS: Name RW Usage
* u16Addr R Address to send data to
* u8Switch R Switch value (0 or 1)
*
****************************************************************************/
PRIVATE void vSendData(uint16 u16Addr, uint8 u8Switch)
{
uint8 u8SrcEP = 0x30;
APS_Addrmode_e eAddrMode;
AF_Transaction_s Transaction;
uint16 u16DestAddr;
uint8 u8DestEndpoint;
uint8 transCount = 1;
eAddrMode = APS_ADDRMODE_SHORT;
u16DestAddr = u16Addr;
u8DestEndpoint = 0x40;
Transaction.u8SequenceNum = u8AfGetTransactionSequence(TRUE);
Transaction.uFrame.sKvp.eCommandTypeID = KVP_SET;
Transaction.uFrame.sKvp.eAttributeDataType = KVP_UNSIGNED_8BIT_INTEGER;
Transaction.uFrame.sKvp.eErrorCode = KVP_SUCCESS;
Transaction.uFrame.sKvp.u16AttributeID = 0x0000;
Transaction.uFrame.sKvp.uAttributeData.UnsignedInt8 = u8Switch;
afdeDataRequest(eAddrMode,
u16DestAddr,
u8DestEndpoint,
u8SrcEP,
DAP_PROFILE_ID,
DAP_CID_SWITCH,
AF_KVP,
transCount,
&Transaction,
APS_TXOPTION_NONE,
ENABLE_ROUTE_DISCOVERY,
0);
}
/****************************************************************************
*
* NAME: vProcessUpdateBlock
*
* DESCRIPTION:
* Called once per second to update the scrolling graphs and, if showing a
* screen with graphs on, updating the LCD.
*
* RETURNS:
* void
*
****************************************************************************/
PRIVATE void vProcessUpdateBlock(void)
{
tsNodeData *psNodeData;
tsNodeElementData *psNodeElementData;
uint8 *pu8GraphData;
uint8 u8PrevPoint;
uint8 u8Node;
uint8 u8Sensor;
uint8 u8Value;
/* Update graphs */
for (u8Node = 0; u8Node < DEMO_ENDPOINTS; u8Node++)
{
psNodeData = &sDemoData.sNode.asNodeData[u8Node];
if (psNodeData->u8FramesMissed)
{
/* Missed data, so copy previous value forward */
u8PrevPoint = (sDemoData.sGui.u8GraphPos - 1) & (DEMO_HISTORY_LEN - 1);
for (u8Sensor = 0; u8Sensor < DEMO_SENSOR_LIST_LEN; u8Sensor++)
{
pu8GraphData = psNodeData->asNodeElementData[u8Sensor].au8GraphData;
pu8GraphData[sDemoData.sGui.u8GraphPos] = pu8GraphData[u8PrevPoint];
}
}
else
{
/* Data must be scaled for graph (0-13)
Temp range is 0-52
Humidity range is 0-104
Light range is 0-6
*/
for (u8Sensor = 0; u8Sensor < DEMO_SENSOR_LIST_LEN; u8Sensor++)
{
psNodeElementData = &psNodeData->asNodeElementData[u8Sensor];
u8Value = psNodeElementData->u8NowValue;
switch (u8Sensor)
{
case E_SENSOR_TEMP:
u8Value = u8Value >> 2;
break;
case E_SENSOR_HTS:
u8Value = u8Value >> 3;
break;
case E_SENSOR_ALS:
u8Value = u8Value * 2;
break;
}
if (u8Value > 13)
{
u8Value = 13;
}
psNodeElementData->au8GraphData[sDemoData.sGui.u8GraphPos] = u8Value;
}
}
/* For next time, assume failed until proven otherwise */
if (psNodeData->u8FramesMissed < FRAMES_MISSED_INDICATION)
{
psNodeData->u8FramesMissed++;
}
else
{
if (u8Node < TEST_ENDPOINTS)
{
sDemoData.sTestData.au8SyncLoss[u8Node]++;
}
}
}
/* Increment graph position */
sDemoData.sGui.u8GraphPos = (sDemoData.sGui.u8GraphPos + 1) & (DEMO_HISTORY_LEN - 1);
/* Update display */
switch (sDemoData.sSystem.eState)
{
case E_STATE_NETWORK:
vUpdateNetworkScreen(sDemoData.sGui.eCurrentSensor);
break;
case E_STATE_NODE:
vUpdateNodeScreen(sDemoData.sGui.u8CurrentNode);
break;
default:
break;
}
}
/****************************************************************************
*
* NAME: vProcessSplashKeyPress
*
* DESCRIPTION:
* Handles button presses on the splash screen. The buttons show the stack
* version.
*
* PARAMETERS: Name RW Usage
* u8KeyMap R Current buttons pressed bitmap
*
* RETURNS:
* void
*
****************************************************************************/
PRIVATE void vProcessSplashKeyPress(uint8 u8KeyMap)
{
char acString[9];
switch (u8KeyMap)
{
case E_KEY_0:
vUTIL_NumToString(sDemoData.sSystem.u32ZigbeeStackVersion, acString);
vLcdWriteText("Stack release", 6, 0);
vLcdWriteText(acString, 6, 80);
vLcdRefreshAll();
break;
case E_KEY_1:
/* Plus button: increment value */
sDemoData.sSystem.u8Channel += 2;
case E_KEY_2:
/* Minus button: decrement value */
sDemoData.sSystem.u8Channel += (CHANNEL_RANGE - 1);
while (sDemoData.sSystem.u8Channel > CHANNEL_MAX)
{
sDemoData.sSystem.u8Channel -= CHANNEL_RANGE;
}
vUpdateSplashScreen();
break;
case E_KEY_3:
/* Done button: start network and go to network screen */
sDemoData.sSystem.eState = E_STATE_NETWORK;
JZS_sConfig.u32Channel = sDemoData.sSystem.u8Channel;
JZS_vStartStack();
vBuildNetworkScreen();
break;
default:
break;
}
}
/****************************************************************************
*
* NAME: vProcessNetworkKeyPress
*
* DESCRIPTION:
* Handles button presses on the Network screen. The buttons can move onto
* the first Node screen (if there are any nodes) or select a particular
* sensor.
*
* PARAMETERS: Name RW Usage
* u8KeyMap R Current buttons pressed bitmap
*
* RETURNS:
* void
*
****************************************************************************/
PRIVATE void vProcessNetworkKeyPress(uint8 u8KeyMap)
{
switch (u8KeyMap)
{
case E_KEY_0:
/* Node button: go to node screen (if there are any nodes) */
if (sDemoData.sNode.u8AssociatedNodes > 0)
{
sDemoData.sSystem.eState = E_STATE_NODE;
sDemoData.sGui.u8CurrentNode = 0;
vBuildNodeScreen(sDemoData.sGui.u8CurrentNode);
}
break;
case E_KEY_1:
/* Temp button: change if not already there */
sDemoData.sGui.eCurrentSensor = E_SENSOR_TEMP;
vBuildNetworkScreen();
break;
case E_KEY_2:
/* Humidity button: change if not already there */
sDemoData.sGui.eCurrentSensor = E_SENSOR_HTS;
vBuildNetworkScreen();
break;
case E_KEY_3:
/* Temp button: change if not already there */
sDemoData.sGui.eCurrentSensor = E_SENSOR_ALS;
vBuildNetworkScreen();
break;
}
}
/****************************************************************************
*
* NAME: vProcessNodeKeyPress
*
* DESCRIPTION:
* Handles button presses on the Node screens. The first button can move to
* the next Node screen (if there are any more nodes) or back to the Network
* screen. Another button selects the Node Control screen and the other two
* toggle the state of the remote switch.
*
* PARAMETERS: Name RW Usage
* u8KeyMap R Current buttons pressed bitmap
*
* RETURNS:
* void
*
****************************************************************************/
PRIVATE void vProcessNodeKeyPress(uint8 u8KeyMap)
{
switch (u8KeyMap)
{
case E_KEY_0:
/* Node button: go to next node or network screen */
sDemoData.sGui.u8CurrentNode++;
if (sDemoData.sGui.u8CurrentNode == sDemoData.sNode.u8AssociatedNodes)
{
sDemoData.sSystem.eState = E_STATE_NETWORK;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -