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

📄 prodtestcoord.c

📁 wireless jennic application note
💻 C
📖 第 1 页 / 共 4 页
字号:
            sDemoData.sGui.eCurrentSensor = E_SENSOR_ALS;
            vBuildNetworkScreen();
        }
        else
        {
            vBuildNodeScreen(sDemoData.sGui.u8CurrentNode);
        }
        break;

    case E_KEY_2:
        /* Off button */
    case E_KEY_3:
        /* On button */
        vSendData(sDemoData.sNode.asNodeData[sDemoData.sGui.u8CurrentNode].u16ShortAdr, (u8KeyMap == E_KEY_2) ? 0 : 1);
        break;
    }
}

/****************************************************************************
 *
 * NAME: vUpdateSplashScreen
 *
 * DESCRIPTION:
 * Updates the Splash screen, when it first appears or when the user
 * changes the channel number.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vUpdateSplashScreen(void)
{
    char acString[5];

    vValToDec(acString, sDemoData.sSystem.u8Channel, "  ");
    vLcdWriteText(acString, 7, 16);

    vLcdRefreshAll();
}

/****************************************************************************
 *
 * NAME: vBuildNetworkScreen
 *
 * DESCRIPTION:
 * Creates the Network screen. Depending on how the GUI has been configured
 * it may want to display up to 3 or up to 4 nodes simultaneuously. Also, it
 * only shows nodes that have successfully associated. To achieve this, it
 * makes use of an array of the four display positions on the screen, and
 * loops through this to position each node in the correct position.
 *
 * This function only draws the text required, then uses the related update
 * function to display the actual data and to refresh the LCD.
 *
 * PARAMETERS:      Name            RW  Usage
 *                  eSensor         R   Sensor to display
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vBuildNetworkScreen(void)
{
    static const char *apcSensorLabel[DEMO_SENSOR_LIST_LEN] = {
       "Temp", "Humidity", "Light"};
    static const uint8 au8LabelPos[DEMO_SENSOR_LIST_LEN] = {29, 58, 102};
    uint8 u8Node;
    int iIndex;
    teSensor eSensor = sDemoData.sGui.eCurrentSensor;

    vLcdClear();

    /* Show labels */
    if (sDemoData.sNode.u8AssociatedNodes == 0)
    {
        vLcdWriteText("No sensors detected", 3, 0);
    }
    else
    {
        u8Node = 0;
        while ((u8Node < sDemoData.sNode.u8AssociatedNodes) && (u8Node < 4))
        {
            vLcdWriteText((char *)apcNodeNameList[u8Node], au8NodeLcdRow[u8Node], au8NodeLcdCol[u8Node]);
            u8Node++;
        }
    }

    /* Hot buttons at bottom of screen */
    vLcdWriteText("Node", 7, 0);

    for (iIndex = 0; iIndex < DEMO_SENSOR_LIST_LEN; iIndex++)
    {
        vLcdWriteText((char *)apcSensorLabel[iIndex], 7, au8LabelPos[iIndex]);
    }
    vLcdWriteInvertedText((char *)apcSensorLabel[eSensor], 7, au8LabelPos[eSensor]);

    vUpdateNetworkScreen(eSensor);
}

