コード例 #1
0
ファイル: bos_shell.c プロジェクト: kamejoko80/BamBooOS
/**
 * @brief         shell_func
 * @param[in]     void
 * @param[in,out] void
 * @return        void
 */
void shell_func (void)
{
    cursor_blink();

    while(1)
    {
        PRINT("\r\nBOS# ");
        
        UART0_AsyncReceive(64, g_rx_buffer, &rx_complete);
        BOS_WaitEvent(EVT_UART_RECEIVE);
        BOS_ClearEvent(EVT_UART_RECEIVE);

        if(check_cmd((char *)g_rx_buffer, "help"))
        {
            cmd_help();
        }
        else if(check_cmd((char *)g_rx_buffer, "info"))
        {
            cmd_info();
        }
        else if(check_cmd((char *)g_rx_buffer, "ps"))
        {
            cmd_ps();
        }
        else if(check_cmd((char *)g_rx_buffer, "mbx"))
        {
            cmd_mbx();
        }
        else
        {
            PRINT("\r\nCommand not found, type help for more details\r\n");
        }
    }
}
コード例 #2
0
/*------------------------------------------------------------------------------
 * Display Digit Shifting Routines
 *------------------------------------------------------------------------------
 */
void shift_digits_left(void){
  int i;
  int buf_len;
  
  for(i=0;i<SCROLL_DELAY;i++); // Delay of text moving across the display
  digits[cur_pos] &= 0x7F;  // Clear the cursor
  buf_len = strlen(buffer);
  if(buf_len < BUF_SIZE){
    buffer_pos++;
    if(buffer_pos == buf_len){
      buffer_pos--;
    }
    if(buffer_pos > 3){
      for(i=0;i<4;i++){
        digits[i] = numtab[buffer[buffer_pos-(3-i)]-'0'];
      }
    }
  }
  cursor_blink();
}
コード例 #3
0
int main (void) {
//  int i;
  int ret;
  char *emergency="! EMERGENCY !";
  char *welcome="Welcome.";
  char *enter_pin="Please Enter PIN.";
  char button_read = FALSE;  // Local snapshot of Global 'Button'

  /* error handling - reset LEDs */
  atexit(closing_time);
  signal(SIGINT, closing_time);

  term_initio();
  rs232_open();
  
  setup_ports();
  ret = pthread_create( &keypad_thread, NULL, keypad, NULL);

//  display_string(welcome,PADDED,BLOCKING);

  while(alive){
    if(state == EMERGENCY){
        display_string(emergency,PADDED,NOT_BLOCKING);
      continue;
    }
    switch(state){
      case WAITING_LOGGED_OUT:
        display_string(enter_pin,PADDED,NOT_BLOCKING);
        digits[0] = 0x80;  // Set cursor position
        
        while(!button && alive && state == WAITING_LOGGED_OUT){ // Just Wait 
         usleep(SLEEP);
        }
        if(state == EMERGENCY) break; // Get out if there's an emergency
        if(button >= '0' && button <= '9'){
          state = INPUTTING_PIN; // Fall through to next state
        }
        else{
          break;
        }
        
      case INPUTTING_PIN:
        if(button_read = button){ // Intentionally Assignment
          input_pin(button_read);  // Sends a snapshot of button
        }
        cursor_blink();
        break;
        
      case WAITING_LOGGED_IN:
        display_string("Enter Track Number.",PADDED,NOT_BLOCKING);
        digits[0] = 0x80;  // Set cursor position
        
        while(!button && alive && state == WAITING_LOGGED_IN){ // Just Wait 
          usleep(SLEEP);
        }
        if(state == EMERGENCY) break; // Get out if there's an emergency
        if(button >= '0' && button <= '9'){
          state = INPUTTING_TRACK_NUMBER; // Fall through to next state
        }
        else if(button == ENTER_MENU){
          state = MENU_SELECT; // Fall through to next state
          break;
        }
        else{
          break;
        }
        
      case INPUTTING_TRACK_NUMBER:
        if(button_read = button){ // Intentionally Assignment
          input_track_number(button_read);  // Sends a snapshot of button
        }
        cursor_blink();
        break;
        
      case MENU_SELECT:
        display_string("MENU.",PADDED,NOT_BLOCKING);
        menu_select();
        break;
        
      default:
        break;
    }
    delay();
  }


  pthread_join(keypad_thread, NULL);

  term_exitio();
  rs232_close();
  return 0;
}
コード例 #4
0
void input_track_number(char button_read){
  int i;
  
  switch(button_read){
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
    if(buffer_cnt != cur_pos){  // If cursor isn't at the end
      buffer_cnt--;  // Decrement it before next line, lest we wrongly add 1
    }
    if(++buffer_cnt > 4){ // Button has been pressed, let's up the buffer count
      buffer_cnt = 4; // Limit PIN to 4 digits
      cur_pos = 4; // Cursor is off the edge of the array and won't blink
      buffer[cur_pos] = 0; // Null terminate string containing PIN
    }
    else{   // Less than 4 digits already? Well, get it in there!
      digits[cur_pos] = numtab[button_read-'0'];// Display the digit pressed
      buffer[cur_pos] = button_read; // Copy ASCII button press
      cur_pos = buffer_cnt; // Point at next empty location
      cursor_blink();  // Clear last cursor and move to next empty space
      delay();  // Wait to make sure button has stopped being pressed
    }
//  printf("buffer: %s\nbuffer_cnt: %d\ncur_pos: %d\n",buffer,buffer_cnt,cur_pos);
    break;
    
  case ACCEPT_PLAY:
  case ENTER_MENU:
    if(cur_pos != buffer_cnt){  // Send cursor to the end
      cur_pos = buffer_cnt;
    }
    if(buffer_cnt < 4){
      display_string("Invalid.",PADDED,BLOCKING);
    }
    else{
      playing = TRUE;//play_track(buffer,strlen(buffer));
      if(playing == TRUE){
        printf("Track number: %s\n",buffer);
        display_string("  Track Number ",NOT_PADDED,NOT_BLOCKING);
        display_string(buffer,NOT_PADDED,NOT_BLOCKING);
        display_string(" Playing   ",NOT_PADDED,NOT_BLOCKING);
      }
      else{
        display_string("Track not found.",PADDED,NOT_BLOCKING);
      }
      state = WAITING_LOGGED_IN;
      reset_buffer();
    }
    break;

  case CANCEL:
    reset_buffer();
    state = WAITING_LOGGED_IN; // Go back to waiting
    break;

  case FORWARD:  // Move the cursor forward 1 digit
    if(buffer_cnt){
      if(++cur_pos>buffer_cnt){ // Scroll as far as 1 digit past last input
        cur_pos = buffer_cnt;
      }
    }
    cursor_blink(); // Update Cursor Position
//    printf("cursor_position: %d\n",cur_pos);
    break;
    
  case BACK:
    if(--cur_pos<=0){
      cur_pos=0;
    }
    cursor_blink();
//    printf("cursor_position: %d\n",cur_pos);
    break;
    
  case DELETE:
    if (cur_pos == 4 || cur_pos == buffer_cnt){
      buffer[--buffer_cnt] = 0;
      digits[cur_pos] &= 0x7F;
      digits[--cur_pos] = 0;
      cursor_blink();
    }
    else{
      digits[cur_pos] &= 0x7F;
      for(i=cur_pos;i<4;i++){
        digits[i] = digits[i+1];
        buffer[i] = buffer[i+1];
      }
      buffer[buffer_cnt--] = 0;
      digits[3] = 0;
    }
    if (!buffer_cnt || cur_pos < 0){
      cur_pos = 0;
      buffer_cnt = 0;
      buffer[buffer_cnt] = 0;
    }
//  printf("buffer: %s\nbuffer_cnt: %d\ncur_pos: %d\n",buffer,buffer_cnt,cur_pos);
    break;
  default:
    break;
  }
}