CHDK Wiki
No edit summary
Line 368: Line 368:
 
: 0 = AF not locked, 1 = AF locked
 
: 0 = AF not locked, 1 = AF locked
 
PROPCASE_CONTINUOUS_AF
 
PROPCASE_CONTINUOUS_AF
  +
 
PROPCASE_SERVO_AF
 
PROPCASE_SERVO_AF

Revision as of 01:04, 31 December 2013

CHDK set_focus() Mode Compatability Chart
Camera set_focus() only set_aflock() PressSw1AndMF SS.MFOn Notes
A540 Y Y Y
A720 Y Y Y
A1200 N Y N
D10 Y Y Y
G10 Y Y Y
IXUS120_SD940 Y Y Y
IXUS140HS_ELPH130 N* Y N * crash
SX220HS N N Y
SX230HS N N Y
SX50 N N N Y



CAM_CAN_SD_OVERRIDE 1 // Camera allows to do subject distance override

in gui.c :
   enables SD bracketing menu & submenu item
   enables SD override menu & submenu items
   changes debugging shortcuts if cam does not have an erase button
in shooting.c 
   shooting_can_focus() , shooting_get_common_focus_mode()
in gui_osd.c
    enables SD override shortcuts if cam does not have MF

CAM_CAN_SD_OVER_NOT_IN_MF 1 // Camera allows subject distance (focus) override when not in manual focus mode

in shooting.c 
   shooting_can_focus()

CAM_CAN_SD_OVER_IN_AF_LOCK // Camera allows subject distance (focus) override when in AF Lock mode

                                           // exact meaning: SD override works in AF lock or movie mode
in shooting.c 
   shooting_can_focus()

CAM_CAN_SD_OVER_IN_AF_LOCK_ONLY // Camera allows subject distance (focus) override only when in AF Lock mode OR in movie mode

in shooting.c 
   shooting_can_focus()

CAM_HAS_MANUAL_FOCUS 1 // Camera has manual focus mode

in gui_osd.c
   enables SD shortcuts if cam does not have MF
in gui.c
   enables short cut display in alt help screen
   enables shortcut key detection in gui_chdk_kbd_process()
in shooting.c
   shooting_get_common_focus_mode() :
in camera_info.c camera_info.h
   sets manual focus to 1 in the camera_info structure (0 by default)
in luascript.c  ubasic.c
   in luaCB_set_focus() via camera_info setting

.

// Focus mode   (0=Auto, 1=macro,  2=portrait, 3=Infinity, 4=MF 5=super macro)
short shooting_get_focus_mode() { return shooting_get_prop(PROPCASE_FOCUS_MODE); }

.

short shooting_get_common_focus_mode()
{
   #if !CAM_HAS_MANUAL_FOCUS && CAM_CAN_SD_OVERRIDE
       return conf.subj_dist_override_koef;
   #elif !CAM_CAN_SD_OVERRIDE
       return 0;
   #else
       return shooting_get_focus_mode();
   #endif
}

.

short shooting_can_focus()
{
   #if !CAM_CAN_SD_OVER_NOT_IN_MF && CAM_CAN_SD_OVERRIDE
       #if CAM_CAN_SD_OVER_IN_AF_LOCK_ONLY
           if (shooting_get_prop(PROPCASE_AF_LOCK))
               return 1;
           else if (!camera_info.state.mode_video)
               return 0;
       #elif CAM_CAN_SD_OVER_IN_AF_LOCK
           if (shooting_get_prop(PROPCASE_AF_LOCK))
               return 1;
       #elif CAM_HAS_VIDEO_BUTTON
           return shooting_get_common_focus_mode();
       #endif
       return (shooting_get_common_focus_mode() || camera_info.state.mode_video);
   #elif !CAM_CAN_SD_OVERRIDE
       return camera_info.state.mode_video;
   #elif defined (CAMERA_ixus800_sd700)
       // TODO whats the reason for this ?!?
       return (shooting_get_zoom()<8) && (camera_info.state.mode_shooting!=MODE_AUTO) && (camera_info.state.mode_shooting!=MODE_SCN_UNDERWATER);
   #else
       #ifdef PROPCASE_CONTINUOUS_AF
       if (shooting_get_prop(PROPCASE_CONTINUOUS_AF))
           return 0;
       #endif
       #ifdef PROPCASE_SERVO_AF
       if (shooting_get_prop(PROPCASE_SERVO_AF))
           return 0;
       #endif
       return 1;
   #endif
   }

.

void shooting_set_focus(int v, short is_now)
{
   int s=v;
   if (!camera_info.state.mode_play)
   {
       if ((is_now) && shooting_can_focus())
       {
           if (conf.dof_subj_dist_as_near_limit)
           {
               s=shooting_get_near_limit_f(v,shooting_get_min_real_aperture(),get_focal_length(lens_get_zoom_point()));
           }
           if (!conf.dof_use_exif_subj_dist && (s != INFINITY_DIST))
               s+=shooting_get_lens_to_focal_plane_width();
           lens_set_focus_pos(s);
       }
       else
           photo_param_put_off.subj_dist=v;
   }
}

.

void lens_set_focus_pos(long newpos)
{
   if (newpos >= MAX_DIST) newpos = INFINITY_DIST; // Set to infinity value that will work on all cameras
   _MoveFocusLensToDistance((short*)&newpos);
   while ((shooting_is_flash_ready()!=1) || (focus_busy)) msleep(10);
   newpos = _GetFocusLensSubjectDistance();
   _SetPropertyCase(PROPCASE_SUBJECT_DIST1, &newpos, sizeof(newpos));
   _SetPropertyCase(PROPCASE_SUBJECT_DIST2, &newpos, sizeof(newpos));
}

.

static int luaCB_set_focus( lua_State* L )
{
   int to = luaL_checknumber( L, 1 );
   if (camera_info.cam_has_manual_focus)
   {
       if (shooting_get_focus_mode() || camera_info.state.mode_video) shooting_set_focus(to, SET_NOW);
       else shooting_set_focus(to, SET_LATER);
   }
   else
   {
       if (shooting_get_common_focus_mode() || camera_info.state.mode_video) shooting_set_focus(to, SET_NOW);
       else shooting_set_focus(to, SET_LATER);
   }
 return 0;
}

.

static void set_focus_statement()
{
   int to;
   accept(TOKENIZER_SET_FOCUS);
   to = expr();
   if (camera_info.cam_has_manual_focus)
   {
       if (shooting_get_focus_mode() || (camera_info.state.mode_video)) shooting_set_focus(to, SET_NOW);
       else shooting_set_focus(to, SET_LATER);
   }
   else
   {
       if (camera_info.state.mode_video) shooting_set_focus(to, SET_NOW);
       else shooting_set_focus(to, SET_LATER);
   }
   accept_cr();
}

.

Propcases

PROPCASE_FOCUS_STATE

Auto-Focus state (0 = unfocussed, 1 = focussed)
Auto-Focus state after half-press (stays 1 if shoot_half is released!) (0 orange, >=1 green, with AiAF=off only 0 or 1, with enabled AiAF or Face the value depends on position & number of AF boxes)

PROPCASE_FOCUS_MODE

(0=AUTO 1=MF)

PROPCASE_REAL_FOCUS_MODE

(0=Auto, 1=macro, 2=portrait, 3=Infinity, 4=MF 5=super macro)

PROPCASE_AF_LOCK

0 = AF not locked, 1 = AF locked

PROPCASE_CONTINUOUS_AF

PROPCASE_SERVO_AF