Esempio n. 1
0
void main_menu(FILINFO* pfile_info) {
  const char* ppitems[] = {S_MODE_PLAY, S_MODE_RECORD, S_MODE_OPTIONS};
  uint8_t cur_mode = 0;
  if ((g_num_files = get_num_files(pfile_info)) == 0) {
    lcd_title_P(S_NO_FILES_FOUND);
    return;
  }

  while (1) {
    cur_mode = handle_select_mode(S_SELECT_MODE, ppitems, 3, cur_mode);
    switch (cur_mode) {
      case MODE_PLAY:
        handle_play_mode(pfile_info);
      break;
      case MODE_RECORD:
        handle_record_mode(pfile_info);
      break;
      case MODE_OPTIONS:
        handle_mode_options();
      break;
      case SELECT_MODE_EXIT:
        cur_mode = 0;
      break;
    }
  }
}
Esempio n. 2
0
/********************************************************
 *	print_dir
 *
 * Takes the a directory's ID and prints the child
 * directories and files within.
 ********************************************************/
void print_dir( uint32_t id )
{
	uint32_t i, num_children, num_files;
	struct FS_Directory *children;
	struct FS_File *dir_files;

	num_children = get_num_children( id );
	if ( num_children )
	{
		children = get_children( id );
		for ( i = 0; i < num_children; i++ )
			printf("%s\n", children[i].name );
		free( children );
	}
	

	num_files = get_num_files( id );
	if ( num_files )
	{
		dir_files = get_files( id );
		for ( i = 0; i < num_files; i++ )
			printf("%s\n", dir_files[i].name );
		free( dir_files );
	}
		
}
Esempio n. 3
0
void show_commits()
{
	const char *snap_dir_name = ".nako/snaps";

	DIR *snap_dir = opendir(snap_dir_name);
	struct dirent *dp;

	int num_files = get_num_files(snap_dir);

	struct snap *snaps = malloc(num_files * sizeof(*snaps));

	int counter = 0;
	while ((dp = readdir(snap_dir)) != NULL) {
		if (dp->d_type == DT_REG) {
			snaps[counter].hash = NULL;
			asprintf(&snaps[counter].hash, "%s", dp->d_name);

			char *full_file_name = NULL;
			asprintf(&full_file_name, "%s/%s", snap_dir_name,
					dp->d_name);

			snaps[counter].file = fopen(full_file_name, "r");

			free(full_file_name);

			snaps[counter].message = malloc(1024
				* sizeof(*snaps[counter].message));
			snaps[counter].time_str = malloc(11
				* sizeof(*snaps[counter].time_str));

			fscanf(snaps[counter].file, "%[^\n]s",
				snaps[counter].message);
			fscanf(snaps[counter].file, "%s",
				snaps[counter].time_str);

			counter++;
		}
	}

	qsort(snaps, num_files, sizeof(*snaps), &snapcmp);

	for (counter = 0; counter < num_files; counter++) {
			time_t snap_time = atol(snaps[counter].time_str);
			struct tm *lt = localtime(&snap_time);
			char time_str[80];
			strftime(time_str, 80, "%c", lt);

			printf("%.10s @ %s - %s\n", snaps[counter].hash,
				time_str,
				snaps[counter].message);

			free(snaps[counter].time_str);
			free(snaps[counter].message);
			free(snaps[counter].hash);
	}
}
Esempio n. 4
0
/********************************************************
 *	get_files
 *
 * Takes the a directory's ID and returns a pointer to
 * an allocated array of FS_File structs representing the
 * files within that directory. 
 * (Don't forget to free the memory)
 ********************************************************/
struct FS_File* get_files( uint32_t id )
{
	uint32_t num_files, file_offset;
	struct FS_File *dir_files;

	num_files = get_num_files( id );
	file_offset = get_file_offset( id );

	dir_files = (struct FS_File*)malloc( num_files * sizeof( struct FS_File) );
	memcpy( dir_files, &files[file_offset], num_files * sizeof( struct FS_File ) );

