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

📄 prodtestcoord.c

📁 Micro controladores jennic wireless networking zigbee
💻 C
📖 第 1 页 / 共 5 页
字号:
 *
 * NAME: vProcessSetChannelKeyPress
 *
 * DESCRIPTION:
 * Handles button presses on the Set Channel screen. There is one parameter
 * that can be adjusted (the channel) and buttons to navigate to two other
 * screens.
 *
 * PARAMETERS:      Name        RW  Usage
 *                  u8KeyMap    R   Current buttons pressed bitmap
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vProcessSetChannelKeyPress(uint8 u8KeyMap)
{
    switch (u8KeyMap)
    {
    case E_KEY_0:
        /* Further setup button: go to setup screen */
        sDemoData.sSystem.eState = E_STATE_SETUP_SCREEN;
        vBuildSetupScreen();
        break;

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

        vAdjustAlarm(&sDemoData.sSystem.u8Channel, CHANNEL_MAX, CHANNEL_MIN, u8KeyMap == E_KEY_1);
        vUpdateSetChannelScreen();
        break;

    case E_KEY_3:
        /* Done button: start beaconing and go to network screen */
        vStartBeacon();
        sDemoData.sSystem.eState = E_STATE_NETWORK;
        vBuildNetworkScreen(sDemoData.sGui.eCurrentSensor);
        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 */
        vUpdateNetworkSensor(E_SENSOR_TEMP);
        break;

    case E_KEY_2:
        /* Humidity button: change if not already there */
        vUpdateNetworkSensor(E_SENSOR_HTS);
        break;

    case E_KEY_3:
        /* Temp button: change if not already there */
        vUpdateNetworkSensor(E_SENSOR_ALS);
        break;
    }
}

/****************************************************************************
 *
 * NAME: vUpdateNetworkSensor
 *
 * DESCRIPTION:
 * Simple function to save a little code. If the user presses a button on the
 * Network screen to select a sensor, this checks that the sensor is not the
 * same as the current sensor before updating the screen.
 *
 * PARAMETERS:      Name            RW  Usage
 *                  eSensor         R   New sensor to display
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vUpdateNetworkSensor(teSensor eSensor)
{
    if (sDemoData.sGui.eCurrentSensor != eSensor)
    {
        sDemoData.sGui.eCurrentSensor = eSensor;
        vBuildNetworkScreen(eSensor);
    }
}
/****************************************************************************
 *
 * 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;
            sDemoData.sGui.eCurrentSensor = E_SENSOR_TEMP;
            vBuildNetworkScreen(E_SENSOR_TEMP);
        }
        else
        {
            vBuildNodeScreen(sDemoData.sGui.u8CurrentNode);
        }
        break;

    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

⌨️ 快捷键说明

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