One of my clients asked me to play sound from an SD card. But file selection should be random because the device is used to scare animals in the field(animals should not get used to sound pattern). I can generate random numbers by
void RNG_Generate_Numbers()
{
HAL_RNG_GenerateRandomNumber(&hrng, &random_number.random_number1);
HAL_RNG_GenerateRandomNumber(&hrng, &random_number.random_number2);
}
And I can count files via
void File_Find_File(file_manager_t *file_manage)
{
file_manage->file_result = f_readdir(&file_manage->file_direction, &file_manage->file_info);
if( (file_manage->file_result != FR_OK) || (file_manage->file_info.fname[0] == '\0') )
{
file_manage->file_counter = 0;
}
else
{
++file_manage->file_counter;
}
}
Everything till here is just fine. But when It comes to select files randomly, I could not find any method to do it. Any help is appreciated. Edit: This is file_manager structure;
typedef struct __file_manager /* struct tag */
{
FATFS drive_handler;
FIL file_handler;
FRESULT file_result;
uint8_t file_disk_status;
DIR file_direction;
FILINFO file_info;
uint8_t file_rx_buffer[512];
char file_current_dir[256];
uint32_t file_bytes_read;
uint32_t file_bytes_write;
size_t file_counter;
}file_manager_t ;
Aucun commentaire:
Enregistrer un commentaire