static void find_scripts(void) { struct fio_file file; struct fio_dirent * dirent = FIO_FindFirstEx( "ML/SCRIPTS/", &file ); if( IS_ERROR(dirent) ) { NotifyBox(2000, "Scripts dir missing" ); return; } script_cnt = 0; do { if (file.mode & ATTR_DIRECTORY) continue; // is a directory if (is_valid_script_filename(file.name)) { snprintf(script_list[script_cnt++], FILENAME_SIZE, "%s", file.name); if (script_cnt >= MAX_SCRIPT_NUM) { NotifyBox(2000, "Too many scripts" ); break; } } } while( FIO_FindNextEx( dirent, &file ) == 0); FIO_FindClose(dirent); for (int i = 0; i < script_cnt; i++) script_parse_header(i); }
static void autoexpo_task() { autoexpo_running = 1; if(!lens_info.raw_shutter) goto cleanup; //open menus int bv = RAW2TV(lens_info.raw_shutter) + RAW2AV(lens_info.raw_aperture) - RAW2SV(lens_info.iso_equiv_raw) + RAW2EC(get_ae_value()); if(bv < -200){ //AE_VALUE overflows, set some low values lens_set_rawshutter(60 + 56); lens_set_rawaperture(1); lens_set_rawiso(1); NotifyBox(1000, "AE_VALUE overflows"); goto cleanup; } last_bv = bv; exposure expo = get_exposure(bv, 0); lens_set_rawaperture(AV2RAW(expo.av)); lens_set_rawiso(SV2RAW(expo.sv)); lens_set_rawshutter(TV2RAW(expo.tv)); cleanup: autoexpo_running = 0; }
static void movie_rec_halfshutter_step() { if (!movie_rec_key) return; if (!is_movie_mode() || !liveview_display_idle() || gui_menu_shown()) return; if (HALFSHUTTER_PRESSED) { if (movie_rec_key_long) { // need to keep halfshutter pressed for one second for (int i = 0; i < 10; i++) { msleep(100); if (!HALFSHUTTER_PRESSED) break; } if (!HALFSHUTTER_PRESSED) return; info_led_on(); NotifyBox(1000, "OK"); } while (HALFSHUTTER_PRESSED) msleep(50); if (NOT_RECORDING && ALLOW_MOVIE_START) schedule_movie_start(); else if(ALLOW_MOVIE_STOP) schedule_movie_end(); } }
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(); }
static void wait_notify(int seconds, char* msg) { wait_till_next_second(); for (int i = 0; i < seconds; i++) { NotifyBox(2000, "%s: %d...", msg, seconds - i); wait_till_next_second(); } }
static void focus_stack_ensure_preconditions() { while (lens_info.job_state) msleep(100); if (!lv) { while (!lv) { focus_stack_check_stop(); get_out_of_play_mode(500); focus_stack_check_stop(); if (!lv) force_liveview(); if (lv) break; NotifyBoxHide(); NotifyBox(2000, "Please switch to LiveView"); msleep(200); } msleep(200); } if (is_movie_mode()) { #ifdef CONFIG_5D2 set_expsim(1); #else while (is_movie_mode()) { NotifyBox(2000, "Please switch to photo mode"); msleep(2000); } #endif } while (is_manual_focus()) { NotifyBoxHide(); NotifyBox(2000, "Please enable autofocus"); msleep(2000); } msleep(300); if (fstack_zoom > 1) set_lv_zoom(fstack_zoom); }
static void rack_focus_start_delayed( void * priv, int delta ) { if (delta < 0) { if (is_movie_mode()) rack_focus_start_auto_record(priv, delta); else NotifyBox(2000, "Please switch to Movie mode."); return; } focus_rack_auto_record = 0; focus_rack_enable_delay = 1; focus_toggle(priv); }
/* called at startup, after init_func's */ void config_load() { #ifdef CONFIG_CONFIG_FILE config_selected = 1; config_preset_name = config_choose_startup_preset(); if (config_preset_name) { NotifyBox(2000, "Config: %s", config_preset_name); if (!DISPLAY_IS_ON) beep(); } char config_file[0x80]; snprintf(config_file, sizeof(config_file), "%smagic.cfg", get_config_dir()); config_parse_file(config_file); #endif config_ok = 1; }
/* allocate and free memory all the time */ static void mem_chk_flood() { char text_str[32]; uint32_t loops = 0; util_atomic_inc(&mem_chk_threads); while(!mem_chk_abort) { /* try a few large blocks and many small blocks */ uint32_t max_size = rand() % 10 < 2 ? mem_chk_flood_size_large : mem_chk_flood_size_small; uint32_t size = MAX(1, rand() % max_size ); char *buf = NULL; loops++; snprintf(text_str, sizeof(text_str), "check: %d", loops); mem_chk_flood_state = text_str; buf = malloc(size); if(!buf) { util_atomic_inc(&mem_chk_errors); NotifyBox(20000, "Memory allocation error"); mem_chk_flood_state = "alloc error"; beep(); break; } atomic_add(&mem_chk_allocated, size); msleep(rand() % 250); free(buf); atomic_add(&mem_chk_allocated, -size); msleep(rand() % 50); } mem_chk_flood_state = "finished"; util_atomic_dec(&mem_chk_threads); }
static void focus_stack( int count, int num_steps, int skip_frame, // skip first frame for stack or original frame for bracket int pre_focus, // zoom to start position and then only go in one direction int is_bracket // perform dumb bracketing if no range is set via follow focus ) { focus_stack_should_stop = 0; int delay = 0; if (drive_mode == DRIVE_SELFTIMER_2SEC) delay = 2; else if (drive_mode == DRIVE_SELFTIMER_REMOTE) delay = 10; if (delay) wait_notify(delay, "Focus stack"); if (focus_stack_check_stop()) return; NotifyBox(1000, "Focus stack: %dx%d", count, ABS(num_steps) ); msleep(1000); int prev_drive_mode = set_drive_single(); int f0 = hdr_script_get_first_file_number(skip_frame); fstack_zoom = lv_dispsize; // if we start the focus stack zoomed in, keep this zoom level throughout the operation int focus_moved_total = 0; if (pre_focus) { NotifyBox(1000, "Pre-focusing %d steps...", ABS(num_steps*pre_focus) ); focus_stack_ensure_preconditions(); if (LensFocus(-num_steps*pre_focus) == 0) { beep(); return; } focus_moved_total -= (num_steps*pre_focus); } int i, real_steps; for( i=0 ; i < count ; i++ ) { if (focus_stack_check_stop()) break; NotifyBox(1000, "Focus stack: %d of %d", i+1, count ); focus_stack_ensure_preconditions(); if (focus_stack_check_stop()) break; if (gui_menu_shown() || CURRENT_DIALOG_MAYBE == 2) break; // menu open? stop here if (!( (!is_bracket && skip_frame && (i == 0)) || // first frame in SNAP-stack (is_bracket && (skip_frame == 1) && (i == 0)) || // first frame in SNAP-bracket (is_bracket && (skip_frame == count) && (i == count-1)) // last frame in SNAP-bracket )) { hdr_shot(0,1); msleep(300); } if( count-1 == i ) break; focus_stack_ensure_preconditions(); if (focus_stack_check_stop()) break; // skip orginal frame on SNAP-bracket (but dont double-focus if last frame) if (is_bracket && skip_frame && (skip_frame == i+2) && (skip_frame != count)) { real_steps = num_steps*2; i++; } else { real_steps = num_steps; } NotifyBox(1000, "Focusing %d steps...", ABS(real_steps)); msleep(500); if (LensFocus(real_steps) == 0) break; focus_moved_total += real_steps; } msleep(1000); NotifyBoxHide(); // Restore to the starting focus position if (focus_moved_total) { NotifyBox(1000, "Reversing %d steps...", ABS(focus_moved_total)); msleep(500); focus_stack_ensure_preconditions(); LensFocus(-focus_moved_total); NotifyBoxHide(); } if (i >= count-1) { NotifyBox(2000, "Focus stack done!" ); msleep(1000); hdr_create_script(f0, 1); } else { NotifyBox(2000, "Focus stack not completed"); } if (prev_drive_mode != -1) lens_set_drivemode(prev_drive_mode); }
/* allocate a buffer and check if its content is changing */ static void mem_chk_persist() { char text_str[32]; char *buf = NULL; util_atomic_inc(&mem_chk_threads); mem_chk_persist_state = "malloc"; buf = malloc(mem_chk_persist_size); if(buf) { uint32_t pos = 0; uint32_t byte_offset = 0; uint32_t cur_blockpos = 0; atomic_add(&mem_chk_allocated, mem_chk_persist_size); mem_chk_persist_state = "memset..."; for(pos = 0; pos < mem_chk_persist_size; pos += 8) { ((uint64_t *)buf)[pos / 8] = 0x5555555555555555ULL; } mem_chk_persist_state = "checking..."; while(!mem_chk_abort) { snprintf(text_str, sizeof(text_str), "check: %d/%d", cur_blockpos / mem_chk_persist_blocksize, mem_chk_persist_size / mem_chk_persist_blocksize); mem_chk_persist_state = text_str; for(pos = 0; pos < mem_chk_persist_blocksize - 16; pos += 16) { if(buf[cur_blockpos + pos + byte_offset] != 0x55) { util_atomic_inc(&mem_chk_errors); NotifyBox(20000, "Memory content changed unexpectedly"); mem_chk_persist_state = "CHANGED"; beep(); break; } } cur_blockpos += mem_chk_persist_blocksize; cur_blockpos %= mem_chk_persist_size; /* one byte offset after every block */ if(!cur_blockpos) { byte_offset++; byte_offset %= 16; } msleep(250); } mem_chk_persist_state = "finished"; } else { mem_chk_persist_state = "alloc error"; util_atomic_inc(&mem_chk_errors); NotifyBox(20000, "Failed to allocate memory"); beep(); } free(buf); atomic_add(&mem_chk_allocated, -mem_chk_persist_size); util_atomic_dec(&mem_chk_threads); }