Ejemplo n.º 1
0
void _console_process_char(void)
{
    A_UINT8  character;
    int      length;
    int      bytes_avail;
    A_BOOL   extended = FALSE;
    
    while (TRUE) {
        
        length = 1;
        
        bytes_avail = SERP_Read(Console_info->port,(A_UINT8 *)&character,&length);

        if (length == 0) {
            break;    
        }
        
        //CONSOLE_OUTPUT("%2.2X\n",character);
        
        if (Console_info->flags & CONSOLE_FLAGS_RX_SUSPENDED) {
            if (character == ASCII_CARRIAGE_RETURN) {
                    /* activate the console when the first enter key is pressed */
                Console_info->flags &= ~CONSOLE_FLAGS_RX_SUSPENDED;
                if (!(Console_info->flags & CONSOLE_FLAGS_USE_HW_RX_SUSP)) {              
                        /* switch to fast polling in the port */
                    SERP_Ioctl(Console_info->port,
                               SER_PORT_HW_IOCTL_SET_POLL_INTERVAL,
                               NULL,
                               CONSOLE_FAST_POLL_INTERVAL_MS);
                }                         
            } else {
                continue;    
            }
        } 
        
        if (Console_info->current_escape_pos > 0) {
            /* in an escape sequence */  
            Console_info->escape_buffer[Console_info->current_escape_pos] = character;
            Console_info->current_escape_pos++;  
            if (Console_info->current_escape_pos >= MIN_ESCAPE_BYTES) {                              
                if (Console_info->escape_buffer[1] == '[') {
                    switch (Console_info->escape_buffer[2]) {
                        case 'A' :
                            /* cursor up */
                            show_console_history(TRUE);
                            break;
                        case 'B' :
                            /* cursor down */
                            show_console_history(FALSE);
                            break;                           
                        case 'C' :
                            /* cursor FORWARD */
                            if (!move_console_cursor(CURSOR_FORWARD)){
                                CONSOLE_OUTPUT(ASCII_BELL);    
                            } else {
                                CONSOLE_OUTPUT(ANSI_VT100_CURSOR_FWD);   
                            }
                            break;
                        case 'D' :
                            /* cursor BACKWARDS */
                            if (!move_console_cursor(CURSOR_BACKWARD)) {
                                CONSOLE_OUTPUT(ASCII_BELL);      
                            } else {
                                CONSOLE_OUTPUT(ANSI_VT100_CURSOR_BACK);
                            }
                            break;
                        case '4' :
                            if (Console_info->current_escape_pos <= MIN_ESCAPE_BYTES) {
                                extended = TRUE;
                            } else {
                                if (Console_info->escape_buffer[3] == 0x7e) {
                                        /* delete key */
                                    if (!process_console_delete()) {
                                        CONSOLE_OUTPUT(ASCII_BELL);      
                                    }          
                                }    
                            }
                            break;    
                        default:
                            break;    
                    }
                }
                
                if (!extended) {                
                    Console_info->current_escape_pos = 0;
                }    
            }
            continue;
        }
        
        if ((character >= 0x20) && (character <= 0x7E)) {            
            if (!insert_console_char(character)) {
                CONSOLE_OUTPUT(ASCII_BELL);       
            }                      
            continue;   
        }
        
        switch (character) {
            
            case ASCII_CARRIAGE_RETURN :
                if (Console_info->config.flags & CONSOLE_CONFIG_FLAGS_AWAKE_FOR_READ) {
                    A_POWER_SYSSLEEP_CONTROL(1); /* Permit sleep while processing cmd */
                }
                process_console_line();
                if (Console_info->config.flags & CONSOLE_CONFIG_FLAGS_AWAKE_FOR_READ) {
                    A_POWER_SYSSLEEP_CONTROL(0); /* disallow sleep while waiting for keystrokes */
                }
                if (Console_info->flags & CONSOLE_FLAGS_ALLOW_RX_SUSPEND) {
                    schedule_console_idle_recv_timer();                
                }
                break;
            case ASCII_BACK_SPACE :
                if (!process_console_backspace()) {
                    CONSOLE_OUTPUT(ASCII_BELL);    
                }  
                break;
            case ASCII_ESCAPE :
                Console_info->escape_buffer[0] = character;
                Console_info->current_escape_pos = 1;
                break;
            default :
                break;
        }
       
    }  
}
Ejemplo n.º 2
0
void update_cursor(void)
{
    move_console_cursor(pos_x, pos_y);
}