30 #include <avr/pgmspace.h> 52 uint8_t file_open = 0, card_open = 0;
55 uint16_t file_getAnzLine (
void )
57 uint16_t counterLines = 0;
58 int32_t read_offset = 0;
65 while ( (count =
fat_read_file ( fd, buffer,
sizeof(buffer) )) > 0 )
67 for ( intptr_t i = 0; i < count; ++i )
69 if ( buffer[i] ==
'\r' )
76 return counterLines + 1;
79 void set_filepointer_position(int32_t offset){
84 uint8_t file_getLine ( uint16_t lineNr,
char* zielbuffer )
92 uint8_t bufferlen = 100;
93 uint8_t arbeitsbuffer[bufferlen];
94 uint16_t counterLines = 0;
95 int32_t pos_after_last_enter = 0;
105 while ( counterLines < lineNr - 1 )
112 for ( intptr_t i = 0; i < count; ++i )
114 if ( arbeitsbuffer[i] ==
'\r' )
117 pos_after_last_enter += (i + 1);
129 for ( intptr_t i = 0; i < count; ++i )
131 zielbuffer[i] = arbeitsbuffer[i];
132 if ( arbeitsbuffer[i] ==
'\r' )
134 zielbuffer[i + 1] = 0;
142 uint32_t strtolong (
const char* str )
145 while ( *str >=
'0' && *str <=
'9' )
146 l = l * 10 + (*str++ -
'0');
155 if ( strcmp ( dir_entry->
long_name, name ) == 0 )
168 if ( !find_file_in_dir ( fs, dd, name, &file_entry ) )
return 0;
179 printf (
"#........\r\n" );
180 printf (
"#manuf : %X\r\n", disk_info.manufacturer );
181 printf (
"#oem : %s\r\n", (
char*) disk_info.oem );
182 printf (
"#prod : %s\r\n", (
char*) disk_info.product );
183 printf (
"#rev : %X\r\n", disk_info.revision );
184 printf (
"#serial: %ld\r\n", disk_info.serial );
185 printf (
"#date : %i / %i\r\n", disk_info.manufacturing_month, disk_info.manufacturing_year );
186 printf (
"#size : %ld MB\r\n", ((
long) disk_info.capacity / 1024 / 1024) );
187 printf (
"#copy : %i\r\n", disk_info.flag_copy );
188 printf (
"#wr.pr.: %i / %i\r\n", disk_info.flag_write_protect_temp, disk_info.flag_write_protect );
189 printf (
"#format: %i\r\n", disk_info.format );
191 printf (
"#........\r\n" );
197 void sd_get_Directory (
void )
199 printf (
"#........Directory:\r\n" );
202 uint8_t spaces = 20 - strlen ( dir_entry.
long_name );
204 printf (
"# %s", (
char*) dir_entry.
long_name );
206 for ( uint8_t i = 0; i < spaces; i++ )
211 printf (
"%ld\r\n", dir_entry.
file_size );
215 void sd_card_open (
void )
217 if ( card_open == 1 )
return;
223 printf (
"#MMC/SD initialisation failed\r\n" );
240 printf(
"#opening partition failed\r\n");
250 printf(
"#opening filesystem failed\r\n");
261 printf(
"#opening root directory failed\r\n");
272 printf (
"#Card open\r\n" );
277 void sd_card_close (
void )
279 if ( card_open == 1 && card_open == 0 )
283 printf (
"#close: directory\r\n" );
287 printf (
"#close: file system \r\n" );
291 printf (
"#close: partition\r\n" );
297 int sd_file_open (
const char* filename )
299 if ( file_open == 1 )
302 printf (
"#File schon offen\r\n" );
307 fd = open_file_in_dir ( fs, dd, filename );
311 printf (
"#Fehler beim oeffen von: %s", filename );
319 printf (
"#File: %s geoeffnet\r\n", filename );
325 uint8_t sd_file_delete (
const char* filename )
329 if ( !find_file_in_dir ( fs, dd, filename, &file_entry ) )
return 0;
334 void sd_file_new (
const char* filename )
340 printf (
"#Fehler beim anlegen von: %s\r\n", filename );
346 printf (
"#File: %s erfolgreich angelegt\r\n", filename );
352 void sd_file_close (
void )
354 if ( file_open == 1 )
359 printf (
"#close: file\r\n" );
365 void sd_file_write_append (
const char* line )
367 if ( file_open == 1 )
372 int32_t write_offset = 0;
375 uint8_t data_len = strlen ( line );
376 if (
fat_write_file ( fd, (uint8_t*) line, data_len ) != data_len )
379 printf (
"#error writing to file\r\n" );
388 void file_write_line ( uint16_t lineNr,
const char* line )
390 if ( file_open == 1 )
396 uint8_t bufferlen = 100;
397 uint8_t arbeitsbuffer[bufferlen];
398 uint16_t counterLines = 0;
399 int32_t pos_after_last_enter = 0;
405 while ( counterLines < lineNr - 1 )
412 for ( intptr_t i = 0; i < count; ++i )
414 if ( arbeitsbuffer[i] ==
'\r' )
417 pos_after_last_enter += (i + 1);
425 uint8_t data_len = strlen ( line );
426 if (
fat_write_file ( fd, (uint8_t*) line, data_len ) != data_len )
429 printf (
"#error writing to file\r\n" );
437 uint8_t sd_get_disk_info (
void )
439 return print_disk_info ( fs );
uint8_t sd_raw_read_interval(offset_t offset, uint8_t *buffer, uintptr_t interval, uintptr_t length, sd_raw_read_interval_handler_t callback, void *p)
struct fat_dir_struct * fat_open_dir(struct fat_fs_struct *fs, const struct fat_dir_entry_struct *dir_entry)
uint8_t fat_reset_dir(struct fat_dir_struct *dd)
void fat_close_dir(struct fat_dir_struct *dd)
uint8_t sd_raw_get_info(struct sd_raw_info *info)
offset_t fat_get_fs_size(const struct fat_fs_struct *fs)
uint8_t fat_read_dir(struct fat_dir_struct *dd, struct fat_dir_entry_struct *dir_entry)
SD-Card Reader Bibliothek von Roland Riegel.
intptr_t fat_read_file(struct fat_file_struct *fd, uint8_t *buffer, uintptr_t buffer_len)
SD-Card Reader Bibliothek von Roland Riegel.
uint8_t fat_delete_file(struct fat_fs_struct *fs, struct fat_dir_entry_struct *dir_entry)
SD-Card Reader Bibliothek von Roland Riegel.
uint8_t fat_create_file(struct fat_dir_struct *parent, const char *file, struct fat_dir_entry_struct *dir_entry)
SD-Card Reader Bibliothek von Roland Riegel. MMC/SD/SDHC raw access header (license: GPLv2 or LGPLv2...
Datei aus der SD-Card Reader Bibliothek von M. Junghans.
uint8_t partition_close(struct partition_struct *partition)
uint8_t sd_raw_read(offset_t offset, uint8_t *buffer, uintptr_t length)
void fat_close_file(struct fat_file_struct *fd)
struct partition_struct * partition_open(device_read_t device_read, device_read_interval_t device_read_interval, device_write_t device_write, device_write_interval_t device_write_interval, int8_t index)
void fat_close(struct fat_fs_struct *fs)
uint8_t fat_get_dir_entry_of_path(struct fat_fs_struct *fs, const char *path, struct fat_dir_entry_struct *dir_entry)
intptr_t fat_write_file(struct fat_file_struct *fd, const uint8_t *buffer, uintptr_t buffer_len)
struct fat_file_struct * fat_open_file(struct fat_fs_struct *fs, const struct fat_dir_entry_struct *dir_entry)
uint8_t fat_seek_file(struct fat_file_struct *fd, int32_t *offset, uint8_t whence)
struct fat_fs_struct * fat_open(struct partition_struct *partition)
uint8_t sd_raw_write_interval(offset_t offset, uint8_t *buffer, uintptr_t length, sd_raw_write_interval_handler_t callback, void *p)
uint8_t sd_raw_write(offset_t offset, const uint8_t *buffer, uintptr_t length)
SD-Card Reader Bibliothek von Roland Riegel.
offset_t fat_get_fs_free(const struct fat_fs_struct *fs)