Пример #1
0
static void SendFileMenu_Init(void)
{
  BSP_LCD_SetTextColor(LCD_COLOR_GREEN); 
  BSP_LCD_DisplayStringAtLine(14, (uint8_t *)"                                           ");
  BSP_LCD_DisplayStringAtLine(15, (uint8_t *)"[User Key] to switch menu                  ");
  BSP_LCD_DisplayStringAtLine(16, (uint8_t *)"[Joystick Up/Down] to change settings items");
  CDC_ChangeSelectMode(CDC_SELECT_FILE);
}
/**
  * @brief  Initiliazes Configuration Menu.
  * @param  None
  * @retval None
  */
static void ConfigurationMenu_Init(void)
{
  BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
  BSP_LCD_DisplayStringAtLine(13, (uint8_t *)"                                           ");    
  BSP_LCD_DisplayStringAtLine(14, (uint8_t *)"[User Key] to switch menu                  ");  
  BSP_LCD_DisplayStringAtLine(15, (uint8_t *)"[Joystick Left/Right] to change settings   ");
  BSP_LCD_DisplayStringAtLine(16, (uint8_t *)"[Joystick Up/Down] to change settings items");
  CDC_ChangeSelectMode(CDC_SELECT_CONFIG);
}
Пример #3
0
/**
  * @brief  Handles CDC Send Menu. 
  * @param  None
  * @retval None
  */
void CDC_Handle_Send_Menu(void)
{ 
  if(CdcSelectMode == CDC_SELECT_MENU)
  {
    switch(CdcDemo.Send_state)
    {
    case CDC_SEND_IDLE:
      CdcDemo.Send_state = CDC_SEND_WAIT;
      CDC_SelectItem (DEMO_SEND_menu, 0);
      CdcDemo.select = 0; 

      PrevPos = 0;
      USBH_CDC_Stop(&hUSBHost);
      break;
      
    case CDC_SEND_WAIT:
      if(CdcDemo.select != PrevSelect)
      {
        PrevSelect = CdcDemo.select;
        CDC_SelectItem (DEMO_SEND_menu, CdcDemo.select & 0x7F);
        
        /* Handle select item */
        if(CdcDemo.select & 0x80)
        {
          switch(CdcDemo.select & 0x7F)
          {
          case 0:
            memset(CDC_TX_Buffer, 0x5A, TX_BUFF_SIZE);
            LCD_DbgLog("Sending data ...\n"); 
            USBH_CDC_Transmit(&hUSBHost, CDC_TX_Buffer, TX_BUFF_SIZE);
            use_file = 0;
            break;
            
          case 1:
            if(FileList.ptr > 0)
            {
              SendFileMenu_Init();
              if(FilePos >= 9)
              {
                CDC_ShowFiles(FileOffset, 9);
              }
              
              else
              {
                CDC_ShowFiles(FileOffset, FilePos);
              }
              CdcDemo.Send_state = CDC_SEND_SELECT_FILE;
            }
            else
            {
             LCD_ErrLog("No file on the microSD\n"); 
            }
            break;
            
          case 2: /* Return */
            ReturnFromSendMenu();
            break;
          default:
            break;
          }
        }
      }
      break; 

    default:
      break;
    }
  }
  else if(CdcSelectMode == CDC_SELECT_FILE)
  {
    switch(CdcDemo.Send_state)
    {
    case  CDC_SEND_SELECT_FILE: 
      if(CdcDemo.select & 0x80)
      {
        CdcDemo.select &= 0x7F;
        CdcDemo.Send_state = CDC_SEND_TRANSMIT_FILE;        
      }
      break;
      
    case CDC_SEND_TRANSMIT_FILE: 
      LCD_DbgLog("Sending file ...\n"); 
      use_file = 1;
      CDC_SendFile(FilePos);
      CDC_ChangeSelectMode(CDC_SELECT_MENU);
      LCD_LOG_UpdateDisplay();
      CdcDemo.Send_state = CDC_SEND_WAIT;
      break;
      
    default:
      break;      
    }
    
    if(FilePos != PrevPos)
    {
      
      if(((FilePos > 9)&&(FilePos > PrevPos)) ||
         ((FilePos >= 9)&&(FilePos < PrevPos)))
      {
        if(FilePos > PrevPos)
        {
          FileOffset++;
        }
        else
        {
          FileOffset--;
        }
        CDC_ShowFiles(FileOffset, 9);        
      }
      else
      {
        CDC_ShowFiles(0, FilePos);
      }
      PrevPos = FilePos;      
    }
  }
  CdcDemo.select &= 0x7F;
}
Пример #4
0
/**
  * @brief  Manages CDC Menu Process.
  * @param  None
  * @retval None
  */
