コード例 #1
0
ファイル: Menu.c プロジェクト: alshorin/projects
void MENU_Event( MENU_Event_t event )
{
    //MENU_LOG( "MENU_Event: %s\n", gMenuEventStr[ event ]);

    if ( !MENU_IsActive() )
    {
        MENU_MemItem_t  mainMenu;

        // Menu isn't currently being displayed. Activate at the top.

        gMenuStackTop = 0;
        gMenuModified = 0;

        MENU_GetItem( gMenuStack[ 0 ], &mainMenu ); 

        MENU_Activate( mainMenu.val.menu );
    }
    else
    {
        MENU_MemItem_t  topItem;

        MENU_GetItem( gMenuStack[ gMenuStackTop ], &topItem ); 

        if ( MENU_IsEditing() )
        {
            (gMenuEditFunc[ topItem.type ])( event, &topItem );

            if ( event == MENU_EVENT_LEFT )
            {
                // Acts like a cancel

                gMenuIsEditing = 0;
            }
            else
            if ( event == MENU_EVENT_SELECT )
            {
                // Value was selected

                gMenuModified = 1;
                gMenuIsEditing = 0;
            }
        }
        else
        {
            MENU_EventEditMenu( event, &topItem );
        }
    }

    if ( event != MENU_EVENT_TIMER )
    {
        MENU_Draw();
    }

} // MENU_Event
コード例 #2
0
ファイル: LineMaze.c プロジェクト: balajianbu/projects
int main( void )
{
    int         i;
    int         led = 0;
    uint16_t    prevSwitches = 0;

    InitHardware();
    InitADC();
    InitMotors();

    eeprom_read_block( &gMemParam, &gEEParam, sizeof( gMemParam ));

    if ( gMemParam.thresh_hi == 0xFF )
    {
        gMemParam.thresh_hi = 0x80;
    }
    if ( gMemParam.thresh_lo == 0xFF )
    {
        gMemParam.thresh_lo = 0x10;
    }

#if CFG_LOG_USE_STDIO
    fdevopen( UART0_PutCharStdio, UART0_GetCharStdio );

    LogInit( stdout );
#endif

    // The first handle opened for read goes to stdin, and the first handle
    // opened for write goes to stdout. So u0 is stdin, stdout, and stderr

    Log( "*****\n" );
    Log( "***** Line Maze program\n" );
    Log( "*****\n" );

    LCD_Init( 2, 16 );
    LCD_Printf( " SRS Sample Bot " );
    LCD_MoveTo( 0, 1 );
    LCD_Printf( "Second line" );

    Log( "\n" );

    MENU_Init( gTopMenu );

    LED_OFF( GREEN );

    while( 1 )
    {
        uint16_t    switches;
        uint8_t     pinc;
        uint8_t     pind;
        int8_t      error;

        LED_TOGGLE( GREEN );

        led++;
        if ( led >= 6 )
        {
            led = 0;
        }

        error = GetLineError();

        if ( MENU_IsActive() )
        {
            MENU_Event( MENU_EVENT_TIMER );
        }
        else
        {
            if ( MENU_IsModified() )
            {
                eeprom_write_block( &gMemParam, &gEEParam, sizeof( gMemParam ));
                MENU_ClearModified();

                LCD_Clear();
                LCD_Printf( "EEPROM Updated\n" );
                Log( "EEPROM Updated\n" );
                ms_spin( 1000 );
            }

            //switches = EXP_TransferWord( ~( 1 << ( led + 2 )), EXP_OUT_LED_MASK );
            switches = EXP_TransferWord( 0, 0 );
            Log( "SW:%04x ", switches );

            if ( switches != prevSwitches )
            {
                LCD_Clear();
                prevSwitches = switches;
            }
            for ( i = 0; i < 8; i++ )
            {
                Log( "%02x ", gLineADC[ i ]);
            }

            //Log( "C: %02x\n", PINC );

            switch (( switches & 0xF0 ) >> 4 )
            {
            case 0:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( " SRS Sample Bot " );
                LCD_MoveTo( 0, 1 );
                LCD_Printf( "Second line" );
                break;
            }

            case 1:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( "Joy: %c%c%c%c%c",
                            (( switches & 0x4000 ) == 0 ) ? 'L' : ' ',
                            (( switches & 0x2000 ) == 0 ) ? 'R' : ' ',
                            (( switches & 0x0800 ) == 0 ) ? 'U' : ' ',
                            (( switches & 0x0400 ) == 0 ) ? 'D' : ' ',
                            (( switches & 0x1000 ) == 0 ) ? 'X' : ' ' );
                LCD_MoveTo( 0, 1 );
                LCD_Printf( "S1:%d S2:%d S3:%d",
                            ( switches & 0x0200 ) == 0,
                            ( switches & 0x0100 ) == 0,
                            ( PIND & ( 1 << 6 ))  == 0 );
                break;
            }

            case 2:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( "L %02x %02x %02x %02x %02x",
                            gLineADC[ 0 ],
                            gLineADC[ 1 ],
                            gLineADC[ 2 ],
                            gLineADC[ 3 ],
                            gLineADC[ 4 ] );

                LCD_MoveTo( 0, 1 );
                LCD_Printf( "E %02x %02x %3d B %02x", gADC[ 0 ], gADC[ 7 ], error, gADC[ 6 ] );
                break;
            }

            default:
            {
                LCD_MoveTo( 0, 0 );
                LCD_Printf( "Setting: %d", ( switches & 0xF0 ) >> 4 );
                break;
            }
            }

            pinc = PINC;
            pind = PIND;

            Log( " QL:%d%d QR:%d%d EC-L:%d EC-R:%d Err:%2d L:%5b H:%5b\n",
                 ( ENCODER_L_A_PIN & ENCODER_L_A_MASK ) != 0,
                 ( ENCODER_L_B_PIN & ENCODER_L_B_MASK ) != 0,
                 ( ENCODER_R_A_PIN & ENCODER_R_A_MASK ) != 0,
                 ( ENCODER_R_B_PIN & ENCODER_R_B_MASK ) != 0,
                 gEncoderCountL,
                 gEncoderCountR,
                 error, gLowMask, gHighMask );
        }

        // Tick rate is 100/sec so waiting for 50 waits for 1/2 sec

        for ( i = 0; i < 50; i++ )
        {
            WaitForTimer0Rollover();
            CheckSwitches();

#if 1
            if ( UART0_IsCharAvailable() )
            {
                char    ch = UART0_GetChar();

                if ( ch == ' ' )
                {
                    DebugKey();
                }
                else
                {
                    Log( "Read: '%c'\n", ch );
                }
            }
#endif
        }
    }

    return 0;
}
コード例 #3
0
ファイル: Menu.c プロジェクト: alshorin/projects
void MENU_Draw( void )
{
    char           *s;
    char            fmtStr[ 10 ];
    uint16_t        val = 0;
    uint16_t        maxVal = 0;
    int16_t         ival = 0;
    int16_t         maxIVal = 0;
    uint8_t         maxLen;
    uint8_t         valLen;
    MENU_MemItem_t  item;
    uint8_t         signedVal = 0;

    if ( !MENU_IsActive() )
    {
        return;
    }

    if ( MENU_IsEditing() )
    {
        MENU_GetItem( gMenuStack[ gMenuStackTop ], &item );
    }
    else
    {
        // By only drawing when we're not editing, we reduce flicker

        LCD_Clear();

        // First of all, draw the title of the containing menu

        MENU_GetItem( gMenuStack[ gMenuStackTop - 1 ], &item );
        LCD_PutStr_P( item.name );

        // Now draw the currently selected item

        LCD_MoveTo( 0, 1 );

        MENU_GetItem( gMenuStack[ gMenuStackTop ], &item );
        LCD_PutStr_P( item.name );
    }

    switch ( item.type )
    {
        case MENU_TYPE_BYTE:
        {
            if ( MENU_IsEditing() )
            {
                val = gMenuEditVal.uintVal;
            }
            else
            {
                val = *item.val.byteVal.bytePtr;
            }
            maxVal =  item.val.byteVal.maxVal;
            break;
        }

        case MENU_TYPE_UINT:
        {
            if ( MENU_IsEditing() )
            {
                val = gMenuEditVal.uintVal;
            }
            else
            {
                val = *item.val.uintVal.uintPtr;
            }
            maxVal =  item.val.uintVal.maxVal;
            break;
        }

        case MENU_TYPE_INT:
        {
            signedVal = 1;

            if ( MENU_IsEditing() )
            {
                ival = gMenuEditVal.intVal;
            }
            else
            {
                ival = *item.val.intVal.intPtr;
            }
            maxIVal =  item.val.intVal.maxVal;
            break;
        }

        default:
        {
            return;
        }
    }

    if ( signedVal )
    {
        snprintf( fmtStr, sizeof( fmtStr ), "%d", maxIVal );
        maxLen = strlen( fmtStr );
        snprintf( fmtStr, sizeof( fmtStr ), "%d", ival );
    }
    else
    {
        snprintf( fmtStr, sizeof( fmtStr ), "%u", maxVal );
        maxLen = strlen( fmtStr );
        snprintf( fmtStr, sizeof( fmtStr ), "%u", val );
    }

    LCD_MoveTo( LCD_NumCols() - maxLen - 2, LCD_NumLines() - 1 );

    LCD_PutChar( MENU_IsEditing() ? '[' : ' ' );

    valLen = strlen( fmtStr );
    while ( maxLen > valLen )
    {
        LCD_PutChar( ' ' );
        maxLen--;
    }

    s = fmtStr;
    while ( valLen > 0 )
    {
        LCD_PutChar( *s++ );
        valLen--;
    }

    LCD_PutChar( MENU_IsEditing() ? ']' : ' ' );

} // MENU_Draw