Пример #1
0
void config_flag_file_setting_save(char* file, int setting)
{
    FIO_RemoveFile(file);
    if (setting)
    {
        FILE* f = FIO_CreateFile(file);
        if (f) FIO_CloseFile(f);
    }
}
Пример #2
0
//dump ram and rom
void dumpmemo()
{
	FIO_RemoveFile("B:/RAMDUMP.BIN");
	int f = FIO_CreateFile("B:/RAMDUMP.BIN");
	
	if (f!=-1) { 
		FIO_WriteFile(f, (void*)0xFFFF0000, 4);
		FIO_WriteFile(f, (void*)4, 0x1900-4);
		FIO_WriteFile(f, (void*)0x1900, 32*1024*1024-0x1900);
		
		FIO_CloseFile(f);
	}
	
	f = FIO_OpenFile("B:/ROMDUMP.BIN", 0, 0644);
	FIO_CloseFile(f);
	
	if (f==-1) { 
		f = FIO_CreateFile("B:/ROMDUMP.BIN");		
		FIO_WriteFile(f, (void*)0xFF800000, 8*1024*1024);
		FIO_CloseFile(f);
	}
}
Пример #3
0
unsigned int module_config_save(char *filename, module_entry_t *module)
{
    if (!module->config)
        return -1;

    char* msg = fio_malloc(MAX_SIZE);
    msg[0] = '\0';

    snprintf( msg, MAX_SIZE,
              "# Config file for module %s (%s)\n\n",
              module->name, module->filename
            );

    int count = 0;
    for (module_config_t * mconfig = module->config; mconfig && mconfig->name; mconfig++)
    {
        if (*(int*)mconfig->ref->value == mconfig->ref->default_value)
            continue;

        snprintf(msg + strlen(msg), MAX_SIZE - strlen(msg) - 1,
                 "%s = %d\r\n",
                 mconfig->ref->name,
                 *(int*) mconfig->ref->value
                );

        count++;
    }

    if (count == 0)
    {
        /* everything is default, just delete the config file */
        FIO_RemoveFile(filename);
        goto finish;
    }

    FILE * file = FIO_CreateFile( filename );
    if (!file)
    {
        fio_free(msg);
        return -1;
    }

    FIO_WriteFile(file, msg, strlen(msg));

    FIO_CloseFile( file );
finish:
    fio_free(msg);
    return 0;
}
Пример #4
0
static void post_deflicker_save_sidecar_file(int type, char* photo_filename, float ev)
{
    /* find and strip extension */
    char* ext = photo_filename + strlen(photo_filename) - 1;
    while (ext > photo_filename && *ext != '/' && *ext != '.') ext--;
    if (*ext != '.') return;
    *ext = 0;
    
    /* find and strip base filename (e.g. IMG_1234) */
    char* p = ext;
    while (p > photo_filename && *p != '/') p--;
    if (*p != '/') return;
    *p = 0;
    
    /* path components */
    char* dir = photo_filename; /* A:/DCIM/100CANON */
    char* basename = p+1;       /* IMG_1234 */
    char* extension = ext+1;    /* CR2 */
    
    //~ NotifyBox(2000, "'%s'\n'%s'\n'%s'", dir, basename, extension);
    
    char sidecar[100];
    snprintf(sidecar, sizeof(sidecar), "%s/%s.%s", dir, basename, type ? "UFR" : "XMP");

    FILE* f = FIO_CreateFile(sidecar);
    if (!f) return;
    if (type == 0)
    {
        /* not sure */
        int evi = ev * 100000;
        
        my_fprintf(f, xmp_template, FMT_FIXEDPOINT5S(evi));
    }
    else if (type == 1)
    {
        char raw[100];
        char jpg[100];
        snprintf(raw, sizeof(raw), "%s.%s", basename, extension);
        snprintf(jpg, sizeof(jpg), "%s.JPG", basename);
        ev = COERCE(ev, -6, 6);
        int evi = ev * 100000;
        my_fprintf(f, ufraw_template, raw, jpg, FMT_FIXEDPOINT5(evi));
    }
    FIO_CloseFile(f);
}
Пример #5
0
static void find_response_curve(const char* fname)
{
    char fname_real[255];
    snprintf(fname_real, sizeof(fname_real), "ML/LOGS/%s", fname);
    FILE* f = FIO_CreateFile(fname_real);

    ensure_movie_mode();
    clrscr();
    set_lv_zoom(5);

    msleep(1000);

    for (int i = 0; i < 64*2; i+=8)
        bmp_draw_rect(COLOR_BLACK,  i*5+40, 0, 8*5, 380);

    draw_line( 40,  190,  720-40,  190, COLOR_BLACK);

    extern int bv_auto;
    //int bva0 = bv_auto;
    bv_auto = 0; // make sure it won't interfere

    bv_enable(); // for enabling fine 1/8 EV increments

    int ma = (lens_info.raw_aperture_min + 7) & ~7;
    for (int i = 0; i < 64*2; i++)
    {
        int a = (i/2) & ~7;                                // change aperture in full-stop increments
        lens_set_rawaperture(ma + a);
        lens_set_rawshutter(96 + i - a);                   // shutter can be changed in finer increments
        msleep(400);
        int Y,U,V;
        get_spot_yuv(180, &Y, &U, &V);
        dot( i*5 + 40 - 16,  380 - Y*380/255 - 16, COLOR_BLUE, 3); // dot has an offset of 16px
        my_fprintf(f, "%d %d %d %d\n", i, Y, U, V);
    }
    FIO_CloseFile(f);
    beep();
    //~ call("dispcheck");
    lens_set_rawaperture(ma);
    lens_set_rawshutter(96);
}
Пример #6
0
static MENU_SELECT_FUNC(config_preset_toggle)
{
    menu_numeric_toggle(&config_new_preset_index, delta, 0, config_preset_num);

    if (!config_new_preset_index)
    {
        FIO_RemoveFile(config_preset_file);
    }
    else
    {
        FILE* f = FIO_CreateFile(config_preset_file);
        if (f)
        {
            if (config_new_preset_index == 1)
                my_fprintf(f, "Startup mode");
            else if (config_new_preset_index == 2)
                my_fprintf(f, "Startup key");
            else
                my_fprintf(f, "%s", config_preset_choices[config_new_preset_index]);
            FIO_CloseFile(f);
        }
    }
}
Пример #7
0
void lv_rec_start()
{    
    int yPos = 3;
    lv_rec_data_t data;
    lv_rec_save_data_t save_data;
    
    /* set all values to zero */
    memset(&data, 0x00, sizeof(lv_rec_data_t));
    memset(&save_data, 0x00, sizeof(lv_rec_save_data_t));
    
    /* menu options */
    data.options.frameSkip = lv_rec_frame_skip;
    data.options.rawMode = lv_rec_raw_mode;
    data.options.singleFile = lv_rec_single_file;
    data.options.linesToSkip = lv_rec_line_skip;
    
    /* this causes the function to hang!? */
    if(data.options.rawMode)
    {
        //~ bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * yPos++, "Make sure you ran call('lv_save_raw')");
        call("lv_save_raw", 1);
        msleep(200);
        raw_update_params();
    }
    
    /* get maximum available memory */
    bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * yPos++, "Allocating memory");
    data.chunkData.memSuite = shoot_malloc_suite(0);
    
    if(!data.chunkData.memSuite)
    {
        bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * yPos++, "Failed to allocate memory");
        return;
    }
    unsigned int allocatedMemory = lv_rec_get_memsize(data.chunkData.memSuite);
    bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * yPos++, "Allocated %d MiB", allocatedMemory/1024/1024);

    
    save_data.options = data.options;
    save_data.chunkData = data.chunkData;
    
    /* ensure the selected profile is applied, dont rely on menu painting to do this for us */
    lv_rec_update_preset(&save_data);
    
    /* file sequence number */
    int start_number = 0;
    
    /* set file pre/suffixes */
    if(data.options.singleFile)
    {
        strcpy(save_data.filePrefix, "M");
    }
    else
    {
        strcpy(save_data.filePrefix, "I");
    }
        
    if(data.options.rawMode)
    {
        strcpy(save_data.fileSuffix, "RAW");
    }
    else
    {
        strcpy(save_data.fileSuffix, "YUV");
    }
    
    /* get first available file name */    
    for (start_number = 0 ; start_number < 1000; start_number++)
    {
        snprintf(save_data.fileName, sizeof(save_data.fileName), "%s%07d.%s", save_data.filePrefix, start_number, save_data.fileSuffix);
        
        uint32_t size;
        if( FIO_GetFileSize( save_data.fileName, &size ) != 0 ) break;
        if (size == 0) break;
    }
    
    if(data.options.rawMode)
    {
        /* copy 8 bytes per transfer */
        data.dmaFlags = 0x20001000;

        /* set block size for EDMAC and update cropping */
        save_data.frameSize = (save_data.frameSizeReal + 4095) & (~4095);
        
        /* the data at bottom are trash remains caused by EDMAC block size, drop it */
        save_data.bottomDrop = save_data.frameSize - save_data.frameSizeReal;
        
        /* mem copy connection */
        data.dmaCopyChannel = 0x19;
        data.dmaCopyConn = 0x06;
        data.dmaSourceConn = 0x06;
        data.dmaFlags = 0;
        
        /* create a memory suite that consists of lv_save_raw raw buffer */
        data.memCopySuite = CreateMemorySuite((void*)shamem_read(RAW_LV_EDMAC), save_data.frameSize, 0);
        PackMem_RegisterEDmacCompleteCBRForMemorySuite(data.dmaCopyChannel, &complete_cbr, 0);
        PackMem_RegisterEDmacPopCBRForMemorySuite(data.dmaCopyChannel, &pop_cbr, 0);
    }
    else
    {
        /* copy 2 byte per transfer */
        data.dmaFlags = 0x20000000;
        /* read from YUV connection */
        data.dmaSourceConn = 0x1B;
        
        /* no special treatment, save the exact size */
        save_data.frameSize = save_data.frameSizeReal;
        save_data.bottomDrop = 0;
    }

    /* who wants to save more? */
    data.maxFrames = 200000;
    data.dmaChannel = 0x11;
    data.maxFramesBufferable = allocatedMemory / save_data.frameSize;
    data.frameSize = save_data.frameSize;

    /* EDMAC callbacks */
    PackMem_RegisterEDmacCompleteCBRForMemorySuite(data.dmaChannel, &complete_cbr, 1);
    PackMem_RegisterEDmacPopCBRForMemorySuite(data.dmaChannel, &pop_cbr, 1);
    
    /* this enables recording */
    lv_rec_state = &data;
    
    bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * yPos++, "Ready, waiting for first frame");

    int wait_loops = 0;
    int t0 = get_ms_clock_value();
    while(!data.finished || (lv_rec_ring_mode && (data.capturedFrames > data.savedFrames)))
    {
        if(lv_rec_ring_mode)
        {
            if(data.capturedFrames > data.savedFrames)
            {
                if(data.options.singleFile)
                {
                    if(!save_data.handle)
                    {
                        snprintf(save_data.fileName, sizeof(save_data.fileName), "%s%07d.%s", save_data.filePrefix, start_number, save_data.fileSuffix);
                        bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * (yPos+1), "Saving to '%s'", save_data.fileName);
                        save_data.handle = FIO_CreateFile(save_data.fileName);
                        save_data.handleWritten = 0;
                    }

                    if(save_data.handle)
                    {
                        /* save or skip, depending on skip counter */
                        save_data.handleWritten += lv_rec_save_frame(save_data.handle, &save_data, (data.savedFrames % data.options.frameSkip) != 0);
                    }
                    else
                    {
                        yPos++;
                        bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * yPos++, "Failed to save file");
                        break;
                    }
                    
                    /* when reaching 2GiB, create another file */
                    if(save_data.handleWritten > ((2UL * 1024UL) - 10UL) * 1024UL * 1024UL)
                    {
                        yPos++;
                        bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * yPos++, "Creating next file");
                        FIO_CloseFile(save_data.handle);
                        save_data.handle = NULL;
                        lv_rec_update_suffix(&save_data);
                        save_data.fileSeqNum++;
                    }
                    data.savedFrames++;
                }
                else
                {
                    if((data.savedFrames % data.options.frameSkip) == 0)
                    {
                        snprintf(save_data.fileName, sizeof(save_data.fileName), "%s%07d.%s", save_data.filePrefix, start_number + (data.savedFrames / data.options.frameSkip), save_data.fileSuffix);
                        bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * (yPos+1), "Saving '%s'", save_data.fileName);
                        save_data.handle = FIO_CreateFile(save_data.fileName);
                        save_data.handleWritten = 0;

                        if(save_data.handle)
                        {
                            save_data.handleWritten += lv_rec_save_frame(save_data.handle, &save_data, 0);
                            save_data.frameCount = 1;
                            lv_rec_save_footer(save_data.handle, &save_data);
                            FIO_CloseFile(save_data.handle);
                            save_data.handle = NULL;
                        }
                        else
                        {
                            yPos++;
                            bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * yPos++, "Failed to save file");
                            break;
                        }
                    }
                    else
                    {
                        /* do not save data, just skip buffers */
                        lv_rec_save_frame(save_data.handle, &save_data, 1);
                    }
                    data.savedFrames++;
                }
                
                /* reset timeout counter */
                wait_loops = 0;
            }
            else
            {
                msleep(10);
                if(wait_loops++ > 25)
                {
                    yPos++;
                    bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * yPos++, "No more data, aborting.");
                    lv_rec_state = NULL;
                    PackMem_PopEDmacForMemorySuite(data.dmaChannel);
                    data.finished = 1;
                }
            }
        }
        else
        {
            msleep(200);
        }
        int t1 = get_ms_clock_value();
        int speed = (save_data.handleWritten / 1024) * 10 / (t1 - t0) * 1000 / 1024; // MB/s x10
        bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * yPos, 
            "%s, %d buffered, %d saved, %d.%d MB/s ", 
            (data.finished?"Finished":(data.running?"Recording":"Wait.....")), 
            data.capturedFrames - data.savedFrames, 
            data.savedFrames / data.options.frameSkip,
            speed/10, speed%10
        );
    }
    yPos++;
    
    if(lv_rec_ring_mode)
    {
        if(data.options.singleFile)
        {
            save_data.frameCount = data.capturedFrames;
            lv_rec_save_footer(save_data.handle, &save_data);
            FIO_CloseFile(save_data.handle);
        }
    }
    else
    {
        bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * ++yPos, "Saving");
        if(data.options.singleFile)
        {
            /* save one single file */
            bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * ++yPos, "Saved: 0x%08X", exmem_save_buffer(data.chunkData.memSuite, "DATA.BIN"));
        }
        
    }
    bmp_printf( FONT(FONT_MED, COLOR_WHITE, COLOR_BLACK), 30, 20 * ++yPos, "Recording finished");
    
    shoot_free_suite(data.chunkData.memSuite);
    
    /* the dummy suite that points to lv_save_raw buffer */
    if(data.memCopySuite)
    {
        DeleteMemorySuite(data.memCopySuite);
    }
}
Пример #8
0
int config_save_file(const char *filename)
{
    int count = 0;

    DebugMsg( DM_MAGIC, 3, "%s: saving to %s", __func__, filename );

#define MAX_SIZE 10240
    char* msg = fio_malloc(MAX_SIZE);
    msg[0] = '\0';

    snprintf( msg, MAX_SIZE,
              "# Magic Lantern %s (%s)\n"
              "# Built on %s by %s\n",
              build_version,
              build_id,
              build_date,
              build_user
            );

    struct tm now;
    LoadCalendarFromRTC( &now );

    snprintf(msg + strlen(msg), MAX_SIZE - strlen(msg),
             "# Configuration saved on %04d/%02d/%02d %02d:%02d:%02d\n",
             now.tm_year + 1900,
             now.tm_mon + 1,
             now.tm_mday,
             now.tm_hour,
             now.tm_min,
             now.tm_sec
            );

    for(struct config_var *var = _config_vars_start; var < _config_vars_end ; var++ )
    {
        if (*(int*)var->value == var->default_value)
            continue;

        snprintf(msg + strlen(msg), MAX_SIZE - strlen(msg) - 1,
                 "%s = %d\r\n",
                 var->name,
                 *(int*) var->value
                );

        count++;
    }

    FILE * file = FIO_CreateFile( filename );
    if(!file)
    {
        fio_free(msg);
        return -1;
    }

    FIO_WriteFile(file, msg, strlen(msg));

    FIO_CloseFile( file );

    fio_free(msg);

    return count;
}