Exemple #1
0
void SwitchTurnedOn( uint8_t switchNum )
{
    switch ( switchNum )
    {
    case SWITCH_JOY_DOWN:
        MENU_Event( MENU_EVENT_DOWN );
        break;
    case SWITCH_JOY_UP:
        MENU_Event( MENU_EVENT_UP );
        break;
    case SWITCH_JOY_SELECT:
        MENU_Event( MENU_EVENT_SELECT );
        break;
    case SWITCH_JOY_RIGHT:
        MENU_Event( MENU_EVENT_RIGHT);
        break;
    case SWITCH_JOY_LEFT:
        MENU_Event( MENU_EVENT_LEFT );
        break;
    }
}
Exemple #2
0
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;
}
Exemple #3
0
static void MENU_EventEditMenu( MENU_Event_t event, MENU_MemItem_t *item )
{
    MENU_LOG(  "MENU_EventEditMenu: %s\n", gMenuEventStr[ event ]);

    switch ( event )
    {
        case MENU_EVENT_SELECT:
        {
            if ( item->type != MENU_TYPE_MENU )
            {
                gMenuIsEditing = 1;

                MENU_Event( MENU_EVENT_INIT );
                break;
            }

            // Fall thru
        }

        case MENU_EVENT_RIGHT:
        {
            if ( item->type == MENU_TYPE_MENU )
            {
                // The item selected is another menu. Activate it.

                MENU_Activate( item->val.menu );
            }
            break;
        }

        case MENU_EVENT_LEFT:
        {
            gMenuStackTop--;
            break;
        }

        case MENU_EVENT_UP:
        {
            if ( gMenuStack[ gMenuStackTop ] <= MENU_GetItem( gMenuStack[ gMenuStackTop - 1 ], item )->val.menu ) 
            {
                while ( MENU_GetItem( gMenuStack[ gMenuStackTop ], item )->name != NULL )
                {
                    gMenuStack[ gMenuStackTop ]++;
                }
            }
            gMenuStack[ gMenuStackTop ]--;
            break;
        }

        case MENU_EVENT_DOWN:
        {
            gMenuStack[ gMenuStackTop ]++;

            if ( MENU_GetItem( gMenuStack[ gMenuStackTop ], item )->name == NULL )
            {
                gMenuStack[ gMenuStackTop ] = MENU_GetItem( gMenuStack[ gMenuStackTop - 1 ], item )->val.menu;
            }
            break;
        }

        default:
            break;
    }

} // MENU_EventEditMenu