Scans the folder structure.

Dependents:   GR-PEACH_Digital_Signage

Committer:
dkato
Date:
Thu Jul 28 09:01:32 2016 +0000
Revision:
1:96838d590e9c
Parent:
0:c72b82f46360
Add include "FATFileSystem.h".

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:c72b82f46360 1 /*******************************************************************************
dkato 0:c72b82f46360 2 * DISCLAIMER
dkato 0:c72b82f46360 3 * This software is supplied by Renesas Electronics Corporation and is only
dkato 0:c72b82f46360 4 * intended for use with Renesas products. No other uses are authorized. This
dkato 0:c72b82f46360 5 * software is owned by Renesas Electronics Corporation and is protected under
dkato 0:c72b82f46360 6 * all applicable laws, including copyright laws.
dkato 0:c72b82f46360 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
dkato 0:c72b82f46360 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
dkato 0:c72b82f46360 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
dkato 0:c72b82f46360 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
dkato 0:c72b82f46360 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
dkato 0:c72b82f46360 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
dkato 0:c72b82f46360 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
dkato 0:c72b82f46360 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
dkato 0:c72b82f46360 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
dkato 0:c72b82f46360 16 * Renesas reserves the right, without notice, to make changes to this software
dkato 0:c72b82f46360 17 * and to discontinue the availability of this software. By using this software,
dkato 0:c72b82f46360 18 * you agree to the additional terms and conditions found by accessing the
dkato 0:c72b82f46360 19 * following link:
dkato 0:c72b82f46360 20 * http://www.renesas.com/disclaimer*
dkato 0:c72b82f46360 21 * Copyright (C) 2015 Renesas Electronics Corporation. All rights reserved.
dkato 0:c72b82f46360 22 *******************************************************************************/
dkato 0:c72b82f46360 23
dkato 0:c72b82f46360 24 #ifndef SCAN_FOLDER_H
dkato 0:c72b82f46360 25 #define SCAN_FOLDER_H
dkato 0:c72b82f46360 26
dkato 0:c72b82f46360 27 #include "r_typedefs.h"
dkato 1:96838d590e9c 28 #include "FATFileSystem.h"
dkato 0:c72b82f46360 29
dkato 0:c72b82f46360 30 /*--- Macro definition of folder scan ---*/
dkato 0:c72b82f46360 31 #define MAX_FOLDER_NUM (99u) /* Supported number of folders */
dkato 0:c72b82f46360 32 #define MAX_TRACK_NUM (999u) /* Supported number of files */
dkato 0:c72b82f46360 33 #define MAX_FOLDER_DEPTH (8u) /* Supported folder levels */
dkato 0:c72b82f46360 34 #define MAX_NAME_LENGTH (NAME_MAX) /* Maximum length of track name and folder name */
dkato 0:c72b82f46360 35 #define MAX_PATH_LENGTH (511) /* Maximum length of the full path */
dkato 0:c72b82f46360 36
dkato 0:c72b82f46360 37 class ScanFolder {
dkato 0:c72b82f46360 38 public:
dkato 0:c72b82f46360 39
dkato 0:c72b82f46360 40 /** Initializes the folder structure
dkato 0:c72b82f46360 41 *
dkato 0:c72b82f46360 42 */
dkato 0:c72b82f46360 43 void init();
dkato 0:c72b82f46360 44
dkato 0:c72b82f46360 45 /** Scans the folder structure
dkato 0:c72b82f46360 46 *
dkato 0:c72b82f46360 47 * @param p_root_name The character string to identify root directory.
dkato 0:c72b82f46360 48 * @param p_extension_tbl extension tbl
dkato 0:c72b82f46360 49 *
dkato 0:c72b82f46360 50 * @returns
dkato 0:c72b82f46360 51 * Results of process. true is success. false is failure.
dkato 0:c72b82f46360 52 */
dkato 0:c72b82f46360 53 bool scan(char_t * p_root_name, const char_t ** pp_extension_tbl);
dkato 0:c72b82f46360 54
dkato 0:c72b82f46360 55 /** Gets the total number of detected files
dkato 0:c72b82f46360 56 *
dkato 0:c72b82f46360 57 * @returns
dkato 0:c72b82f46360 58 * the total number of files
dkato 0:c72b82f46360 59 */
dkato 0:c72b82f46360 60 uint32_t getTotalFile();
dkato 0:c72b82f46360 61
dkato 0:c72b82f46360 62 /** Gets the file name
dkato 0:c72b82f46360 63 *
dkato 0:c72b82f46360 64 * @param track_id Track ID [0 - (total track - 1)]
dkato 0:c72b82f46360 65 *
dkato 0:c72b82f46360 66 * @returns
dkato 0:c72b82f46360 67 * Pointer to the file name.
dkato 0:c72b82f46360 68 */
dkato 0:c72b82f46360 69 const char_t * getFileName(const uint32_t track_id);
dkato 0:c72b82f46360 70
dkato 0:c72b82f46360 71 /** Opens the file
dkato 0:c72b82f46360 72 *
dkato 0:c72b82f46360 73 * @param track_id Track ID [0 - (total track - 1)]
dkato 0:c72b82f46360 74 *
dkato 0:c72b82f46360 75 * @returns
dkato 0:c72b82f46360 76 * Pointer to the track handle
dkato 0:c72b82f46360 77 */
dkato 0:c72b82f46360 78 FILE * open(const uint32_t track_id);
dkato 0:c72b82f46360 79
dkato 0:c72b82f46360 80 /** Closes the file
dkato 0:c72b82f46360 81 *
dkato 0:c72b82f46360 82 * @param fp Pointer to the track handle
dkato 0:c72b82f46360 83 */
dkato 0:c72b82f46360 84 void close(FILE * const fp);
dkato 0:c72b82f46360 85
dkato 0:c72b82f46360 86 private:
dkato 0:c72b82f46360 87 /* Information of a folder / track. */
dkato 0:c72b82f46360 88 typedef struct {
dkato 0:c72b82f46360 89 char_t name[MAX_NAME_LENGTH + 1]; /* Name of a folder / track. */
dkato 0:c72b82f46360 90 uint32_t parent_number; /* Number of the parent folder. */
dkato 0:c72b82f46360 91 } item_t;
dkato 0:c72b82f46360 92
dkato 0:c72b82f46360 93 /* Information of folder scan in USB memory */
dkato 0:c72b82f46360 94 typedef struct {
dkato 0:c72b82f46360 95 item_t folder_list[MAX_FOLDER_NUM]; /* Folder list */
dkato 0:c72b82f46360 96 item_t track_list[MAX_TRACK_NUM]; /* File list */
dkato 0:c72b82f46360 97 uint32_t total_folder; /* Total number of folders */
dkato 0:c72b82f46360 98 uint32_t total_file; /* Total number of files */
dkato 0:c72b82f46360 99 char_t work_buf[MAX_PATH_LENGTH + 1]; /* Work */
dkato 0:c72b82f46360 100 /* (Including the null terminal character.) */
dkato 0:c72b82f46360 101 } fid_scan_folder_t;
dkato 0:c72b82f46360 102
dkato 0:c72b82f46360 103 fid_scan_folder_t scan_data;
dkato 0:c72b82f46360 104
dkato 0:c72b82f46360 105 const char_t * get_full_path(const item_t * const p_item);
dkato 0:c72b82f46360 106 bool open_dir(const item_t * const p_item, FATFS_DIR * const p_fdir);
dkato 0:c72b82f46360 107 bool read_dir(FATFS_DIR * const p_fdir, const char_t ** const p_name, bool * const p_flag_dir);
dkato 0:c72b82f46360 108 bool regist_item(item_t * const p_item, const char_t * const p_name, const uint32_t parent);
dkato 0:c72b82f46360 109 bool check_extension(const char_t * const p_name, const char_t ** pp_extension_tbl);
dkato 0:c72b82f46360 110 bool check_folder_depth(const uint32_t folder_id);
dkato 0:c72b82f46360 111 };
dkato 0:c72b82f46360 112
dkato 0:c72b82f46360 113 #endif /* SCAN_FOLDER_H */