Exemplo n.º 1
0
/*
status = write_usb_msg(msg,[timeout])
writes a message to the CHDK ptp interface
msg may be nil, boolean, number, string or table (table has some restrictions, will be converted to string)
returns true if the message was queued successfully, otherwise false
if timeout is set and not zero, wait until message is written or timeout expires
NOTE strings will not include a terminating NULL, must be handled by recipient
*/
static int luaCB_write_usb_msg( lua_State* L )
{
    ptp_script_msg *msg;
    int timeout = luaL_optnumber( L, 2, 0 );
    // TODO would it be better to either ignore this or return nil ?
    // a write_usb_msg(function_which_returns_no_value()) is an error in this case
    // replacing with nil might be more luaish
    if(lua_gettop(L) < 1) {
        return luaL_error(L,"missing argument");
    }
    msg=lua_create_usb_msg(L,1,PTP_CHDK_S_MSGTYPE_USER);
    // for user messages, trying to create a message from an incompatible type throws an error
    if(msg->subtype == PTP_CHDK_TYPE_UNSUPPORTED) {
        free(msg);
        return luaL_error(L,"unsupported type");
    }
    if(!msg) {
        return luaL_error(L,"failed to create message");
    }
    if(timeout) {
        action_push(timeout);
        action_push((int)msg);
        action_push(AS_SCRIPT_WRITE_USB_MSG);
        return lua_yield( L, 0 );
    }
    lua_pushboolean(L,ptp_script_write_msg(msg));
    return 1;
}
Exemplo n.º 2
0
// Push the core 'shoot' actions onto the stack
// Note: action stack actions are processed in reverse order
void action_push_shoot(int retry)
{
    // Init shooting state
    camera_info.state.state_shooting_progress = SHOOTING_PROGRESS_NONE;

    // Wait for camera ready to shoot or timeout
    action_push(retry);
    action_push(get_tick_count() + 5000);
    action_push_func(action_stack_AS_WAIT_SHOOTING_IN_PROGRESS);

    // Half press shutter
    action_push_press(KEY_SHOOT_HALF);
}
Exemplo n.º 3
0
/*
msg = read_usb_msg([timeout])
read a message from the CHDK ptp interface.
Returns the next available message as a string, or nil if no messages are available
If timeout is given and not zero, wait until a message is available or timeout expires
*/
static int luaCB_read_usb_msg( lua_State* L )
{
    int timeout = luaL_optnumber( L, 1, 0 );
    if(timeout) {
        action_push(timeout);
        action_push(AS_SCRIPT_READ_USB_MSG);
        return lua_yield( L, 0 );
    }
    ptp_script_msg *msg = ptp_script_read_msg();
    if(msg) {
        lua_pushlstring(L,msg->data,msg->size);
        return 1;
    }
    lua_pushnil(L);
    return 1;
}
Exemplo n.º 4
0
// Push a button release action onto the stack
// Can only be called from an action stack
void action_push_release(long key)
{
    // WARNING stack program flow is reversed
    action_push_delay(camera_info.cam_key_release_delay);
    action_push(key);
    action_push_func(action_stack_AS_RELEASE);
}
Exemplo n.º 5
0
// Push a button press action onto the stack
// Can only be called from an action stack
void action_push_press(long key)
{
    // WARNING stack program flow is reversed
    action_push_delay(camera_info.cam_key_press_delay);
    action_push(key);
    action_push_func(action_stack_AS_PRESS);
}
Exemplo n.º 6
0
static void md_kbd_sched_immediate_shoot(int no_release)
{
    action_pop();// REMOVE MD ITEM
  
    // stack operations are reversed!
    if (!no_release)  // only release shutter if allowed
    {
      action_push_release(KEY_SHOOT_FULL);
      action_push_delay(20);
    }
    action_push(AS_MOTION_DETECTOR); // it will removed right after exit from this function
    kbd_key_press(KEY_SHOOT_FULL); // not a stack operation... pressing right now
}
Exemplo n.º 7
0
OPENVPN_EXPORT void
openvpn_plugin_close_v1 (openvpn_plugin_handle_t handle)
{
  ldap_context_t *context = (ldap_context_t *) handle;
  action_t *action = action_new( );

  if (DOINFO (context->verb))
    LOGINFO( "%s() called", __FUNCTION__ );
  if( action){
    action->type = LDAP_AUTH_ACTION_QUIT;
    action_push( context->action_list, action );
    if( DODEBUG( context->verb ) )
      LOGDEBUG ("Waiting for thread to return");
    pthread_join( action_thread, NULL );
    if( DODEBUG( context->verb ) )
      LOGDEBUG ("Thread returned queries left in queue: %d", list_length( context->action_list ));
    pthread_attr_destroy( &action_thread_attr );
    pthread_mutex_destroy( &action_mutex );
    pthread_cond_destroy( &action_cond );
  }
  ldap_context_free( context );
  //pthread_exit(NULL);
}
Exemplo n.º 8
0
// Action stack function - wait for camera ready to shoot after half press, or timeout
// parameters - timeout delay, retry flag
static int action_stack_AS_WAIT_SHOOTING_IN_PROGRESS()
{
    // Get parameters
    int timeout = action_top(2);
    int retry = action_top(3);

    if (shooting_in_progress() || camera_info.state.mode_video)
    {
        // Remove this action from the stack
        action_pop_func(2);

        // Push the rest of the shoot actions onto the stack (reversed flow)

        // Push 'retry if failed' parameter for exit action
        action_push(retry);
        action_push_func(action_stack_AS_WAIT_SHOOTING_DONE);

        // Full press shutter
        action_push_click(KEY_SHOOT_FULL);

        // Wait for flash recharged
        action_push_func(action_stack_AS_WAIT_FLASH);

        return 1;
    }
    if (get_tick_count() >= timeout)
    {
        // Remove this action from the stack
        action_pop_func(2);

        // Return 'shoot' status to script - 1 = shutter half press timed out
        libscriptapi->set_as_ret(1);

        return 1;
    }
    return 0;
}
Exemplo n.º 9
0
OPENVPN_EXPORT int
openvpn_plugin_func_v2 (openvpn_plugin_handle_t handle,
                        const int type,
                        const char *argv[],
                        const char *envp[],
                        void *per_client_context,
                        struct openvpn_plugin_string_list **return_list)
{
  ldap_context_t *context = (ldap_context_t *) handle;
  auth_context_t *auth_context = NULL;
  action_t *action = NULL;


