Changeset 607 for trunk/core/luascript.c


Ignore:
Timestamp:
11/30/08 10:40:36 (4 years ago)
Author:
reyalp
Message:

+ add lua functions for flash parameters (onboard flash memory, not light)

num=get_flash_params_count() -- num is the number of parameters
str,num=get_parameter_data(id) -- str is the parameter value as a lua string,

which may contain embedded NULLs or other non-printable characters. If the size of the flash parameter is 4 bytes or less, a second value is returned, containing the parameter value as a number if the parameter id is invalid, or the parameter size is 0, then nil is returned.

scripts/examples/paramdmp.lua contains an example

  • added CAMERA_HAS_JOGDAIL for g7/g9/sx100is, and used it instead of checking individual camera defines
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/luascript.c

    r606 r607  
    201201} 
    202202 
     203static int luaCB_get_parameter_data( lua_State* L ) 
     204{ 
     205  extern long* FlashParamsTable[];  
     206 
     207  unsigned size; 
     208  unsigned id = luaL_checknumber( L, 1 ); 
     209  unsigned val; 
     210 
     211  if (id >= get_flash_params_count()) { 
     212    // return nil 
     213    return 0; 
     214  } 
     215 
     216  size = FlashParamsTable[id][1]>>16; 
     217  if (size == 0) { 
     218    // return nil 
     219    return 0; 
     220  } 
     221  if (size >= 1 && size <= 4) { 
     222    val = 0; 
     223    get_parameter_data( id, &val, size ); 
     224    lua_pushlstring( L, (char *)&val, size ); 
     225    // for convenience, params that fit in a number are returned in one as a second result 
     226    lua_pushnumber( L, val ); 
     227    return 2; 
     228  } 
     229  else { 
     230    char *buf = malloc(size); 
     231    if(!buf) { 
     232      luaL_error( L, "malloc failed in luaCB_get_parameter_data" ); 
     233    } 
     234    get_parameter_data( id, buf, size ); 
     235    lua_pushlstring( L, buf, size ); 
     236    free(buf); 
     237    return 1; 
     238  } 
     239} 
     240 
     241static int luaCB_get_flash_params_count( lua_State* L ) 
     242{ 
     243  lua_pushnumber( L, get_flash_params_count() ); 
     244  return 1; 
     245} 
     246 
    203247static int luaCB_set_av96_direct( lua_State* L ) 
    204248{ 
     
    383427} 
    384428 
    385 #if defined (CAMERA_g7) || defined (CAMERA_sx100is) || defined (CAMERA_g9) 
     429#if CAM_HAS_JOGDIAL 
    386430static int luaCB_wheel_right( lua_State* L ) 
    387431{ 
     
    857901  FUNC(get_zoom); 
    858902  FUNC(get_exp_count); 
     903  FUNC(get_flash_params_count); 
     904  FUNC(get_parameter_data); 
    859905 
    860906  FUNC(set_av96_direct); 
     
    884930  FUNC(is_pressed); 
    885931  FUNC(is_key); 
    886 #if defined (CAMERA_g7) || defined (CAMERA_sx100is) 
     932#ifdef CAM_HAS_JOGDIAL 
    887933  FUNC(wheel_right); 
    888934  FUNC(wheel_left); 
Note: See TracChangeset for help on using the changeset viewer.