/* * Copyright (c) 2006-2012 by Roland Riegel * * This file is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include "main.h" #define DEBUG 1 #define MAX_SONG_NUM 9 typedef struct { struct fat_file_struct* fd; char* name; } song_info_t; song_info_t songs[MAX_SONG_NUM]; int main() { /* we will just use ordinary idle mode */ //set_sleep_mode(SLEEP_MODE_IDLE); /* open first partition */ struct partition_struct* partition = partition_open(sd_raw_read, sd_raw_read_interval, 0, 0, 0 ); if(!partition) { /* If the partition did not open, assume the storage device * is a "superfloppy", i.e. has no MBR. */ partition = partition_open(sd_raw_read, sd_raw_read_interval, 0, 0, -1 ); } /* open file system */ struct fat_fs_struct* fs = fat_open(partition); /* open root directory */ struct fat_dir_entry_struct directory; fat_get_dir_entry_of_path(fs, "/", &directory); struct fat_dir_struct* dd = fat_open_dir(fs, &directory); // Get all of the song names struct fat_dir_entry_struct dir_entry; uint8_t song_id = 0; while(fat_read_dir(dd, &dir_entry)) { // too many files! if (song_id == MAX_SONG_NUM) { break; } // Is file, so add to list if (!(dir_entry.attributes & FAT_ATTRIB_DIR)) { // TODO add checking if its .wav // Copy song name into memory uint8_t len = strlen(dir_entry.long_name); songs[song_id].name = malloc(len); strcpy(songs[song_id].name, dir_entry.long_name); // Open file and keep info in songs fat_open_file(fs, songs[song_id].fd); // Move on to reading next song song_id++; } } // Print out all files/directories in top level while (1) { /// do stuff uint8_t incoming_cmd; if (fifo_pop(&incoming_cmd) == FIFO_SUCCESS) { // Handle incoming command } // TODO check here if we are running into the end of our song buffer, and read in song data } return 0; }