/****************************************************************************
 *
 * NAME: vUpdateNetworkScreen
 *
 * DESCRIPTION:
 * Draws the graphs and values for the Network screen. See the description
 * for vBuildNetworkScreen for an explanation of the positioning of elements
 * on the display.
 *
 * PARAMETERS:      Name            RW  Usage
 *                  eSensor         R   Sensor to display
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vUpdateNetworkScreen(teSensor eSensor)
{
    uint8 u8Node;
    uint8 u8Row;
    uint8 u8Col;

    u8Node = 0;

    while ((u8Node < sDemoData.sNode.u8AssociatedNodes) && (u8Node < 4))
    {
        u8Row = au8NodeLcdRow[u8Node] + 1;
        u8Col = au8NodeLcdCol[u8Node];

        vLcdUpdateElement(&sDemoData.sNode.asNodeData[u8Node],
                          eSensor, u8Row, u8Col, TRUE);

        u8Node++;
    }

    vLcdRefreshAll();
}

/****************************************************************************
 *
 * NAME: vLcdUpdateElement
 *
 * DESCRIPTION:
 * Draws the graph and text for a single sensor for a single node. The text
 * includes alarm indications if the sensor value exceeds user specified
 * limits.
 *
 * PARAMETERS:  Name                RW  Usage
 *              psNodeElementData   R   Pointer to data for node
 *              u8Row               R   Character row to display on
 *              u8Col               R   Pixel column to display on
 *              boShowInfo          R   TRUE to show missed frames indication
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vLcdUpdateElement(tsNodeData *psNodeData, teSensor eSensor,
                               uint8 u8Row, uint8 u8Col, bool_t boShowInfo)
{
    char acString[10];
    uint8 u8NowValue;
    tsNodeElementData *psNodeElementData = &psNodeData->asNodeElementData[eSensor];

    u8NowValue = psNodeElementData->u8NowValue;

    switch (eSensor)
    {
    case E_SENSOR_TEMP:
        vValToDec(acString, u8NowValue, "[C ");
        break;

    case E_SENSOR_HTS:
        vValToDec(acString, u8NowValue, "% ");
        break;

    case E_SENSOR_ALS:
        /* This is a light sensor so display symbol */
        acString[0] = '&' + u8NowValue;
        acString[1] = '\0';
        break;

    default:
        break;
    }

    vLcdWriteText(acString, u8Row, u8Col);

    /* Print alarm */
    vLcdWriteText("       ", (uint8)(u8Row + 1), u8Col);

    if (boShowInfo)
    {
        //vUTIL_NumToString(psNodeData->u16ShortAdr, acString);
        //vLcdWriteText(&acString[4], (uint8)(u8Row + 1), u8Col);
        vValToDec(acString, psNodeData->u8FramesMissed - 1, "");
        vLcdWriteText(acString, (uint8)(u8Row + 1), u8Col + 20);
    }

    /* Draw graph */
    vDrawGraph(psNodeElementData->au8GraphData, (uint8)(u8Col + 27), u8Row);
}

/****************************************************************************
 *
 * NAME: vBuildNodeScreen
 *
 * DESCRIPTION:
 * Builds the text to appear on a Node screen, then uses the update function
 * to populate it with data.
 *
 * PARAMETERS:      Name            RW  Usage
 *                  u8Node          R   Node to display
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vBuildNodeScreen(uint8 u8Node)
{
    vLcdClear();
    vLcdWriteText((char *)apcNodeNameList[u8Node], 0, 0);
    vLcdWriteText("Humidity", 0, 64);
    vLcdWriteText("Temp", 3, 0);
    vLcdWriteText("Light", 3, 64);
    vLcdWriteText("Node", 7, 0);
    vLcdWriteText("Off", 7, 75);
    vLcdWriteText("On", 7, 115);

    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 */
    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);

    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 = 0; i < DEMO_HISTORY_LEN; i += 1)
    {
        u16LineData = au16LineData[pu8GraphData[u8DataPos]];

        au8GraphBitmap[i * 2 + 1] = (uint8)(u16LineData & 0xff);
        au8GraphBitmap[i * 2 + 2] = (uint8)(u16LineData & 0xff);
        au8GraphBitmap[i * 2 + 34] = (uint8)(u16LineData >> 8);
        au8GraphBitmap[i * 2 + 35] = (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: vAddDesc
 *
 * DESCRIPTION:
 * Draws the three sensor graphs for a node.
 *
 * PARAMETERS:      Name            RW  Usage
 *                  u8Node          R   Node to display
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vAddDesc(void)
{
    uint8  u8DeviceVer = 0x00;
    uint8  u8Flags = 0x00;
    uint8  u8EndPoint = 0x40;
    uint16 u16DeviceId = 0x0000;

    uint8 u8InputClusterCnt = 1;
    uint8 au8InputClusterList[] = {DAP_CID_SENSOR_READINGS};
    uint8 u8OutputClusterCnt = 0;
    uint8 au8OutputClusterList[] = {};

    (void)afmeSimpleDescAdd(u8EndPoint, DAP_PROFILE_ID, u16DeviceId,
                            u8DeviceVer, u8Flags, u8InputClusterCnt,
                            au8InputClusterList, u8OutputClusterCnt,
                            au8OutputClusterList);
}

PRIVATE void vSendOnUart(const char *pcString)
{
    while (*pcString)
    {
        while ((u8AHI_UartReadLineStatus(0) & E_AHI_UART_LS_THRE) == 0);
        vAHI_UartWriteData(0, *pcString);
        pcString++;
    }
}

/****************************************************************************/
/***        END OF FILE                                                   ***/
/****************************************************************************/

⌨️ 快捷键说明

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