⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 homesensorcoord.c

📁 基于zigbee技术的数据链路层通讯协议的驱动程序,是现场总线技术的最新发展趋势
💻 C
📖 第 1 页 / 共 5 页
字号:
    vUpdateNodeScreen(u8Node);}/**************************************************************************** * * NAME: vUpdateNodeScreen * * DESCRIPTION: * Draws the three sensor graphs for a node. * * PARAMETERS:      Name            RW  Usage *                  u8Node          R   Node to display * * RETURNS: * void * ****************************************************************************/PRIVATE void vUpdateNodeScreen(uint8 u8Node){    tsNodeData *psNodeData;    char acString[8];    psNodeData = &sDemoData.sNode.asNodeData[u8Node];    /* Status */    if ((sDemoData.sNode.bLocalNode) && (u8Node != 0))    {        vValToDec(acString, psNodeData->u8Rssi, "    ");        vLcdWriteText(acString, 1, 0);        vValToDec(acString, psNodeData->u8FramesMissed - 1, "    ");        vLcdWriteText(acString, 1, 20);    }    /* Update graphs, alarms and values */    vLcdUpdateElement(psNodeData, E_SENSOR_TEMP, 4, 0, FALSE);    vLcdUpdateElement(psNodeData, E_SENSOR_HTS, 1, 64, FALSE);    vLcdUpdateElement(psNodeData, E_SENSOR_ALS, 4, 64, FALSE);    //vDisplayDebug();    vLcdRefreshAll();}/**************************************************************************** * * NAME: vBuildNodeControlScreen * * DESCRIPTION: * Builds the text for a Node Control screen, then uses the update function * to show the values for each adjustable parameter in turn. * * PARAMETERS:      Name            RW  Usage *                  u8Node          R   Node to display * * RETURNS: * void * ****************************************************************************/PRIVATE void vBuildNodeControlScreen(uint8 u8Node){    vLcdClear();    vLcdWriteText((char *)apcNodeNameList[u8Node], 0, 0);    vLcdWriteText("Select", 7, 0);    vLcdWriteText("\\", 7, 47);    vLcdWriteText("]", 7, 74);    vLcdWriteText("Done", 7, 103);    /* Update node control screen multiple times to display all the data */    vUpdateNodeControlScreen(u8Node, 1, FALSE);    vUpdateNodeControlScreen(u8Node, 2, FALSE);    vUpdateNodeControlScreen(u8Node, 3, FALSE);    vUpdateNodeControlScreen(u8Node, 0, TRUE);}/**************************************************************************** * * NAME: vUpdateNodeControlScreen * * DESCRIPTION: * Updates a single row of a Node Control screen. The row label is either * highlighted or normal text, and the value must be displayed with a symbol * after it or, for light levels, purely as a symbol. * * PARAMETERS:      Name            RW  Usage *                  u8Node          R   Node to display information for *                  u8Selection     R   Currently selected item (0-x) *                  boUpdate        R   TRUE if LCD should update afterwards * * RETURNS: * void * ****************************************************************************/PRIVATE void vUpdateNodeControlScreen(uint8 u8Node, uint8 u8Selection,                                      bool_t boUpdate){    static const char *apcRowName[CONTROL_LIST_LEN] = {        "Temp high alarm", "Temp low alarm", "Light high alarm",        "Light low alarm"};    char acString[10];    tsNodeData *psNodeData = &sDemoData.sNode.asNodeData[u8Node];    uint8 u8Value;    /* Write row label highlighted, and previous row label in normal text */    vWriteRowLabel(u8Selection, (char **)apcRowName, CONTROL_LIST_LEN);    switch (u8Selection)    {    case 0:        u8Value = psNodeData->asNodeElementData[E_SENSOR_TEMP].u8HighAlarm;        if (u8Value == 0)        {            vLcdWriteText("off   ", 1, 90);        }        else        {            vValToDec(acString, u8Value, "[C   ");            vLcdWriteText(acString, 1, 90);        }        break;    case 1:        u8Value = psNodeData->asNodeElementData[E_SENSOR_TEMP].u8LowAlarm;        if (u8Value == 255)        {            vLcdWriteText("off   ", 2, 90);        }        else        {            vValToDec(acString, u8Value, "[C   ");            vLcdWriteText(acString, 2, 90);        }        break;    case 2:        u8Value = psNodeData->asNodeElementData[E_SENSOR_ALS].u8HighAlarm;        if (u8Value == 0)        {            vLcdWriteText("off", 3, 90);        }        else        {            acString[0] = '&' + u8Value;            acString[1] = ' ';            acString[2] = ' ';            acString[3] = '\0';            vLcdWriteText(acString, 3, 90);        }        break;    default:        u8Value = psNodeData->asNodeElementData[E_SENSOR_ALS].u8LowAlarm;        if (u8Value == 255)        {            vLcdWriteText("off", 4, 90);        }        else        {            acString[0] = '&' + u8Value;            acString[1] = ' ';            acString[2] = ' ';            acString[3] = '\0';            vLcdWriteText(acString, 4, 90);        }        break;    }    if (boUpdate)    {        vLcdRefreshAll();    }}/**************************************************************************** * * NAME: vBuildSetupScreen * * DESCRIPTION: * Builds the text for the Setup screen, then uses the update function * to show the values for each adjustable parameter in turn. * * RETURNS: * void * ****************************************************************************/PRIVATE void vBuildSetupScreen(void){    char acString[9];    vLcdClear();    vLcdWriteText("Settings", 0, 0);    vLcdWriteText("Select", 7, 0);    vLcdWriteText("\\", 7, 47);    vLcdWriteText("]", 7, 74);    vLcdWriteText("Done", 7, 103);    /* Display version numbers */    vLcdWriteText("MAC library", 4, 0);    vUTIL_NumToString(sDemoData.sSystem.u32AppApiVersion, acString);    vLcdWriteText(acString, 4, 75);    vLcdWriteText("Periph` library", 5, 0);    vUTIL_NumToString(sDemoData.sSystem.u32HwApiVersion, acString);    vLcdWriteText(acString, 5, 75);    /* Update node control screen multiple times to display all the data */    vUpdateSetupScreen(1, FALSE);    vUpdateSetupScreen(0, TRUE);}/**************************************************************************** * * NAME: vUpdateSetupScreen * * DESCRIPTION: * Updates a single row of the Setup screen. The row label is either * highlighted or normal text, and the values are always 'on' or 'off'. * * PARAMETERS:      Name            RW  Usage *                  u8Selection     R   Currently selected item (0-x) *                  boUpdate        R   TRUE if LCD should update afterwards * * RETURNS: * void * ****************************************************************************/PRIVATE void vUpdateSetupScreen(uint8 u8Selection, bool_t boUpdate){    static const char *apcRowName[SETUP_LIST_LEN] = {        "Local node", "Four nodes"};    /* Write row label highlighted, and previous row label in normal text */    vWriteRowLabel(u8Selection, (char **)apcRowName, SETUP_LIST_LEN);    switch (u8Selection)    {    case 0:        vWriteOnOff(sDemoData.sNode.bLocalNode, 1, 75);        break;    case 1:        vWriteOnOff(sDemoData.sGui.bShowFourNodes, 2, 75);        break;    }    if (boUpdate)    {        vLcdRefreshAll();    }}/**************************************************************************** * * NAME: vDrawGraph * * DESCRIPTION: * Creates a bitmap from an array of values. Each value is represented by a * column on the graph, and a lookup table is used to translate each value * (assumed to be in the range 0 to 13) to the data required for the bitmap. * Finally, the bitmap is displayed via a board API. * * PARAMETERS:      Name            RW  Usage *                  pu8GraphData    R   Array of 32 elements of graph data *                  u8StartCol      R   First column of bitmap *                  u8StartRow      R   Top character row of bitmap * * RETURNS: * void * ****************************************************************************/PRIVATE void vDrawGraph(uint8 *pu8GraphData, uint8 u8StartCol,                        uint8 u8StartRow){    static const uint16 au16LineData[14] = {0x4000, 0x6000, 0x7000, 0x7800,                                            0x7c00, 0x7e00, 0x7f00, 0x7f80,                                            0x7fc0, 0x7fe0, 0x7ff0, 0x7ff8,                                            0x7ffc, 0x7ffe};    uint8 au8GraphBitmap[66];    const tsBitmap sGraphBitmap = {au8GraphBitmap, 33, 2};    int    i;    uint16 u16LineData;    uint8  u8DataPos = sDemoData.sGui.u8GraphPos;    /* Draw y axis */    au8GraphBitmap[0] = 0xfe;    au8GraphBitmap[33] = 0x7f;    /* Fill in data */    for (i = 1; i <= DEMO_HISTORY_LEN; i += 1)    {        u16LineData = au16LineData[pu8GraphData[u8DataPos]];        au8GraphBitmap[i] = (uint8)(u16LineData & 0xff);        au8GraphBitmap[i + 33] = (uint8)(u16LineData >> 8);        /* Increment data point */        u8DataPos = (u8DataPos + 1) & (DEMO_HISTORY_LEN - 1);    }    /* Write bitmap to shadow memory */    vLcdWriteBitmap((tsBitmap *)&sGraphBitmap, u8StartCol, u8StartRow);}/**************************************************************************** * * NAME: vStringCopy * * DESCRIPTION: * Simple string copy as standard libraries not available. * * PARAMETERS:      Name    RW  Usage *                  pcFrom  R   Pointer to string to copy *                  pcTo    W   Pointer to store for new string * * RETURNS: * void * ****************************************************************************/PRIVATE void vStringCopy(char *pcFrom, char *pcTo){    while (*pcFrom != '\0')    {        *pcTo = *pcFrom;        pcTo++;        pcFrom++;    }    *pcTo = '\0';}/**************************************************************************** * * NAME: vValToDec * * DESCRIPTION: * Converts an 8-bit value to a string of the textual decimal representation. * Adds a text string after the text. * * PARAMETERS:      Name            RW  Usage *                  pcOutString     R   Location for new string *                  u8Value         R   Value to convert *                  pcLabel         R   Label to append to string * * RETURNS: * void * ****************************************************************************/PRIVATE void vValToDec(char *pcOutString, uint8 u8Value, char *pcLabel){    static const uint8 au8Digits[3] = {100, 10, 1};    uint8 u8Digit;    uint8 u8DigitIndex;    uint8 u8Count;    bool_t boPreviousDigitPrinted = FALSE;    for (u8DigitIndex = 0; u8DigitIndex < 3; u8DigitIndex++)    {        u8Count = 0;        u8Digit = au8Digits[u8DigitIndex];        while (u8Value >= u8Digit)        {            u8Value -= u8Digit;            u8Count++;        }        if ((u8Count != 0) || (boPreviousDigitPrinted == TRUE)            || (u8DigitIndex == 2))        {            *pcOutString = '0' + u8Count;            boPreviousDigitPrinted = TRUE;            pcOutString++;        }    }    vStringCopy(pcLabel, pcOutString);}/**************************************************************************** * * NAME: vAdjustAlarm * * DESCRIPTION: * Increment a variable: If the variable is the maximum in the normal range, * sets it to a value that signifies 'off'. If the value is already 'off', * sets it to 0 (assumed to be the minimum within the normal range). This * function is used to set alarm levels. * * Decrement a variable: If the variable is 0 (assumed to be the minimum * within the normal range), sets it to a value that signifies 'off'. If the * value is already 'off', sets it to the maximum value in the normal range. * This function is used to set alarm levels. * * PARAMETERS:      Name            RW  Usage *                  pu8Value        R   Pointer to variable to adjust *                  u8MaxValue      R   Maximum value in normal range *                  u8OffValue      R   Value that signifies 'off' *                  bUpNotDown      R   TRUE to increment, FALSE to decrement * * RETURNS: * void * ****************************************************************************/PRIVATE void vAdjustAlarm(uint8 *pu8Value, uint8 u8MaxValue, uint8 u8OffValue,                          bool_t bUpNotDown){    if (bUpNotDown)    {        if (*pu8Value == u8MaxValue)        {            *pu8Value = u8OffValue;        }        else        {            if ((*pu8Value == u8OffValue ) && (u8OffValue > u8MaxValue))            {                *pu8Value = 0;            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -