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

📄 homesensorcoord.c

📁 Micro controladores jennic wireless networking zigbee
💻 C
📖 第 1 页 / 共 5 页
字号:

    case E_KEY_1:
        /* Control screen button */
        sDemoData.sSystem.eState = E_STATE_NODE_CONTROL;
        sDemoData.sGui.u8ControlSelection = 0;
        vBuildNodeControlScreen(sDemoData.sGui.u8CurrentNode);
        break;

    case E_KEY_2:
        /* On button */
        sDemoData.sNode.asNodeData[sDemoData.sGui.u8CurrentNode].boDeviceOn = TRUE;
        break;

    case E_KEY_3:
        /* Off button */
        sDemoData.sNode.asNodeData[sDemoData.sGui.u8CurrentNode].boDeviceOn = FALSE;
        break;
    }
}

/****************************************************************************
 *
 * NAME: vProcessNodeControlKeyPress
 *
 * DESCRIPTION:
 * Handles button presses on the Node Control screen. The first button
 * selects which item to alter, the next two adjust the value up or down, and
 * the last button returns to the Node screen.
 *
 * PARAMETERS:      Name        RW  Usage
 *                  u8KeyMap    R   Current buttons pressed bitmap
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vProcessNodeControlKeyPress(uint8 u8KeyMap)
{
    tsNodeData *psNodeData = &sDemoData.sNode.asNodeData[sDemoData.sGui.u8CurrentNode];
    bool_t bUpNotDown;

    switch (u8KeyMap)
    {
    case E_KEY_0:
        /* Select button: move to next item in list */
        vAdjustAlarm(&sDemoData.sGui.u8ControlSelection, CONTROL_LIST_LEN - 1, 0, TRUE);
        vUpdateNodeControlScreen(sDemoData.sGui.u8CurrentNode, sDemoData.sGui.u8ControlSelection, TRUE);
        break;

    case E_KEY_1:
        /* Plus button: increment value */
    case E_KEY_2:
        /* Minus button: decrement value */

        bUpNotDown = (u8KeyMap == E_KEY_1);

        switch (sDemoData.sGui.u8ControlSelection)
        {
        case 0:
            /* Temp high alarm */
            vAdjustAlarm(&psNodeData->asNodeElementData[E_SENSOR_TEMP].u8HighAlarm,
                         TEMP_HIGH_MAX, 0, bUpNotDown);
            break;

        case 1:
            /* Temp low alarm */
            vAdjustAlarm(&psNodeData->asNodeElementData[E_SENSOR_TEMP].u8LowAlarm,
                            TEMP_HIGH_MAX, 255, bUpNotDown);
            break;

        case 2:
            /* Light high alarm */
            vAdjustAlarm(&psNodeData->asNodeElementData[E_SENSOR_ALS].u8HighAlarm,
                            LIGHT_HIGH_MAX, 0, bUpNotDown);
            break;

        case 3:
            /* Light low alarm */
            vAdjustAlarm(&psNodeData->asNodeElementData[E_SENSOR_ALS].u8LowAlarm,
                            LIGHT_HIGH_MAX, 255, bUpNotDown);
            break;
        }

        vUpdateNodeControlScreen(sDemoData.sGui.u8CurrentNode, sDemoData.sGui.u8ControlSelection, TRUE);
        break;

    case E_KEY_3:
        /* Done button: return to node screen */
        sDemoData.sSystem.eState = E_STATE_NODE;
        vBuildNodeScreen(sDemoData.sGui.u8CurrentNode);
        break;
    }
}

