00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00015 /* Copyright (c) 2009 Atmel Corporation. All rights reserved. 00016 * 00017 * Redistribution and use in source and binary forms, with or without 00018 * modification, are permitted provided that the following conditions are met: 00019 * 00020 * 1. Redistributions of source code must retain the above copyright notice, this 00021 * list of conditions and the following disclaimer. 00022 * 00023 * 2. Redistributions in binary form must reproduce the above copyright notice, 00024 * this list of conditions and the following disclaimer in the documentation 00025 * and/or other materials provided with the distribution. 00026 * 00027 * 3. The name of Atmel may not be used to endorse or promote products derived 00028 * from this software without specific prior written permission. 00029 * 00030 * 4. This software may only be redistributed and used in connection with an Atmel 00031 * AVR product. 00032 * 00033 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 00034 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00035 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00036 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 00037 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00038 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00039 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00040 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00041 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00042 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00043 * 00044 */ 00045 //_____ I N C L U D E S ___________________________________________________ 00046 #include "conf_explorer.h" 00047 #include "navigation.h" 00048 #include "nav_filterlist.h" 00049 #include "file.h" 00050 #include LIB_CTRLACCESS 00051 00052 00053 //_____ D E C L A R A T I O N S ____________________________________________ 00054 00055 //********************************************************************** 00056 //****************** File list navigation FLAT functions *************** 00057 00058 00070 Bool nav_filterflat_mount( void ) 00071 { 00072 fs_g_nav.u8_flat_dir_level = 0; 00073 fs_g_nav.u16_flat_pos_offset = 0; 00074 return nav_filterlist_mount(); 00075 } 00076 00077 00083 Bool nav_filterflat_root( void ) 00084 { 00085 fs_g_nav.u8_flat_dir_level = 0; 00086 fs_g_nav.u16_flat_pos_offset = 0; 00087 return nav_filterlist_root(); 00088 } 00089 00090 00096 Bool nav_filterflat_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_filterlist_reset(); 00105 } 00106 00107 00113 Bool nav_filterflat_next( void ) 00114 { 00115 U16 u16_save_current_pos; 00116 00117 u16_save_current_pos = nav_filterlist_get(); 00118 if( nav_file_isdir() ) 00119 { 00120 // The current file is a dir then enter in this 00121 if( !nav_dir_cd() ) 00122 return FALSE; 00123 if( nav_filterlist_next() ) 00124 { 00125 // File present in this dir then valid the new position 00126 fs_g_nav.u8_flat_dir_level++; 00127 fs_g_nav.u16_flat_pos_offset += u16_save_current_pos+1; 00128 return TRUE; 00129 }else{ 00130 // No file then return in parent dir 00131 if( !nav_filterlist_gotoparent() ) 00132 return FALSE; 00133 } 00134 } 00135 // Find next file in current dir or parent dir 00136 while( !nav_filterlist_next() ) 00137 { 00138 // End of current directory then goes to parent 00139 if( 0 == fs_g_nav.u8_flat_dir_level ) 00140 return FALSE; // End of list FLAT 00141 if( !nav_filterlist_gotoparent() ) 00142 return FALSE; 00143 fs_g_nav.u8_flat_dir_level--; 00144 } 00145 fs_g_nav.u16_flat_pos_offset = (fs_g_nav.u16_flat_pos_offset +u16_save_current_pos +1) -nav_filterlist_get(); 00146 return TRUE; 00147 } 00148 00149 00155 Bool nav_filterflat_previous( void ) 00156 { 00157 U16 u16_save_current_pos; 00158 00159 u16_save_current_pos = nav_filterlist_get(); 00160 if( nav_filterlist_previous() ) 00161 { 00162 while( 1 ) 00163 { 00164 if( !nav_file_isdir() ) 00165 { 00166 fs_g_nav.u16_flat_pos_offset = ((fs_g_nav.u16_flat_pos_offset +u16_save_current_pos) -nav_filterlist_get()) -1; 00167 return TRUE; // New position valid 00168 } 00169 // The file is a dir then enter in this 00170 if( !nav_dir_cd() ) 00171 return FALSE; 00172 if( !nav_filterlist_next() ) 00173 { 00174 // Dir empty then goes to parent and dir is the new selection 00175 nav_filterlist_gotoparent(); 00176 fs_g_nav.u16_flat_pos_offset = ((fs_g_nav.u16_flat_pos_offset +u16_save_current_pos) -nav_filterlist_get()) -1; 00177 return TRUE; 00178 } 00179 fs_g_nav.u8_flat_dir_level++; 00180 // Go to end of the dir 00181 while( nav_filterlist_next() ); 00182 } 00183 } 00184 // Beginning of current directory then goes to parent 00185 if( 0 == fs_g_nav.u8_flat_dir_level ) 00186 return FALSE; // beginning of list FLAT 00187 if( !nav_filterlist_gotoparent() ) 00188 return FALSE; 00189 fs_g_nav.u8_flat_dir_level--; 00190 fs_g_nav.u16_flat_pos_offset -= (nav_filterlist_get()+1); 00191 return TRUE; 00192 } 00193 00194 00201 U16 nav_filterflat_get( void ) 00202 { 00203 return (fs_g_nav.u16_flat_pos_offset + nav_filterlist_get()); 00204 } 00205 00206 00214 Bool nav_filterflat_goto( U16 u16_newpos ) 00215 { 00216 if (u16_newpos < (nav_filterflat_get()/2)) 00217 { 00218 // Restart at the beginning of list to accelerate search 00219 if (!nav_filterflat_reset()) 00220 return FALSE; 00221 } 00222 if( FS_NO_SEL == nav_filterflat_get() ) 00223 if( !nav_filterflat_next() ) 00224 return FALSE; // No file available 00225 while( u16_newpos > nav_filterflat_get()) 00226 { 00227 if( !nav_filterflat_next()) 00228 return FALSE; // End of list, position is bad 00229 } 00230 while(u16_newpos < nav_filterflat_get()) 00231 { 00232 if( !nav_filterflat_previous()) 00233 return FALSE; // Position error 00234 } 00235 return TRUE; 00236 } 00237 00238 00252 Bool nav_filterflat_findname( const FS_STRING sz_name , Bool b_match_case ) 00253 { 00254 while( 1 ) 00255 { 00256 if ( !nav_filterflat_next() ) 00257 return FALSE; 00258 if ( nav_file_name( sz_name , 0 , FS_NAME_CHECK , b_match_case )) 00259 return TRUE; 00260 } 00261 } 00262 00263 00268 U16 nav_filterflat_nb( void ) 00269 { 00270 U16 u16_save_position; 00271 U16 u16_number; 00272 00273 // Save current position 00274 u16_save_position = nav_filterflat_get(); 00275 00276 // Reset position 00277 if ( !nav_filterflat_reset()) 00278 return 0; 00279 00280 // Scan all directory 00281 u16_number = 0; 00282 while( nav_filterflat_next() ) 00283 { 00284 u16_number++; 00285 } 00286 // Restore previous position 00287 nav_filterflat_goto( u16_save_position ); 00288 00289 return u16_number; 00290 } 00291 00292 00298 Bool nav_filterflat_cd( void ) 00299 { 00300 if( !nav_dir_cd() ) 00301 return FALSE; 00302 fs_g_nav.u8_flat_dir_level = 0; 00303 fs_g_nav.u16_flat_pos_offset = 0; 00304 return TRUE; 00305 } 00306 00307 00317 Bool nav_filterflat_gotoparent( void ) 00318 { 00319 _MEM_TYPE_SLOW_ Fs_index index; 00320 index = nav_getindex(); 00321 while( 0 != fs_g_nav.u8_flat_dir_level ) 00322 { 00323 fs_g_nav.u8_flat_dir_level--; 00324 nav_dir_gotoparent(); 00325 } 00326 if( !nav_dir_gotoparent() ) 00327 { 00328 nav_gotoindex( &index ); 00329 return FALSE; 00330 } 00331 // go to the beginning of FLAT list 00332 fs_g_nav.u8_flat_dir_level = 0; 00333 fs_g_nav.u16_flat_pos_offset = 0; 00334 nav_filterlist_reset(); 00335 nav_filterflat_next(); 00336 return TRUE; 00337 } 00338