	return dir_files; 
}
void filter_calcs(void) {
	
    //External variables
    extern char filtersinput[FILEPATH_LENGTH];
    extern char galssedinput[FILEPATH_LENGTH];
    extern char starssedinput[FILEPATH_LENGTH];
	
    //Internal variables
    long *N,ii;
    long sedlength = 0;
    long regridfactor;
    long filterlength[Nfilter]; 

    double *pnorm;
    double *filtlamb,*filtthru;

    //Allocate temporary variables
    N     = (long *)malloc(sizeof(long));
    pnorm = (double *)malloc(sizeof(double));
	
    //How many filters?
    get_num_files(filtersinput, N);
    Nfilter = *N;
    if (Nfilter<2) {
        printf("Need more than 1 filter\n");
        return;
    }
    printf("\n\nFound %ld Filters\n",Nfilter);
	
    //Read in the number of star/galaxy SEDs
    get_num_files(starssedinput, N);
    Nstartemplate = *N;
    get_num_files(galssedinput, N);
    Ngaltemplate  = *N;
	
    //Find the finest SED amongst the bunch
    for (ii=0;ii<Nstartemplate;ii++) {	
        get_filelength(ii,starssedinput,N);
        if (*N * 2 > sedlength) 
            sedlength = *N * 2;
    }
    for (ii=0;ii<Ngaltemplate;ii++) {	
        get_filelength(ii,galssedinput,N);
        if (*N * 2 > sedlength)
            sedlength = *N * 2;
    }
	
	
    //Allocate final filter arrays, which are globals
    filter_lgth_fine = (long *)malloc(Nfilter*sizeof(long)); 
    filter_lamb_fine = malloc(Nfilter*sizeof(double*));
    filter_thru_fine = malloc(Nfilter*sizeof(double*));
    norm             = (double *)malloc(Nfilter*sizeof(double));
	
	
    //Loop over the filters in the file
    for (ii=0;ii<Nfilter;ii++) {
		
        //get length
        get_filelength(ii,filtersinput, N);
        filterlength[ii]     = *N;
        regridfactor = round((float)sedlength / (float)*N);
        filter_lgth_fine[ii] = *N * regridfactor;
		
        //alloc filter arrays
        filtlamb = (double *)malloc(*N * sizeof(double));
        filtthru = (double *)malloc(*N * sizeof(double));
        filter_lamb_fine[ii] = (double *)malloc(regridfactor * *N * sizeof(double));
        filter_thru_fine[ii] = (double *)malloc(regridfactor * *N * sizeof(double));
        
        //read in the 2 column ascii filter file
        read_file(ii,filtersinput,filtlamb,filtthru);
        
        //regrid the filter to user spec, using gsl spline interpolation
        regrid_filter(filtlamb,filtthru,filterlength[ii],filter_lgth_fine[ii], \
                      filter_lamb_fine[ii],filter_thru_fine[ii]);
                    
        //calculate the flux zeropoint
        calc_normalization(filter_lamb_fine[ii],filter_thru_fine[ii], \
                           filter_lgth_fine[ii],pnorm);
        norm[ii] = *pnorm;
        printf("Filter %ld has (AB) zeropoint flux normalization: %g\n",ii,norm[ii]);
		
        free(filtlamb);
        free(filtthru);
    }
    free(pnorm);
    free(N);
	

}
Esempio n. 6
0
void handle_play_mode(FILINFO* pfile_info) {
  // reset to the root after a possible record operation
  change_dir("/");
  // refresh the file list to avoid blank entries bug
  if ((g_num_files = get_num_files(pfile_info)) == 0) {
    lcd_title_P(S_NO_FILES_FOUND);
    lcd_busy_spinner();
    return;
  }

  g_cur_file_index = 0;
  if (!get_file_at_index(pfile_info, g_cur_file_index)) {
    // shouldn't happen...
    lcd_title_P(S_NO_FILES_FOUND);
    lcd_busy_spinner();
    return;
  }

  lcd_title_P(S_SELECT_FILE);
  display_filename(pfile_info);
  
  while (1) {
    switch(get_cur_command()) {
      case COMMAND_SELECT:
        if (pfile_info->fattrib & AM_DIR) {
          if (change_dir(pfile_info->fname) == FR_OK) {
            g_num_files = get_num_files(pfile_info);
            g_cur_file_index = 0;
            get_file_at_index(pfile_info, g_cur_file_index);
            display_filename(pfile_info);
          } else {
            lcd_status_P(S_CHDIR_FAILED);
          }
        } else {
          display_filename(pfile_info);
          play_file(pfile_info);
          lcd_title_P(S_SELECT_FILE);
          // buffer is used so get the file again
          get_file_at_index(pfile_info, g_cur_file_index);
          display_filename(pfile_info);
        }
      break;
      case COMMAND_ABORT:
        if (g_fs.cdir != 0) {
          if (change_dir("..") == FR_OK) {
            g_num_files = get_num_files(pfile_info);
            g_cur_file_index = 0;
            get_file_at_index(pfile_info, g_cur_file_index);
            display_filename(pfile_info);
          } else {
            lcd_status_P(S_CHDIR_FAILED);
          }        
        } else {
          // back to main menu
          return;
        }
      break;
      case COMMAND_NEXT:
        if (++g_cur_file_index >= g_num_files) {
          g_cur_file_index = 0;
        }
        get_file_at_index(pfile_info, g_cur_file_index);
        display_filename(pfile_info);
      break;
      case COMMAND_PREVIOUS:
        if (--g_cur_file_index < 0) {
          g_cur_file_index = g_num_files - 1;
        }
        get_file_at_index(pfile_info, g_cur_file_index);
        display_filename(pfile_info);
      break;
    }
    filename_ticker(pfile_info, get_timer_tick());
  }
}