/** * @brief CDC data transmit callback. * @param phost: Host handle * @retval None */ void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost) { uint32_t bytesread; if(use_file == 1) { if( MyFile.fptr >= MyFile.fsize) { f_close(&MyFile); LCD_DbgLog (">> File sent\n" ); use_file = 0; } else { /* Fill the buffer to Send */ f_read(&MyFile, CDC_TX_Buffer, TX_BUFF_SIZE, (void *)&bytesread); /* Send File */ USBH_CDC_Transmit(&hUSBHost, CDC_TX_Buffer, bytesread); } } else { LCD_DbgLog (">> Data sent\n" ); } }
/** * @brief Sends file to the root. * @param fileidx: File index * @retval None */ static void CDC_SendFile(uint8_t fileidx) { uint32_t bytesread; if(FileList.ptr > 0) { /* Close any opened file */ f_close(&MyFile); if(f_open(&MyFile, (char *)FileList.file[fileidx].name, FA_OPEN_EXISTING | FA_READ) == FR_OK) { /* Fill the buffer to Send */ f_read(&MyFile, CDC_TX_Buffer, TX_BUFF_SIZE, (void *)&bytesread); /* Send File */ USBH_CDC_Transmit(&hUSBHost, CDC_TX_Buffer, bytesread); } else { LCD_ErrLog("Cannot open %s file\n", FileList.file[0].name); } } else { LCD_ErrLog("No file on the microSD\n"); } }
/** * @brief Handles CDC Send Menu. * @param None * @retval None */ void CDC_Handle_Send_Menu(void) { switch(CdcDemo.Send_state) { case CDC_SEND_IDLE: CdcDemo.Send_state = CDC_SEND_WAIT; CDC_SendState = 0; USBH_CDC_Stop(&hUSBHost); memset(CDC_TX_Buffer, 0x5A, TX_BUFF_SIZE); LCD_LOG_ClearTextZone(); LCD_DbgLog("Sending data ...\n"); USBH_CDC_Transmit(&hUSBHost, CDC_TX_Buffer, TX_BUFF_SIZE); break; case CDC_SEND_WAIT: if(CDC_SendState == 1) /* Data sent */ { BSP_LCD_ClearStringLine(19); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_DisplayStringAtLine(19, (uint8_t *)"Press User button to start receiving data "); /* Wait for User Input */ while((BSP_PB_GetState(BUTTON_KEY) != SET) && (Appli_state != APPLICATION_DISCONNECT)) { } HAL_Delay(400); CdcDemo.state = CDC_DEMO_RECEIVE; CdcDemo.Send_state = CDC_SEND_IDLE; } break; default: break; } }
/** * @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; }