/****************************************************************************
 *
 * NAME: vProcessSetupKeyPress
 *
 * DESCRIPTION:
 * Handles button presses on the Setup screen. The first button
 * selects which item to alter, the next two adjust the value up or down, and
 * the last button puts the device into running mode, starting the beacons
 * and moving to the Network screen.
 *
 * PARAMETERS:      Name        RW  Usage
 *                  u8KeyMap    R   Current buttons pressed bitmap
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vProcessSetupKeyPress(uint8 u8KeyMap)
{
    switch (u8KeyMap)
    {
    case E_KEY_0:
        /* Select button: move to next item in list */
        vAdjustAlarm(&sDemoData.sGui.u8SetupSelection, SETUP_LIST_LEN - 1, 0, TRUE);
        vUpdateSetupScreen(sDemoData.sGui.u8SetupSelection, TRUE);
        break;

    case E_KEY_1:
        /* Plus button: increment value */
    case E_KEY_2:
        /* Minus button: decrement value */

        switch (sDemoData.sGui.u8SetupSelection)
        {
        case 0:
            /* Local node */
            vToggleOnOff(&sDemoData.sNode.bLocalNode);
            break;

        case 1:
            /* Four node selection */
            vToggleOnOff(&sDemoData.sGui.bShowFourNodes);
            break;
        }

        vUpdateSetupScreen(sDemoData.sGui.u8SetupSelection, TRUE);
        break;

    case E_KEY_3:
        /* Done button: start beaconing and go to network screen. If
           local node is not being used, number of associated nodes is 0,
           as none can have associated yet, otherwise it is 1 as set during
           initialisation */
        if (sDemoData.sNode.bLocalNode == FALSE)
        {
            sDemoData.sNode.u8AssociatedNodes = 0;
        }

        vStartBeacon();
        sDemoData.sSystem.eState = E_STATE_NETWORK;
        vBuildNetworkScreen(sDemoData.sGui.eCurrentSensor);
        break;
    }
}

/****************************************************************************
 *
 * NAME: vBuildSetChannelScreen
 *
 * DESCRIPTION:
 * Creates the Set Channel screen, consisting of a bitmap of the Jennic logo
 * and labels for the soft buttons on the bottom row. Uses the related update
 * function to display the current channel and refresh the LCD.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vBuildSetChannelScreen(void)
{
    vLcdClear();

    vLcdWriteBitmap((tsBitmap *)&sJennicLogo, 0, 1);

    /* Soft keys */
    vLcdWriteText("Ch", 7, 0);
    vLcdWriteText("\\", 7, 47);
    vLcdWriteText("]", 7, 74);
    vLcdWriteText("Done", 7, 103);

    /* Update to display the data */
    vUpdateSetChannelScreen();
}

/****************************************************************************
 *
 * NAME: vUpdateSetChannelScreen
 *
 * DESCRIPTION:
 * Updates the Set Channel screen, when it first appears or when the user
 * changes the channel number.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vUpdateSetChannelScreen(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(teSensor eSensor)
{
    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 iPos;

    vLcdClear();

    /* If showing four nodes, they appear on screen as follows:
         Node 0    Node 1
         Node 2    Node 3

       If showing only three nodes, they appear as follows:
         Info      Node 0
         Node 1    Node 2
    */
    if (sDemoData.sGui.bShowFourNodes)
    {
        iPos = 0;
    }
    else
    {
        iPos = 1;
        vLcdWriteText("Network", 0, 0);
        vLcdWriteText("overview", 1, 0);
    }

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

    /* Hot buttons at bottom of screen */
    vLcdWriteText("Node", 7, 0);
    for (iPos = 0; iPos < DEMO_SENSOR_LIST_LEN; iPos++)
    {
        vLcdWriteText((char *)apcSensorLabel[iPos], 7, au8LabelPos[iPos]);
    }
    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;
    int iPos;
    bool_t bShowRssi;

    /* If showing four nodes, they appear on screen as follows:
         Node 0    Node 1
         Node 2    Node 3

       If showing only three nodes, they appear as follows:
         Info      Node 0
         Node 1    Node 2
    */
    if (sDemoData.sGui.bShowFourNodes)
    {
        iPos = 0;
    }
    else
    {
        iPos = 1;
    }

    u8Node = 0;
    bShowRssi = sDemoData.sNode.bLocalNode ? FALSE : TRUE;

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

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

        u8Node++;
        iPos++;
        bShowRssi = TRUE;
    }

    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
 *              bShowRssi           R   True to show RSSI data
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vLcdUpdateElement(tsNodeData *psNodeData, teSensor eSensor,
                               uint8 u8Row, uint8 u8Col, bool_t bShowRssi)
{
    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 ((u8NowValue >= psNodeElementData->u8HighAlarm)
        && (psNodeElementData->u8HighAlarm != 0))
    {
        vLcdWriteInvertedText("High", (uint8)(u8Row + 1), u8Col);

⌨️ 快捷键说明

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