  int res = OPENVPN_PLUGIN_FUNC_ERROR;

  if (type == OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY){
    /* get username/password/auth_control_file from envp string array */
    const char *username = get_env ("username", envp);
    const char *password = get_env ("password", envp);
    const char *auth_control_file = get_env ( "auth_control_file", envp );
    const char *pf_file = get_env ("pf_file", envp);



    /* required parameters check */
    if (!username){
      LOGERROR("No username supplied to OpenVPN plugin");
      return OPENVPN_PLUGIN_FUNC_ERROR;
    }

    auth_context = auth_context_new( );
    if( !auth_context ){
      LOGERROR( "Could not allocate auth_context before calling thread" );
      return res;
    }
    if( username ) auth_context->username = strdup( username );
    if( password ) auth_context->password = strdup( password );
    if( pf_file ) auth_context->pf_file = strdup( pf_file );
    if( auth_control_file ) auth_context->auth_control_file = strdup( auth_control_file );
    /* If some argument were missing or could not be duplicate */
    if( !(auth_context->username && auth_context->password && auth_context->auth_control_file ) ){
      auth_context_free( auth_context );
      return res;
    }
    action = action_new( );
    action->type = LDAP_AUTH_ACTION_AUTH;
    action->context = auth_context;
    action->client_context = per_client_context;
    action->context_free_func = (void *)auth_context_free;
    action_push( context->action_list, action );
    return OPENVPN_PLUGIN_FUNC_DEFERRED;
  }
  else if (type == OPENVPN_PLUGIN_ENABLE_PF){
    /* unfortunately, at this stage we dont know anything about the client
     * yet. Let assume it is enabled, we will define default somewhere
     */
    return OPENVPN_PLUGIN_FUNC_SUCCESS;
  }else if( type == OPENVPN_PLUGIN_CLIENT_CONNECT_V2 ){
    /* on client connect, we return conf options through return list
     */
    const char *username = get_env ("username", envp);
    client_context_t *cc = per_client_context;
    char *ccd_options = NULL;
    /* sanity check */
    if (!username){
      LOGERROR("No username supplied to OpenVPN plugin");
      return OPENVPN_PLUGIN_FUNC_ERROR;
    }
    if (!cc || !cc->profile){
      LOGERROR("No profile found for user");
      return OPENVPN_PLUGIN_FUNC_ERROR;
    }
#ifdef ENABLE_LDAPUSERCONF
    ccd_options = ldap_account_get_options_to_string( cc->ldap_account );
#endif
    if( cc->profile->redirect_gateway_prefix && strlen( cc->profile->redirect_gateway_prefix ) > 0 ){
      /* do the username start with prefix? */
      if( strncmp( cc->profile->redirect_gateway_prefix, username, strlen( cc->profile->redirect_gateway_prefix ) ) == 0 ){
        char *tmp_ccd = ccd_options;
        ccd_options = strdupf("push \"redirect-gateway %s\"\n%s",
                            cc->profile->redirect_gateway_flags ? cc->profile->redirect_gateway_flags : DFT_REDIRECT_GATEWAY_FLAGS,
                            tmp_ccd ? tmp_ccd : "");
        if( tmp_ccd ) la_free( tmp_ccd );
      }
    }
    if( ccd_options ){
      *return_list = la_malloc( sizeof( struct openvpn_plugin_string_list ) );
      if( *return_list != NULL){
        (*return_list)->next = NULL;
        (*return_list)->name = strdup( "config" );
        (*return_list)->value = ccd_options;
      }
    }
    return OPENVPN_PLUGIN_FUNC_SUCCESS;
  }
#ifdef ENABLE_LDAPUSERCONF
  else if( type == OPENVPN_PLUGIN_CLIENT_DISCONNECT ){
    /* nothing done for now
     * potentially, session could be logged
     */
    return OPENVPN_PLUGIN_FUNC_SUCCESS;
  }
#endif
  return res;
}
Exemplo n.º 10
0
static int luaCB_shoot( lua_State* L )
{
    action_push(AS_SHOOT);
    return lua_yield( L, 0 );
}
Exemplo n.º 11
0
// Push a sleep onto the stack
// Can only be called from an action stack
void action_push_delay(long msec)
{
    action_push(msec);
    action_push_func(action_stack_AS_SLEEP);
}
Exemplo n.º 12
0
// Push a function onto the stack
void action_push_func(action_func f)
{
    action_push((long)f);
    action_push(AS_FUNC_ENTRY);
}
Exemplo n.º 13
0
int md_init_motion_detector(
 int columns,
 int rows,
 int pixel_measure_mode,
 int detection_timeout,
 int measure_interval,
 int threshold,
 int draw_grid,
 int clipping_region_mode,
 int clipping_region_column1,
 int clipping_region_row1,
 int clipping_region_column2,
 int clipping_region_row2,
 int parameters,
 int pixels_step,
 int msecs_before_trigger
){

	if(!motion_detector) {
		motion_detector=malloc(sizeof(struct motion_detector_s));
		if(!motion_detector)
			return 0; // TODO make sure callers handle this
	}
#ifdef OPT_MD_DEBUG
	motion_detector->comp_calls_cnt=0;
#endif
	motion_detector->previous_picture_is_ready=0;
	motion_detector->curr=motion_detector->buff1;
	motion_detector->prev=motion_detector->buff2;

	if(		pixel_measure_mode != MD_MEASURE_MODE_Y 
		&&	pixel_measure_mode != MD_MEASURE_MODE_U
		&&	pixel_measure_mode != MD_MEASURE_MODE_V
		&&	pixel_measure_mode != MD_MEASURE_MODE_R
		&&	pixel_measure_mode != MD_MEASURE_MODE_G
		&&	pixel_measure_mode != MD_MEASURE_MODE_B
		){
		pixel_measure_mode = MD_MEASURE_MODE_Y;
	}


	if( columns<1 || rows<1 || columns * rows > MOTION_DETECTOR_CELLS ){
		columns=3;
		rows=3;
	}

	if(msecs_before_trigger<0){
		msecs_before_trigger=0;
	}

	if (pixels_step<1){
		pixels_step=1;
	}

	if(detection_timeout<0){
		detection_timeout=0;
	}

	if(measure_interval<0) {
		measure_interval=0;
	}

	if(threshold<0) {
		threshold=0;
	}


	motion_detector->msecs_before_trigger=msecs_before_trigger;
	motion_detector->parameters = parameters;
	motion_detector->pixels_step=pixels_step;
	motion_detector->columns=columns;
	motion_detector->rows=rows;
	motion_detector->return_value=0;
	

	motion_detector->pixel_measure_mode=pixel_measure_mode;
	motion_detector->timeout=detection_timeout;
	motion_detector->measure_interval=measure_interval;
	motion_detector->threshold=threshold;
	motion_detector->draw_grid=draw_grid;


	if (clipping_region_column1>clipping_region_column2){
		motion_detector->clipping_region_column2=clipping_region_column1;
		motion_detector->clipping_region_column1=clipping_region_column2;
	} else {
		motion_detector->clipping_region_column2=clipping_region_column2;
		motion_detector->clipping_region_column1=clipping_region_column1;
	}

	if (clipping_region_row1>clipping_region_row2){
		motion_detector->clipping_region_row2=clipping_region_row1;
		motion_detector->clipping_region_row1=clipping_region_row2;
	} else {
		motion_detector->clipping_region_row2=clipping_region_row2;
		motion_detector->clipping_region_row1=clipping_region_row1;
	}

	if (clipping_region_mode!=MD_REGION_NONE && clipping_region_mode!=MD_REGION_INCLUDE && clipping_region_mode!=MD_REGION_EXCLUDE){
		clipping_region_mode=MD_REGION_NONE;
	}
	motion_detector->clipping_region_mode=clipping_region_mode;

	motion_detector->detected_cells=0;
	motion_detector->previous_picture_is_ready=0;
	motion_detector->start_time=get_tick_count();

	motion_detector->last_measure_time = motion_detector->start_time - motion_detector->measure_interval;

	motion_detector->running=1;

	action_push(AS_MOTION_DETECTOR);
	draw_clear();

	return 1;
}