Example #1
0
int snapshot_write(char *name) {
	const int version = SETTINGS_VERSION;

	int  result = FALSE;
	int  file   = -1;

	snapshot_t buffer = {
		DPData     : DPData,
		settings   : settings,
		menu_order : menu_order,
	};

	if ((file = FIO_OpenFile(name, O_CREAT | O_WRONLY , 644)) == -1)
		goto end;

	if (FIO_WriteFile(file, (void*)&version, sizeof(version)) != sizeof(version))
		goto end;

	if (FIO_WriteFile(file, (void*)&buffer, sizeof(buffer)) != sizeof(buffer))
		goto end;

	if (FIO_CloseFile(file) == -1)
		goto end;

	result = TRUE;

end:
	if (file != -1)
		FIO_CloseFile(file);

	return result;
}
Example #2
0
void cmodes_write() {
	const int version = SNAPSHOT_VERSION;
	int file = -1;

	if ((file = FIO_OpenFile(MKPATH_NEW(CMODES_CONFIG), O_CREAT | O_WRONLY)) == -1)
		if (status.folder_exists || (file = FIO_OpenFile(MKPATH_OLD(CMODES_CONFIG), O_CREAT | O_WRONLY)) == -1)
			goto end;

	FIO_WriteFile(file, (void*)&version,        sizeof(version));
	FIO_WriteFile(file, (void*)&cmodes_config, sizeof(cmodes_config));
	FIO_CloseFile(file);

end:
	if (file != -1)
		FIO_CloseFile(file);
}
Example #3
0
void save_log()
{
    NotifyBox(1000, "%d ", strlen(log));
    FILE* f = FIO_CreateFileEx(CARD_DRIVE"shoot.log");
    FIO_WriteFile(f, UNCACHEABLE(log), strlen(log));
    FIO_CloseFile(f);
    beep();
}
Example #4
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);
    }
}
Example #5
0
void console_hide()
{
    console_visible = 0;
    msleep(100);
    canon_gui_enable_front_buffer(1);

    #ifdef CONSOLE_DEBUG
    FIO_CloseFile(console_log_file);
    console_log_file = 0;
    #endif
}
Example #6
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);
	}
}
Example #7
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;
}
Example #8
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);
}
Example #9
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);
}
Example #10
0
File: utils.c Project: AEUG/400plus
void dump_memory() {
	char filename[20] = "A:/12345678.MEM";
	time_t t;
	struct tm tm;

	time(&t);
	localtime_r(&t, &tm);

	sprintf(filename, "A:/%02d%02d%02d%02d.MEM", tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);

	debug_log("Dumping memory to %s.\n", filename);
	int file = FIO_OpenFile(filename, O_CREAT | O_WRONLY , 644);

	if (file == -1) {
		debug_log("ERROR: can't open file for writing (%s)", filename);
		beep();
		beep();
	} else {
		int addr=0;
		int power_off_state = DPData.auto_power_off;

		send_to_intercom(IC_SET_AUTO_POWER_OFF, false);

		while (addr<0x800000) { // dump 8MB of RAM
			char buf[0x800];
			// i don't know why, but if we try to pass the mem address (addr) directly to
			// FIO_WriteFile, we get zero-filled file... so we need local buffer as a proxy
			// note: do not increase the size of the local buffer too much, because it is in the stack
			LEDBLUE ^= 2;
			memcpy(buf, (void*)addr, 0x800);
			FIO_WriteFile(file, buf, 0x800);
			addr += 0x800;
		}
		FIO_CloseFile(file);

		send_to_intercom(IC_SET_AUTO_POWER_OFF, power_off_state);
	}
	beep();
}
Example #11
0
int snapshot_read(char *name, snapshot_t *snapshot) {
	int result  = FALSE;
	int file    = -1;
	int version =  0;

	snapshot_t buffer;

	if ((file = FIO_OpenFile(name, O_RDONLY, 644)) == -1)
		goto end;

	if (FIO_ReadFile(file, &version, sizeof(version)) != sizeof(version))
		goto end;

	if (version != SETTINGS_VERSION)
		goto end;

	if (FIO_ReadFile(file, &buffer, sizeof(buffer)) != sizeof(buffer))
		goto end;

	*snapshot = buffer;

	result = TRUE;

#if SETTINGS_VERSION == 0x4A
	int nt;
	// Temporal fix for those affected by issue #333
	// Remove after increasing the version of the settings file
	if (snapshot->menu_order.named_temps[0] == 0 && snapshot->menu_order.named_temps[1] == 0)
		for (nt = 0; nt < LENGTH(snapshot->menu_order.named_temps); nt++)
			snapshot->menu_order.named_temps[nt] = nt;
#endif

end:
	if (file != -1)
		FIO_CloseFile(file);

	return result;
}
Example #12
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);
        }
    }
}
Example #13
0
void cmodes_read() {
	int   id;
	int   version =  0;
	int file    = -1;

	cmodes_config_t buffer;

	for (id = 0; id < CMODES_MAX; id ++) {
		sprintf(cmodes_default.names[id], "%s %X", LP_WORD(L_S_CMODE_NAME), id);
		cmodes_default.order[id] = id;
	}

	for (id = 0; id < CMODES_MODES; id ++) {
		cmodes_default.assign[id] = CMODE_NONE;
	}

	cmodes_config = cmodes_default;

	if ((file = FIO_OpenFile(MKPATH_NEW(CMODES_CONFIG), O_RDONLY)) == -1)
		if ((file = FIO_OpenFile(MKPATH_OLD(CMODES_CONFIG), O_RDONLY)) == -1)
			goto end;

	if (FIO_ReadFile(file, &version, sizeof(version)) != sizeof(version))
		goto end;

	if (version != SNAPSHOT_VERSION)
		goto end;

	if (FIO_ReadFile(file, &buffer, sizeof(buffer)) != sizeof(buffer))
		goto end;

	cmodes_config = buffer;

end:
	if (file != -1)
		FIO_CloseFile(file);
}
Example #14
0
void start_up() {
	// Check and create our 400PLUS folder
	status.folder_exists = check_create_folder();

	// Recover persisting information
	persist_read();

	// Read settings from file
	settings_read();

	// If configured, start debug mode
	if (settings.debug_on_poweron)
		start_debug_mode();

	// If configured, restore AEB
	if (settings.persist_aeb)
		send_to_intercom(IC_SET_AE_BKT, persist.aeb);

	// Enable IR remote
	// i'm not sure where to call this? perhaps this isn't the right place.
	if (settings.remote_enable)
		remote_on();

	// Enable extended ISOs
	// Enable (hidden) CFn.8 for ISO H
	send_to_intercom(IC_SET_CF_EXTEND_ISO, 1);

	// Enable realtime ISO change
	send_to_intercom(IC_SET_REALTIME_ISO_0, 0);
	send_to_intercom(IC_SET_REALTIME_ISO_1, 0);

	// Set current language
	enqueue_action(lang_pack_init);

	// Read custom modes configuration from file
	enqueue_action(cmodes_read);

	// And optionally apply a custom mode
	enqueue_action(cmode_recall);

    // turn off the blue led after it was lighten by our hack_task_MainCtrl()
	eventproc_EdLedOff();

#ifdef MEMSPY
	debug_log("starting memspy task");
	CreateTask("memspy", 0x1e, 0x1000, memspy_task, 0);
#endif

#if 0
	debug_log("=== DUMPING DDD ===");
	printf_DDD_log( (void*)(int)(0x00007604+0x38) );

	debug_log("maindlg @ 0x%08X, handler @ 0x%08X", hMainDialog, hMainDialog->event_handler);

	debug_log("dumping");
	long *addr   = (long*) 0x7F0000;

	int file = FIO_OpenFile("A:/dump.bin", O_CREAT | O_WRONLY , 644);

	if (file != -1) {
		FIO_WriteFile(file, addr, 0xFFFF);
		FIO_CloseFile(file);
		beep();
	}
#endif
}
Example #15
0
static int script_load_symbols(void* tcc, void* script_state, char *filename)
{
    uint32_t size = 0;
    FILE* file = NULL;
    char *buf = NULL;
    uint32_t count = 0;
    uint32_t pos = 0;

    if( FIO_GetFileSize( filename, &size ) != 0 )
    {
        console_printf("Error loading '%s': File does not exist\n", filename);
        return -1;
    }
    buf = fio_malloc(size);
    if(!buf)
    {
        console_printf("Error loading '%s': File too large\n", filename);
        return -1;
    }

    file = FIO_OpenFile(filename, O_RDONLY | O_SYNC);
    if(!file)
    {
        console_printf("Error loading '%s': File does not exist\n", filename);
        fio_free(buf);
        return -1;
    }
    FIO_ReadFile(file, buf, size);
    FIO_CloseFile(file);

    while(buf[pos])
    {
        char address_buf[16];
        char symbol_buf[128];
        uint32_t length = 0;
        uint32_t address = 0;

        while(buf[pos + length] && buf[pos + length] != ' ' && length < sizeof(address_buf))
        {
            address_buf[length] = buf[pos + length];
            length++;
        }
        address_buf[length] = '\000';

        pos += length + 1;
        length = 0;

        while(buf[pos + length] && buf[pos + length] != '\r' && buf[pos + length] != '\n' && length < sizeof(symbol_buf))
        {
            symbol_buf[length] = buf[pos + length];
            length++;
        }
        symbol_buf[length] = '\000';

        pos += length + 1;
        length = 0;

        while(buf[pos + length] && (buf[pos + length] == '\r' || buf[pos + length] == '\n'))
        {
            pos++;
        }
        sscanf(address_buf, "%x", &address);

        module_exec(tcc, "tcc_add_symbol", 3, script_state, symbol_buf, (void*)address);
        count++;
    }

    /* ToDo: parse the old plugin sections as all needed OS stubs are already described there */
    module_exec(tcc, "tcc_add_symbol", 3, script_state, "strcpy", &strcpy);
    module_exec(tcc, "tcc_add_symbol", 3, script_state, "strlen", &strlen);

    fio_free(buf);
    return 0;
}
Example #16
0
static int dng_show(char* filename)
{
    uint32_t size;
    if( FIO_GetFileSize( filename, &size ) != 0 ) return 0;

    FILE* f = FIO_OpenFile(filename, O_RDONLY | O_SYNC);
    void* buf = 0;

    /* should be big enough for the header */
    int header_maxsize = 65536;
    int* header = fio_malloc(header_maxsize);
    if (!header) return 0;

    int rc = FIO_ReadFile(f, header, header_maxsize);
    if( rc != header_maxsize ) goto err;

    if (header[0] != 0x002A4949 && header[1] != 0x00000008)
    {
        bmp_printf(FONT_MED, 0, 0, "Not a CHDK DNG");
        goto err;
    }

    raw_info.width = 0;
    raw_info.height = 0;
    
    int strip_offset = 0;

    int off = 8;
    for (int ifd = 0; off; ifd++)
        off = tif_parse_ifd(ifd, (void*)header, off, &strip_offset);

    fio_free(header); header = 0;

    if (!strip_offset) goto err;
    if (!raw_info.width) goto err;
    if (!raw_info.height) goto err;

    int raw_size = raw_info.width * raw_info.height * 14/8;
    buf = fio_malloc(raw_size);
    if (!buf) goto err;
    
    FIO_SeekSkipFile(f, strip_offset, SEEK_SET);
    rc = FIO_ReadFile(f, buf, raw_size);
    if (rc != raw_size) goto err;
    FIO_CloseFile(f); f = 0;

    info_led_on();
    /* fixme: this step is really slow */
    reverse_bytes_order(buf, raw_size);
    info_led_off();
    raw_info.buffer = buf;

    raw_set_geometry(raw_info.width, raw_info.height, raw_info.active_area.x1, raw_info.width - raw_info.active_area.x2, raw_info.active_area.y1, raw_info.height - raw_info.active_area.y2);
    raw_force_aspect_ratio_1to1();

    vram_clear_lv();
    raw_preview_fast_ex((void*)-1, (void*)-1, -1, -1, RAW_PREVIEW_COLOR_HALFRES);
    fio_free(buf); buf = 0;
    raw_set_dirty();
    
    bmp_printf(FONT_MED, 600, 460, " %dx%d ", raw_info.jpeg.width, raw_info.jpeg.height);
    return 1;
err:
    if (f) FIO_CloseFile(f);
    if (header) fio_free(header);
    if (buf) fio_free(buf);
    raw_set_dirty();
    return 0;
}
Example #17
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%s%07d.%s", MODULE_CARD_DRIVE, 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%s%07d.%s", MODULE_CARD_DRIVE, 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_CreateFileEx(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%s%07d.%s", MODULE_CARD_DRIVE, 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_CreateFileEx(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);
    }
}
Example #18
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;
}