void CDC_MenuProcess(void)
{
  switch(CdcDemo.state)
  {
  case CDC_DEMO_IDLE:
    CDC_SelectItem(CDC_main_menu, 0); 
    CdcDemo.state = CDC_DEMO_WAIT;
    CdcDemo.select = 0;
    break;    
    
  case CDC_DEMO_WAIT:
    if(CdcDemo.select != PrevSelect)
    {
      PrevSelect = CdcDemo.select;
      CDC_SelectItem(CDC_main_menu, CdcDemo.select & 0x7F);
      
      /* Handle select item */
      if(CdcDemo.select & 0x80)
      {
        switch(CdcDemo.select & 0x7F)
        {
        case 0:
          CdcDemo.state = CDC_DEMO_SEND;
          CdcDemo.Send_state = CDC_SEND_IDLE;
          break;
          
        case 1:
          CdcDemo.state = CDC_DEMO_RECEIVE; 
          CdcDemo.Receive_state = CDC_RECEIVE_IDLE;   
          break;
          
        case 2:
          CdcDemo.state = CDC_DEMO_CONFIGURATION;  
          CdcDemo.Configuration_state = CDC_CONFIGURATION_IDLE; 
          break;
          
        case 3:
          CdcDemo.state = CDC_DEMO_REENUMERATE;  
          break;
          
        default:
          break;
        }
      }
    }
    break;
    
  case CDC_DEMO_SEND: 
    if(Appli_state == APPLICATION_READY)
    {    
      CDC_Handle_Send_Menu();
    }
    else
    {
      CdcDemo.state = CDC_DEMO_WAIT;
    }  
    break; 
    
  case CDC_DEMO_RECEIVE:
    if(Appli_state == APPLICATION_READY)
    {    
      CDC_Handle_Receive_Menu();
    }    
    else
    {
      CdcDemo.state = CDC_DEMO_WAIT;
    }
    break; 
    
  case CDC_DEMO_CONFIGURATION:
    if(Appli_state == APPLICATION_READY)
    {
      CDC_Handle_Configuration_Menu();
    }
    else
    {
      CdcDemo.state = CDC_DEMO_WAIT;
    }
    break;
    
  case CDC_DEMO_REENUMERATE:
    /* Force MSC Device to re-enumerate */
    USBH_ReEnumerate(&hUSBHost); 
    CdcDemo.state = CDC_DEMO_WAIT;
    break;
    
  default:
    break;
  } 
  
  CdcDemo.select &= 0x7F;
  
  if(Appli_state == APPLICATION_DISCONNECT)
  {
    Appli_state = APPLICATION_IDLE; 
    LCD_LOG_ClearTextZone();
    LCD_ErrLog("CDC device disconnected!\n");
    CDC_ChangeSelectMode(CDC_SELECT_MENU);
    CdcDemo.state = CDC_DEMO_IDLE;
    CdcDemo.select = 0;    
  } 
} 
Пример #5
0
/**
  * @brief  EXTI line detection callbacks.
  * @param  GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  static JOYState_TypeDef JoyState = JOY_NONE;
  static uint32_t debounce_time = 0;

  if(GPIO_Pin == GPIO_PIN_8)
  {    
    /* Get the Joystick State */
    JoyState = BSP_JOY_GetState();
    
    CDC_DEMO_ProbeKey(JoyState); 
    
    /* Clear joystick interrupt pending bits */
    BSP_IO_ITClear();
    
    if((CdcSelectMode == CDC_SELECT_MENU) && (CdcDemo.state != CDC_DEMO_RECEIVE))
    {
      switch(JoyState)
      {
      case JOY_LEFT:
        LCD_LOG_ScrollBack();
        break;
             
      case JOY_RIGHT:
        LCD_LOG_ScrollForward();
        break;          
        
      default:
        break;           
      }
    }
  }
  
  if(CdcDemo.state == CDC_DEMO_CONFIGURATION)
  {
    if(GPIO_Pin == KEY_BUTTON_PIN)
    {  
      /* Prevent debounce effect for user key */
      if((HAL_GetTick() - debounce_time) > 50)
      {
        debounce_time = HAL_GetTick();
      }
      else
      {
        return;
      }  
      BSP_LCD_SetBackColor(LCD_COLOR_BLACK); 
      /* Change the selection type */
      if(CdcSelectMode == CDC_SELECT_MENU)
      {
        CDC_ChangeSelectMode(CDC_SELECT_CONFIG); 
      }
      else if(CdcSelectMode == CDC_SELECT_CONFIG)
      {
        CDC_ChangeSelectMode(CDC_SELECT_MENU);
      }
      
      else if(CdcSelectMode == CDC_SELECT_FILE)
      {
        CDC_ChangeSelectMode(CDC_SELECT_FILE);
      }
    }
  }
  
  if(CdcDemo.state == CDC_DEMO_SEND)
  {
    if(GPIO_Pin == KEY_BUTTON_PIN)
    { 
      /* Prevent debounce effect for user key */
      if((HAL_GetTick() - debounce_time) > 50)
      {
        debounce_time = HAL_GetTick();
      }
      else
      {
        return;
      }  
      
      if(CdcDemo.Send_state == CDC_SEND_SELECT_FILE)
      {
        BSP_LCD_SetBackColor(LCD_COLOR_BLACK);   
        /* Change the selection type */
        if(CdcSelectMode == CDC_SELECT_MENU)
        {
          CDC_ChangeSelectMode(CDC_SELECT_FILE); 
        }
        else if(CdcSelectMode == CDC_SELECT_FILE)
        {
          LCD_ClearTextZone();    
          LCD_LOG_UpdateDisplay();
          CDC_ChangeSelectMode(CDC_SELECT_MENU);
          CdcDemo.Send_state = CDC_SEND_WAIT;
        }
      }
    }
  }  
}