コード例 #1
0
ファイル: audio.c プロジェクト: taylor123454321/c_control
//*****************************************************************************
//
// Handles the SysTick timeout interrupt.
//
//*****************************************************************************
void
SysTickIntHandler(void)
{
    unsigned long ulData, ulDelta;

    //
    // Read the state of the buttons.
    //
    ulData = GPIOPinRead(GPIO_PORTG_BASE,
                         (GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |
                          GPIO_PIN_7));

    //
    // Determine the switches that are at a different state than the debounced
    // state.
    //
    ulDelta = ulData ^ g_ucSwitches;

    //
    // Increment the clocks by one.
    //
    g_ucSwitchClockA ^= g_ucSwitchClockB;
    g_ucSwitchClockB = ~g_ucSwitchClockB;

    //
    // Reset the clocks corresponding to switches that have not changed state.
    //
    g_ucSwitchClockA &= ulDelta;
    g_ucSwitchClockB &= ulDelta;

    //
    // Get the new debounced switch state.
    //
    g_ucSwitches &= g_ucSwitchClockA | g_ucSwitchClockB;
    g_ucSwitches |= (~(g_ucSwitchClockA | g_ucSwitchClockB)) & ulData;

    //
    // Determine the switches that just changed debounced state.
    //
    ulDelta ^= (g_ucSwitchClockA | g_ucSwitchClockB);

    //
    // See if the up button was just pressed.
    //
    if((ulDelta & 0x08) && !(g_ucSwitches & 0x08))
    {
        //
        // Increase the volume of the playback.
        //
        ClassDVolumeUp(16);
    }

    //
    // See if the down button was just pressed.
    //
    if((ulDelta & 0x10) && !(g_ucSwitches & 0x10))
    {
        //
        // Decrease the volume of the playback.
        //
        ClassDVolumeDown(16);
    }

    //
    // See if the left button was just pressed.
    //
    if((ulDelta & 0x20) && !(g_ucSwitches & 0x20))
    {
        //
        // Start playback of the PCM stream.
        //
        ClassDPlayPCM(g_pucPCMData, sizeof(g_pucPCMData));
    }

    //
    // See if the right button was just pressed.
    //
    if((ulDelta & 0x40) && !(g_ucSwitches & 0x40))
    {
        //
        // Start playback of the ADPCM stream.
        //
        ClassDPlayADPCM(g_pucADPCMData, sizeof(g_pucADPCMData));
    }

    //
    // See if the select button was just pressed.
    //
    if((ulDelta & 0x80) && !(g_ucSwitches & 0x80))
    {
        //
        // Stop playback.
        //
        ClassDStop();
    }
}
コード例 #2
0
//*****************************************************************************
//
// Performs all necessary menu and control processing based on new button
// states.
//
// \param ucButtons contains the current state of each of the front panel
// buttons.  A 1 in a bit position indicates that the corresponding button
// is released while a 0 indicates that the button is pressed.
// \param ucChanged contains bit flags showing which button states changed
// since the last call to this function.  A 1 indicates that the corresponding
// button state changed while a 0 indicates that it remains unchanged.
// \param ucRepeat contains bit flags indicating whether a key autorepeat
// event is being signalled for each key.  A 1 indicates that an autorepeat is
// being signalled while a 0 indicates that it is not.
//
// This is the top level function called when any key changes state.  This
// updates the relevant control or controls on the screen and processes
// the key appropriately for the control that currently has focus.
//
// \return Returns \b true if the menu was dismissed as a result of this
// call (in which case the caller should refresh the main waveform
// display area) or any control reported that a display update is required.
// Returns \b false if the menu is still being displayed or if it
// was not being displayed when the function was called and no control
// reported needing a display update.
//
//*****************************************************************************
tBoolean
MenuProcess(unsigned char ucButtons, unsigned char ucChanged,
            unsigned char ucRepeat)
{
    tGroup *pFocusGroup;
    tBoolean bRetcode;
    tBoolean bRedrawNeeded;

    //
    // Assume we won't be dismissing the menu until we find out otherwise.
    //
    bRedrawNeeded = false;

    //
    // Which group has focus?
    //
    pFocusGroup = g_sMenu.ppcGroups[g_sMenu.ucFocusGroup];

    //
    // Is the menu currently visible?
    //
    if(!g_bMenuShown)
    {
        //
        // The menu is not currently shown.  First check to see if we need to
        // show it and, if so, do this.  We look for a release of the select
        // button to trigger the display of the menu.  Note that we
        // deliberately ignore all other key notifications that may be present
        // at the same time.
        //
        if(BUTTON_RELEASED(SELECT_BUTTON, ucButtons, ucChanged))
        {
            //
            // Draw the menu.
            //
            g_bMenuShown = MenuDisplay(&g_sMenu);

            //
            // Get rid of any alert message that may currently be displayed.
            //
            RendererClearAlert();
        }
        else
        {
            //
            // We were not being asked to show the menu so we pass the
            // various events on to the group for it to decide what to do
            // with them.  For the group, we pass on any button press or auto-
            // repeat indication.  We ignore button releases in this case.
            //

            //
            // Left button press or repeat.
            //
            if(BUTTON_PRESSED(LEFT_BUTTON, ucButtons, ucChanged) ||
               BUTTON_REPEAT(LEFT_BUTTON, ucRepeat))
            {
                bRetcode = pFocusGroup->pfnGroupEventProc(pFocusGroup,
                                                          MENU_EVENT_LEFT);
                if(bRetcode)
                {
                    bRedrawNeeded = true;
                }
            }

            //
            // Right button press or repeat.
            //
            if(BUTTON_PRESSED(RIGHT_BUTTON, ucButtons, ucChanged) ||
               BUTTON_REPEAT(RIGHT_BUTTON, ucRepeat))
            {
                bRetcode = pFocusGroup->pfnGroupEventProc(pFocusGroup,
                                                          MENU_EVENT_RIGHT);
                if(bRetcode)
                {
                    bRedrawNeeded = true;
                }
            }

            //
            // Left button released.
            //
            if(BUTTON_RELEASED(LEFT_BUTTON, ucButtons, ucChanged))
            {
                bRetcode = pFocusGroup->pfnGroupEventProc(pFocusGroup,
                                                     MENU_EVENT_LEFT_RELEASE);
                if(bRetcode)
                {
                    bRedrawNeeded = true;
                }
            }

            //
            // Right button released.
            //
            if(BUTTON_RELEASED(RIGHT_BUTTON, ucButtons, ucChanged))
            {
                bRetcode = pFocusGroup->pfnGroupEventProc(pFocusGroup,
                                                     MENU_EVENT_RIGHT_RELEASE);
                if(bRetcode)
                {
                    bRedrawNeeded = true;
                }
            }

            //
            // Up button press.
            //
            if(BUTTON_PRESSED(UP_BUTTON, ucButtons, ucChanged) ||
               BUTTON_REPEAT(UP_BUTTON, ucRepeat))
            {
                bRetcode = pFocusGroup->pfnGroupEventProc(pFocusGroup,
                                                          MENU_EVENT_UP);
                if(bRetcode)
                {
                    bRedrawNeeded = true;
                }
            }

            //
            // Down button press.
            //
            if(BUTTON_PRESSED(DOWN_BUTTON, ucButtons, ucChanged) ||
               BUTTON_REPEAT(DOWN_BUTTON, ucRepeat))
            {
                bRetcode = pFocusGroup->pfnGroupEventProc(pFocusGroup,
                                                          MENU_EVENT_DOWN);
                if(bRetcode)
                {
                    bRedrawNeeded = true;
                }
            }
        }
    }
    else
    {
        //
        // The menu is already visible so we ignore left and right keys and
        // use up/down/select only to change the focus group.
        //

        //
        // If this button press will result in a group focus change we need to
        // redraw the current group in its non-focused colors, update the
        // focus to the new group then send an activate event to the group.
        //
        if(BUTTON_PRESSED(DOWN_BUTTON, ucButtons, ucChanged) ||
           BUTTON_REPEAT(DOWN_BUTTON, ucRepeat) ||
           BUTTON_PRESSED(UP_BUTTON, ucButtons, ucChanged) ||
           BUTTON_REPEAT(UP_BUTTON, ucRepeat))
        {
            //
            // Redraw the current focus button in its original colors
            //
            MenuDrawGroupButton(&g_sMenu, g_sMenu.ucFocusGroup,
                                &g_psBtnColors);

            //
            // Update the group with the focus
            //
            if(BUTTON_PRESSED(DOWN_BUTTON, ucButtons, ucChanged) ||
               BUTTON_REPEAT(DOWN_BUTTON, ucRepeat))
            {
                if(g_sMenu.ucFocusGroup < (g_sMenu.ucNumGroups - 1))
                {
                    g_sMenu.ucFocusGroup++;
                }
            }
            else
            {
                if(g_sMenu.ucFocusGroup > 0)
                {
                    g_sMenu.ucFocusGroup--;
                }
            }

            //
            // Redraw the new focus button with the focus colors.
            //
            MenuDrawGroupButton(&g_sMenu, g_sMenu.ucFocusGroup,
                                &g_psFocusColors);

            //
            // Tell the new group that it has been activated.
            //
            pFocusGroup = g_sMenu.ppcGroups[g_sMenu.ucFocusGroup];
            bRetcode = (pFocusGroup->pfnGroupEventProc)(pFocusGroup,
                                                        MENU_EVENT_ACTIVATE);
            if(bRetcode)
            {
                bRedrawNeeded = true;
            }
        }

        //
        // Now look for a release of the SELECT key.  This indicates that we
        // must dismiss the menu.
        //
        if(BUTTON_RELEASED(SELECT_BUTTON, ucButtons, ucChanged))
        {
            //
            // We did receive a release message for the SELECT button so
            // tell the caller that the menu has been dismissed.
            //
            g_bMenuShown = false;
            bRedrawNeeded = true;
        }
    }

    //
    // Play the button click sound if any button was just pressed.
    //
    if((~ucButtons & ucChanged) && g_bClicksEnabled)
    {
        ClassDPlayADPCM(g_pucADPCMClick, sizeof(g_pucADPCMClick));
    }

    return(bRedrawNeeded);
}