00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00016 /* Copyright (c) 2009 Atmel Corporation. All rights reserved. 00017 * 00018 * Redistribution and use in source and binary forms, with or without 00019 * modification, are permitted provided that the following conditions are met: 00020 * 00021 * 1. Redistributions of source code must retain the above copyright notice, this 00022 * list of conditions and the following disclaimer. 00023 * 00024 * 2. Redistributions in binary form must reproduce the above copyright notice, 00025 * this list of conditions and the following disclaimer in the documentation 00026 * and/or other materials provided with the distribution. 00027 * 00028 * 3. The name of Atmel may not be used to endorse or promote products derived 00029 * from this software without specific prior written permission. 00030 * 00031 * 4. This software may only be redistributed and used in connection with an Atmel 00032 * AVR product. 00033 * 00034 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 00035 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00036 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00037 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 00038 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00039 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00040 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00041 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00042 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00043 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00044 * 00045 */ 00046 //_____ I N C L U D E S ___________________________________________________ 00047 #include "conf_explorer.h" 00048 #include "navigation.h" 00049 #include "nav_flat.h" 00050 #include "file.h" 00051 #include LIB_CTRLACCESS 00052 00053 00054 //_____ D E C L A R A T I O N S ____________________________________________ 00055 00056 //********************************************************************** 00057 //****************** File list navigation FLAT functions *************** 00058 00059 00071 Bool nav_flat_mount( void ) 00072 { 00073 fs_g_nav.u8_flat_dir_level = 0; 00074 fs_g_nav.u16_flat_pos_offset = 0; 00075 return nav_partition_mount(); 00076 } 00077 00078 00084 Bool nav_flat_root( void ) 00085 { 00086 fs_g_nav.u8_flat_dir_level = 0; 00087 fs_g_nav.u16_flat_pos_offset = 0; 00088 return nav_dir_root(); 00089 } 00090 00096 Bool nav_flat_reset( void ) 00097 { 00098 while( 0 != fs_g_nav.u8_flat_dir_level ) 00099 { 00100 fs_g_nav.u8_flat_dir_level--; 00101 nav_dir_gotoparent(); 00102 } 00103 fs_g_nav.u16_flat_pos_offset = 0; 00104 return nav_filelist_reset(); 00105 } 00106 00107 00113 Bool nav_flat_validpos( void ) 00114 { 00115 return nav_filelist_validpos(); 00116 } 00117 00118 00124 Bool nav_flat_fileisnotopen( void ) 00125 { 00126 return nav_filelist_fileisnotopen(); 00127 } 00128 00129 00135 Bool nav_flat_next( void ) 00136 { 00137 U16 u16_save_current_pos; 00138 00139 u16_save_current_pos = nav_filelist_get(); 00140 if( nav_file_isdir() ) 00141 { 00142 // The current file is a dir then enter in this 00143 if( !nav_dir_cd() ) 00144 return FALSE; 00145 if( nav_filelist_set( 0 , FS_FIND_NEXT ) ) 00146 { 00147 // A file is present in this dir then valid the new position 00148 fs_g_nav.u8_flat_dir_level++; 00149 fs_g_nav.u16_flat_pos_offset += u16_save_current_pos+1; 00150 return TRUE; 00151 }else{ 00152 // No file then return in parent dir 00153 if( !nav_dir_gotoparent() ) 00154 return FALSE; // Error 00155 } 00156 } 00157 // Find next file in the current dir or the parent dir 00158 while( !nav_filelist_set( 0 , FS_FIND_NEXT ) ) 00159 { 00160 // End of the directory then goes to parent 00161 if( 0 == fs_g_nav.u8_flat_dir_level ) 00162 return FALSE; // End of list FLAT 00163 if( !nav_dir_gotoparent() ) 00164 return FALSE; // Error 00165 fs_g_nav.u8_flat_dir_level--; 00166 } 00167 fs_g_nav.u16_flat_pos_offset = (fs_g_nav.u16_flat_pos_offset +u16_save_current_pos +1) -nav_filelist_get(); 00168 return TRUE; 00169 } 00170 00171 00177 Bool nav_flat_previous( void ) 00178 { 00179 U16 u16_save_current_pos; 00180 00181 u16_save_current_pos = nav_filelist_get(); 00182 if( nav_filelist_set( 0 , FS_FIND_PREV ) ) 00183 { 00184 while( 1 ) 00185 { 00186 if( !nav_file_isdir() ) 00187 { 00188 fs_g_nav.u16_flat_pos_offset = ((fs_g_nav.u16_flat_pos_offset +u16_save_current_pos) -nav_filelist_get()) -1; 00189 return TRUE; // New valid position 00190 } 00191 // The selection is a dir then enter in this 00192 if( !nav_dir_cd() ) 00193 return FALSE; 00194 if( !nav_filelist_set( 0 , FS_FIND_NEXT ) ) 00195 { 00196 // The dir is empty then goes to the parent 00197 nav_dir_gotoparent(); 00198 // The parent dir is the new selection 00199 fs_g_nav.u16_flat_pos_offset = ((fs_g_nav.u16_flat_pos_offset +u16_save_current_pos) -nav_filelist_get()) -1; 00200 return TRUE; 00201 } 00202 fs_g_nav.u8_flat_dir_level++; 00203 // Go to the end of dir 00204 while( nav_filelist_set( 0 , FS_FIND_NEXT ) ); 00205 } 00206 } 00207 // Beginning of the directory then goes to parent directory 00208 if( 0 == fs_g_nav.u8_flat_dir_level ) 00209 return FALSE; // beginning of the file list FLAT 00210 if( !nav_dir_gotoparent() ) 00211 return FALSE; 00212 fs_g_nav.u8_flat_dir_level--; 00213 fs_g_nav.u16_flat_pos_offset -= (nav_filelist_get()+1); 00214 return TRUE; 00215 } 00216 00217 00223 U16 nav_flat_get( void ) 00224 { 00225 return (fs_g_nav.u16_flat_pos_offset + nav_filelist_get()); 00226 } 00227 00228 00236 Bool nav_flat_goto( U16 u16_newpos ) 00237 { 00238 if (u16_newpos < (nav_flat_get()/2)) 00239 { 00240 // Restart at the beginning of list to accelerate the search 00241 if (!nav_flat_reset()) 00242 return FALSE; 00243 } 00244 if (!nav_flat_validpos()) 00245 { 00246 // Go to first position 00247 if (!nav_flat_next()) 00248 return FALSE; // Empty list 00249 } 00250 00251 while(u16_newpos < nav_flat_get()) 00252 { 00253 if( !nav_flat_previous()) 00254 return FALSE; // Position error 00255 } 00256 while(u16_newpos > nav_flat_get()) 00257 { 00258 if( !nav_flat_next()) 00259 return FALSE; // End of the list, then the position is bad 00260 } 00261 return TRUE; 00262 } 00263 00264 00278 Bool nav_flat_findname( const FS_STRING sz_name , Bool b_match_case ) 00279 { 00280 while( 1 ) 00281 { 00282 if ( !nav_flat_next() ) 00283 return FALSE; 00284 if ( nav_file_name( sz_name , 0 , FS_NAME_CHECK , b_match_case )) 00285 return TRUE; 00286 } 00287 } 00288 00289 00294 U16 nav_flat_nb( void ) 00295 { 00296 U16 u16_save_position; 00297 U16 u16_number; 00298 00299 // Save current position 00300 u16_save_position = nav_flat_get(); 00301 00302 // Reset position 00303 if ( !nav_flat_reset()) 00304 return 0; 00305 00306 // Scan all directories 00307 u16_number = 0; 00308 while( nav_flat_next() ) 00309 { 00310 u16_number++; 00311 } 00312 // Restore previous position 00313 nav_flat_goto( u16_save_position ); 00314 00315 return u16_number; 00316 } 00317 00318 00324 Bool nav_flat_cd( void ) 00325 { 00326 if( !nav_dir_cd() ) 00327 return FALSE; 00328 fs_g_nav.u8_flat_dir_level = 0; 00329 fs_g_nav.u16_flat_pos_offset = 0; 00330 return TRUE; 00331 } 00332 00333 00343 Bool nav_flat_gotoparent( void ) 00344 { 00345 _MEM_TYPE_SLOW_ Fs_index index; 00346 index = nav_getindex(); 00347 while( 0 != fs_g_nav.u8_flat_dir_level ) 00348 { 00349 fs_g_nav.u8_flat_dir_level--; 00350 nav_dir_gotoparent(); 00351 } 00352 if( !nav_dir_gotoparent() ) 00353 { 00354 nav_gotoindex( &index ); 00355 return FALSE; 00356 } 00357 // Go to at the beginning of FLAT list 00358 fs_g_nav.u8_flat_dir_level = 0; 00359 fs_g_nav.u16_flat_pos_offset = 0; 00360 nav_filelist_reset(); 00361 nav_flat_next(); 00362 return TRUE; 00363 } 00364