Esempio n. 1
0
int photo_camera::photo_camera_find_widget_by_name( std::string name, CameraWidget **child, CameraWidget **root)
 {
  int error_code;

  // Get camera configuration
  error_code = gp_camera_get_config( camera_, root, context_ );
  if (error_code != GP_OK)
  {
    photo_reporter::error( "gp_camera_get_config()");
    return error_code;
  }

  // Find child of configuration by name
  if( gp_widget_get_child_by_name( *root, name.c_str(), child ) == GP_OK )
  {
    return GP_OK;
  }

  // Find child of configuration  by label
  if( gp_widget_get_child_by_label( *root, name.c_str(), child ) == GP_OK )
  {
    return GP_OK;
  }

  // If full name is not found, search for last subname.
  // name delimeter is '/'
  size_t found_index = name.length();
  while( found_index == name.length() )
  {
    found_index = name.rfind( '/' );

    if( found_index == std::string::npos ) // No subname, we already failed this search above
    {
      gp_context_error( context_,"%s not found in configuration tree.", name.c_str() );
      gp_widget_free( *root );
      return GP_ERROR;
    }

    if( found_index == name.length() - 1 ) // end of string, cut it off
    {
      name = name.substr( 0, found_index );
    }
  }
  name = name.substr( found_index, name.length() - 1 );

  // Find child using 
  if( gp_widget_get_child_by_name( *root, name.c_str(), child ) == GP_OK )
  {
    return GP_OK;
  }
  if( gp_widget_get_child_by_label( *root, name.c_str(), child ) == GP_OK )
  {
    return GP_OK;
  }

  // all matches have failed
  gp_context_error( context_, "%s not found in configuration tree.", name.c_str() );
  gp_widget_free( *root );
  return GP_ERROR;
}
Esempio n. 2
0
static int file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list, void *data, GPContext *context) {

	Camera *camera = data;
	int count;

	/* We only support root folder */
	if (strcmp (folder, "/"))
	{
		gp_context_error (context, _("Only root folder is supported - "
			"you requested a file listing for folder '%s'."), folder);
		return (GP_ERROR_DIRECTORY_NOT_FOUND);
	}

	count = mesa_get_image_count (camera->port);
	if (count < 0)
	{
		gp_context_error (context, _("Problem getting number of images"));
		return (count);
	}

	/*
	 * Create pseudo file names for each picture in the camera, including
	 * the temporary picture in RAM, which, unfortunately, might not always
	 * be available.
	 *
	 * We don't add anything to the filesystem here - the filesystem does
	 * that for us.
	 */
	CHECK (gp_filesystem_append (fs, "/", RAM_IMAGE_TEMPLATE, context));
	return (gp_list_populate (list, IMAGE_NAME_TEMPLATE, count));
}
Esempio n. 3
0
/* Download a live image from the camera and return it in a malloced
buffer with PGM headers */
static uint8_t *
Dimera_Preview( long *size, Camera *camera, GPContext *context )
{
	uint8_t buffer[VIEWFIND_SZ/2], *p;
	int		i;
	uint8_t *image;
	uint32_t exposure_total;
	unsigned brightness;

	if ( !(image = (unsigned char *) malloc( VIEWFIND_SZ +
			sizeof( Dimera_viewhdr ) - 1 )) )
	{
		ERROR( "Get Preview, allocation failed" );
		gp_context_error (context, _("Out of memory"));
		return NULL;
	}

	/* set image size */
	*size = VIEWFIND_SZ + sizeof( Dimera_viewhdr ) - 1;

	/* set image header */
	memcpy( image, Dimera_viewhdr, sizeof( Dimera_viewhdr ) - 1 );

	if ( mesa_snap_view( camera->port, buffer, TRUE, 0, 0, 0, camera->pl->exposure,
			VIEW_TYPE) < 0 )
	{
		ERROR( "Get Preview, mesa_snap_view failed" );
		free (image);
		gp_context_error (context, _("Problem taking live image"));
		return NULL;
	}

	/* copy the buffer, splitting the pixels up */
	exposure_total = 0;
	for ( p = image + sizeof( Dimera_viewhdr ) - 1, i = 0;
			i < (VIEWFIND_SZ/2) ; i++ )
	{
		*p++ = buffer[i] >> 4;
		*p++ = buffer[i] & 0xf;
		exposure_total += (buffer[i] >> 4) + (buffer[i] & 0xf);
	}

	/* Automatic exposure control */

	/* Current picture brightness, where 0 is is dark and 255 is bright */
	brightness = exposure_total / (VIEWFIND_SZ / 16);

	GP_DEBUG(
		"Average pixel brightness %f, Current exposure value: %d",
		brightness / 16.0, camera->pl->exposure);

	if (camera->pl->auto_exposure && (brightness < 96 || brightness > 160)) {
		/* Picture brightness needs to be corrected for next time */
		camera->pl->exposure = calc_new_exposure(camera->pl->exposure, brightness);
		GP_DEBUG( "New exposure value: %d", camera->pl->exposure);
	}

	return image;
}
Esempio n. 4
0
/*
 * Capture an image
 */
static int
camera_capture (Camera* camera, CameraCaptureType type, CameraFilePath* path,
		GPContext *context)
{
	unsigned char cmd[3], buf[256], ack;
	int ret, nbr_images,images_taken,i;

	GP_DEBUG ("*** ENTER: camera_capture ***");

	/* Just check if there is space available yet */
	cmd[0] = ESC;
	cmd[1] = GETCAMINFO;
	ret = gp_port_write (camera->port, (char*)cmd, 2); 
	if (ret<GP_OK)
		return ret;
	ret = gp_port_read (camera->port, (char*)buf, INFO_BUFFER);
	nbr_images = (buf[FREE_IMAGE_PTR] << 8) | (buf[FREE_IMAGE_PTR+1]);
	images_taken = (buf[TAKEN_IMAGE_PTR] << 8) | (buf[TAKEN_IMAGE_PTR+1]);

	/* Capture the image */
	cmd[0] = ESC;
	cmd[1] = CAPTUREIMAGE_CMD1;
	cmd[2] = CAPTUREIMAGE_CMD2;
	ret = gp_port_write (camera->port, (char*)cmd, sizeof(cmd));
	if (ret<GP_OK)
		return ret;
	ret = gp_port_read (camera->port, (char*)&ack, ACK_LEN);
	if (ret<GP_OK)
		return ret;
	if (ack == NACK) {
		if (buf[CAMERA_MODE_PTR] != REC_MODE)
			gp_context_error(context, _("You must be in record "
				"mode to capture images."));
		else if (!nbr_images)
			gp_context_error(context, _("No space available "
				"to capture new images. You must delete some "
				"images."));
		else
			gp_context_error(context, _("Can't capture new images. "
				"Unknown error"));
		return (GP_ERROR);
	}

	/* Wait image writting in camera's memory */
	for (i=0; i<=15; i++) {
		sleep(1);
		if ((ret = k_ping(camera->port)) == GP_OK)
			break;
	}
	if (ret < GP_OK) {
		gp_context_error(context, _("No answer from the camera."));
		return (GP_ERROR);
	}

	/* Now register new image */
	images_taken++;
	sprintf (path->name, FILENAME, (unsigned int) images_taken);
	return (GP_OK);
}
Esempio n. 5
0
int
camera_init (Camera *camera, GPContext *context)
{
	int ret;
	GPPortSettings settings;

	/* First, set up all the function pointers */
	camera->functions->exit = camera_exit;
	camera->functions->summary = camera_summary;
	camera->functions->about = camera_about;

	CHECK (gp_port_get_settings (camera->port, &settings));
	switch (camera->port->type) {
		case GP_PORT_USB:
			settings.usb.inep = 0x82;
			settings.usb.outep = 0x03;
			settings.usb.config = 1;
			settings.usb.interface = 0;
			settings.usb.altsetting = 0;

			CHECK (gp_port_set_settings (camera->port, settings));
			CHECK (gp_port_set_timeout (camera->port, TIMEOUT));

			break;
		default:
			gp_context_error (context,
					  _("Unsupported port type: %d. "
					    "This driver only works with USB "
					    "cameras.\n"), camera->port->type);
			return (GP_ERROR);
			break;
	}

	camera->pl = malloc (sizeof (CameraPrivateLibrary));
	if (!camera->pl)
		return (GP_ERROR_NO_MEMORY);
	memset (camera->pl, 0, sizeof (CameraPrivateLibrary));
	camera->pl->gpdev = camera->port;
	camera->pl->dirty = 1;

	ret = gsmart300_reset (camera->pl);

	if (ret < 0) {
		gp_context_error (context, _("Could not reset camera.\n"));
		free (camera->pl);
		camera->pl = NULL;

		return (ret);
	}
	/* Set up the CameraFilesystem */
	return gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);
}
Esempio n. 6
0
bool photo_camera::photo_camera_capture_to_file( std::string filename )
{
  int fd, error_code;
  CameraFile *photo_file;
  CameraFilePath photo_file_path;

  // NOP: This gets overridden in the library to /capt0000.jpg
  strcpy( photo_file_path.folder, "/");
  strcpy( photo_file_path.name, "foo.jpg");

  error_code = gp_camera_capture( camera_, GP_CAPTURE_IMAGE, &photo_file_path, context_ );
  if( error_code < GP_OK )
  {
    photo_reporter::error( "gp_camera_capture()" );
    gp_context_error( context_, "Could not capture image  (error code %d)\n", error_code );
    return false;
  }

  fd = open( filename.c_str(), O_CREAT|O_WRONLY, 0644 );
  error_code = gp_file_new_from_fd( &photo_file, fd );
  if( error_code < GP_OK )
  {
    photo_reporter::error( "gp_file_new_from_fd()" );
    gp_context_error( context_, "Could not create a new image file from %s%s (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
    gp_file_free( photo_file );
    return false;
  }

  error_code = gp_camera_file_get( camera_, photo_file_path.folder, photo_file_path.name, GP_FILE_TYPE_NORMAL, photo_file, context_ );
  if( error_code < GP_OK )
  {
    photo_reporter::error( "gp_camera_file_get()" );
    gp_context_error( context_, "Could not get file %s%s (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
    gp_file_free( photo_file );
    return false;
  }

  error_code = gp_camera_file_delete( camera_, photo_file_path.folder, photo_file_path.name, context_ );
  if( error_code < GP_OK )
  {
    photo_reporter::error( "gp_camera_file_delete()" );
    gp_context_error( context_, "Could delete file %s%s  (error code %d)\n", photo_file_path.folder, photo_file_path.name, error_code );
    gp_file_free( photo_file );
    return false;
  }

  gp_file_free( photo_file );
  return true;
}
Esempio n. 7
0
/*
 * OK, lets get serious !
 */
int 
camera_init(Camera *camera,GPContext *context)
{
 GPPortSettings settings;
 CameraAbilities abilities;
 /* try to contact the camera ...*/
 /*CR(gp_port_get_settings(camera->port,&settings));*/
 
 camera->functions->about=camera_about; 
 camera->functions->exit=camera_exit;
 gp_port_get_settings(camera->port,&settings);
 if (camera->port->type!=GP_PORT_USB)
 {
  gp_context_error(context,_("sx330z is USB only"));
  return(GP_ERROR_UNKNOWN_PORT);
 }
/* GP_DEBUG("camera_init : in = %x",camera->port->settings.usb.inep);*/
 CR(gp_port_set_settings(camera->port,settings));
 CR(gp_port_set_timeout(camera->port,TIMEOUT)); 

 CR(gp_filesystem_set_funcs(camera->fs, &fsfuncs, camera));
 
 camera->pl=malloc(sizeof(CameraPrivateLibrary));
 if (!camera->pl) 
   return(GP_ERROR_NO_MEMORY);

 CR(gp_camera_get_abilities(camera, &abilities));
 camera->pl->usb_product=abilities.usb_product; /* some models differ in Thumbnail size */
/* GP_DEBUG("sx330z Camera_init : sx init %04x",camera->pl->usb_product); */
 return(sx330z_init(camera,context));

} /* camera init */
Esempio n. 8
0
static int put_file_func (CameraFilesystem *fs, const char *folder, const char *filename,
			  CameraFileType type, CameraFile *file, void *data, GPContext *context) {
   
    Camera *camera=data;
    const char *data_file;
    long unsigned int data_size;
   
    /*
     * Upload the file to the camera. Use gp_file_get_data_and_size, etc.
    */
    GP_DEBUG ("*** put_file_func");
    GP_DEBUG ("*** folder: %s", folder);
    GP_DEBUG ("*** filename: %s", filename);
   
    gp_file_get_data_and_size (file, &data_file, &data_size);
    if ( data_size == 0) {
       gp_context_error (context,
			 _("The file to be uploaded has a null length"));
       return GP_ERROR_BAD_PARAMETERS;
    }

    /* Should check memory here */
   
   /*        if (available_memory < data_size) {
       gp_context_error (context,
			 _("Not enough memory available on the memory card"));
       return GP_ERROR_NO_MEMORY;
     }
   */
   
    tiger_upload_file (camera->pl, filename,data_file,data_size);
   
    return GP_OK;
}
Esempio n. 9
0
/**
 * Captures a preview that won't be stored on the camera but returned in 
 * supplied file. 
 *
 * @param camera a #Camera
 * @param file a #CameraFile
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * For example, you could use gp_capture_preview() for taking some sample
 * pictures before calling gp_capture().
 *
 **/
int
gp_camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
{
	char *xname;
	C_PARAMS (camera && file);
	CHECK_INIT (camera, context);

	CR (camera, gp_file_clean (file), context);

	if (!camera->functions->capture_preview) {
		gp_context_error (context, _("This camera can "
			"not capture previews."));
		CAMERA_UNUSED (camera, context);
                return (GP_ERROR_NOT_SUPPORTED);
	}

	CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->capture_preview (
					camera, file, context), context);
	gp_file_get_name_by_type (file, "capture_preview", GP_FILE_TYPE_NORMAL, &xname);
	/* FIXME: Marcus ... will go away, just keep compatible now. */
	gp_file_set_name (file, xname);
	free (xname);

	CAMERA_UNUSED (camera, context);
	return (GP_OK);
}
Esempio n. 10
0
static int
set_info_func (CameraFilesystem *fs, const char *folder, const char *file,
               CameraFileInfo info, void *data, GPContext *context)
{
        Camera *camera = data;
        char tmp[7];
        int p;
        unsigned long image_id;
	KncCamRes cr;

        /* Permissions? */
        if (info.file.fields & GP_FILE_INFO_PERMISSIONS) {
                strncpy (tmp, file, 6);
                tmp[6] = '\0';
                image_id = atol (tmp);
                if (info.file.permissions & GP_FILE_PERM_DELETE) p = FALSE;
                else p = TRUE;
                CR (knc_set_prot (camera->pl->c, &cr, image_id,
				  KNC_SOURCE_CARD, p), context);
		CCR (cr, context);
        }

        /* Name? */
        if (info.file.fields & GP_FILE_INFO_NAME) {
                gp_context_error (context, _("Your camera does not support "
                        "changing filenames."));
                return (GP_ERROR_NOT_SUPPORTED);
        }

        return (GP_OK);
}
Esempio n. 11
0
/*
 * Delete all images
 */
static int
delete_all_func (CameraFilesystem *fs, const char *folder, void *data,
		GPContext *context)
{
	unsigned char	cmd[7], ack;
	int	ret;
	Camera *camera = data;

	GP_DEBUG ("*** ENTER: delete_all_func ***");

	cmd[0] = ESC;
	cmd[1] = ERASEIMAGE_CMD1;
	cmd[2] = IMAGE_CMD2;
	cmd[3] = 0x30;
	cmd[4] = 0x30;
	cmd[5] = 0x30;
	cmd[6] = 0x30;
	ret = gp_port_write (camera->port, (char*)cmd, sizeof(cmd));
	if (ret<GP_OK) return ret;
	ret = gp_port_read (camera->port, (char*)&ack, ACK_LEN);
	if (ret<GP_OK) return ret;
	if (ack != ACK) {
		gp_context_error(context, _("Can't delete all images."));
		return (GP_ERROR);
	}	
	return (GP_OK);
}
Esempio n. 12
0
/*
 * Delete one image
 * The image mustn't be protected
 */
static int
delete_file_func (CameraFilesystem *fs, const char *folder, 
		const char *filename, void *data, GPContext *context)
{
	Camera *camera = data;
	CameraFileInfo file_info;
	unsigned char cmd[7], ack;
	int image_no;
	int ret;

	GP_DEBUG ("*** ENTER: delete_file_func ***");

        image_no = gp_filesystem_number(fs, folder, filename, context);
	if (image_no < 0) return image_no;

	image_no++;
	ret = k_info_img (image_no, data, (CameraFileInfo *)&file_info, 
		&image_no);
	if (ret < GP_OK)
		return ret;

	/* Now, check if the image isn't protected */
	if (file_info.file.permissions == GP_FILE_PERM_READ) {
		gp_context_error(context, _("Image %s is delete protected."),
			filename);
		return (GP_ERROR);
	}

	/* Erase the image */
	cmd[0] = ESC;
	cmd[1] = ERASEIMAGE_CMD1;
	cmd[2] = IMAGE_CMD2;
	cmd[3] = 0x30 + ((image_no/1000)%10);
	cmd[4] = 0x30 + ((image_no/100 )%10);
	cmd[5] = 0x30 + ((image_no/10  )%10);
	cmd[6] = 0x30 + ( image_no      %10);
	ret = gp_port_write (camera->port, (char*)cmd, sizeof(cmd));
	if (ret<GP_OK) return ret;
	ret = gp_port_read (camera->port, (char*)&ack, ACK_LEN);
	if (ret<GP_OK) return ret;
	if (ack != ACK) {
		gp_context_error(context, _("Can't delete image %s."),filename);
		return (GP_ERROR);
	}	
	return (GP_OK);
}
Esempio n. 13
0
static int
pre_func (Camera *camera, GPContext *context)
{
	int r;
	unsigned int i;
	GPPortSettings settings;

	GP_DEBUG ("Initializing connection...");

	CR (gp_port_get_settings (camera->port, &settings));
	CR (fuji_ping (camera, context));
	if (!camera->pl->speed) {

		/* Set to the highest possible speed. */
		for (i = 0; Speeds[i].bit_rate; i++) {
			r = fuji_set_speed (camera, Speeds[i].speed, NULL);
			if (r >= 0)
				break;
		}

		/*
		 * Change the port's speed and check if the camera is
		 * still there.
		 */
		settings.serial.speed = Speeds[i].bit_rate;
		CR (gp_port_set_settings (camera->port, settings));
		GP_DEBUG("Pinging to check new speed %i.", Speeds[i].bit_rate);
		CR (fuji_ping (camera, context));

	} else {

		/* User specified a speed. Check if the speed is possible */
		for (i = 0; Speeds[i].bit_rate; i++)
			if (Speeds[i].bit_rate == camera->pl->speed)
				break;
		if (!Speeds[i].bit_rate) {
			gp_context_error (context, _("Bit rate %ld is not "
					"supported."), camera->pl->speed);
			return (GP_ERROR_NOT_SUPPORTED);
		}

		/* Change the speed if necessary. */
		if (camera->pl->speed != Speeds[i].bit_rate) {
			CR (fuji_set_speed (camera, Speeds[i].speed, context));

			/*
			 * Change the port's speed and check if the camera is 
			 * still there.
			 */
			settings.serial.speed = Speeds[i].bit_rate;
			CR (gp_port_set_settings (camera->port, settings));
			CR (fuji_ping (camera, context));
		}
	}

	return (GP_OK);
}
Esempio n. 14
0
static int get_file_func (CameraFilesystem *fs, const char *folder,
			  const char *filename, CameraFileType type,
			  CameraFile *file, void *user_data, 
			  GPContext *context)
{
	Camera		*camera = user_data;
	unsigned char	*data = NULL;
	long unsigned	data_len = 0;
	int		res;

	if(camera->pl->context)
	{
		gp_context_error(context, CONTEXT_EXISTS);
		return GP_ERROR;
	}

	camera->pl->context = context;

	if(check_last_use(camera) == GP_ERROR)
	{
		camera->pl->context = NULL;
		return GP_ERROR;
	}

	switch (type) {
	case GP_FILE_TYPE_PREVIEW:
		res = dc3200_get_data (camera, &data, &data_len,
				       CMD_GET_PREVIEW, folder, filename);
		break;
	case GP_FILE_TYPE_NORMAL:
		res = dc3200_get_data (camera, &data, &data_len, 
				       CMD_GET_FILE, folder, filename);
		break;
	default:
		camera->pl->context = NULL;
		return (GP_ERROR_NOT_SUPPORTED);
	}
	if (res < 0)
	{
		camera->pl->context = NULL;
		return (res);
	}

	if (data == NULL || data_len < 1)
	{
		camera->pl->context = NULL;
		return GP_ERROR;
	}

	gp_file_append (file, (char *)data, data_len);

	free(data);
	camera->pl->context = NULL;
	return (dc3200_keep_alive(camera));
}
Esempio n. 15
0
static int camera_exit (Camera *camera, GPContext *context)
{
	if (camera->pl) {
		if(camera->pl->context) {
			gp_context_error(context, CONTEXT_EXISTS);
			return GP_ERROR;
		}
		free (camera->pl);
		camera->pl = NULL;
	}

	return GP_OK;
}
Esempio n. 16
0
/**
 * Triggers capture of one or more images.
 *
 * @param camera a #Camera
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * This functions just remotely causes the shutter release and returns
 * immediately. You will want to run #gp_camera_wait_event until a image
 * is added which can be downloaded using #gp_camera_file_get.
 **/
int
gp_camera_trigger_capture (Camera *camera, GPContext *context)
{
	C_PARAMS (camera);
	CHECK_INIT (camera, context);

	if (!camera->functions->trigger_capture) {
		gp_context_error (context, _("This camera can not trigger capture."));
		CAMERA_UNUSED (camera, context);
                return (GP_ERROR_NOT_SUPPORTED);
	}
	CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->trigger_capture (camera,
						context), context);
	CAMERA_UNUSED (camera, context);
	return (GP_OK);
}
Esempio n. 17
0
/**
 * Retrieve a configuration \c window for the \c camera.
 *
 * @param camera a #Camera
 * @param window a #CameraWidget
 * @param context a #GPContext
 * @return gphoto2 error code
 *
 * This \c window can be used for construction of a configuration dialog.
 *
 */
int
gp_camera_get_config (Camera *camera, CameraWidget **window, GPContext *context)
{
	C_PARAMS (camera);
	CHECK_INIT (camera, context);

	if (!camera->functions->get_config) {
		gp_context_error (context, _("This camera does "
			"not provide any configuration options."));
		CAMERA_UNUSED (camera, context);
                return (GP_ERROR_NOT_SUPPORTED);
	}

	CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->get_config (
					camera, window, context), context);

	CAMERA_UNUSED (camera, context);
	return (GP_OK);
}
Esempio n. 18
0
/**
 * Sets the configuration.
 *
 * @param camera a #Camera
 * @param window a #CameraWidget
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * Typically, a \c window is retrieved using #gp_camera_get_config and passed 
 * to this function in order to adjust the settings on the camera.
 *
 **/
int
gp_camera_set_config (Camera *camera, CameraWidget *window, GPContext *context)
{
	CHECK_NULL (camera && window);
	CHECK_INIT (camera, context);

	if (!camera->functions->set_config) {
		gp_context_error (context, _("This camera does "
			"not support setting configuration options."));
		CAMERA_UNUSED (camera, context);
                return (GP_ERROR_NOT_SUPPORTED);
	}

	CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->set_config (camera,
						window, context), context);

	CAMERA_UNUSED (camera, context);
	return (GP_OK);
}
Esempio n. 19
0
/**
 * Retrieves a camera summary.
 *
 * @param camera a #Camera
 * @param summary a #CameraText
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * This summary typically contains information like manufacturer, pictures
 * taken, or generally information that is not configurable.
 *
 **/
int
gp_camera_get_summary (Camera *camera, CameraText *summary, GPContext *context)
{
	CHECK_NULL (camera && summary);
	CHECK_INIT (camera, context);

	if (!camera->functions->summary) {
		gp_context_error (context, _("This camera does "
				  "not support summaries."));
		CAMERA_UNUSED (camera, context);
                return (GP_ERROR_NOT_SUPPORTED);
	}

	CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->summary (camera,
						summary, context), context);

	CAMERA_UNUSED (camera, context);
	return (GP_OK);
}
Esempio n. 20
0
/**
 * Retrieves the \c manual for given \c camera.
 *
 * @param camera a #Camera
 * @param manual a #CameraText
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * This manual typically contains information about using the camera.
 *
 **/
int
gp_camera_get_manual (Camera *camera, CameraText *manual, GPContext *context)
{
	CHECK_NULL (camera && manual);
	CHECK_INIT (camera, context);

	if (!camera->functions->manual) {
		gp_context_error (context, _("This camera "
			"does not offer a manual."));
		CAMERA_UNUSED (camera, context);
                return (GP_ERROR_NOT_SUPPORTED);
	}

	CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->manual (camera,
						manual, context), context);

	CAMERA_UNUSED (camera, context);
	return (GP_OK);
}
Esempio n. 21
0
/**
 * Retrieves information about the camera driver.
 *
 * @param camera a #Camera
 * @param about a #CameraText
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * Typically, this information contains name and address of the author,
 * acknowledgements, etc.
 *
 **/
int
gp_camera_get_about (Camera *camera, CameraText *about, GPContext *context)
{
	CHECK_NULL (camera && about);
	CHECK_INIT (camera, context);

	if (!camera->functions->about) {
		gp_context_error (context, _("This camera does "
			"not provide information about the driver."));
		CAMERA_UNUSED (camera, context);
                return (GP_ERROR_NOT_SUPPORTED);
	}

	CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->about (camera,
						about, context), context);

	CAMERA_UNUSED (camera, context);
	return (GP_OK);
}
Esempio n. 22
0
/**
 * Captures an image, movie, or sound clip depending on the given \c type.
 *
 * @param camera a #Camera
 * @param type a #CameraCaptureType
 * @param path a #CameraFilePath
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * The resulting file will be stored on the camera. The location gets stored
 * in \c path. The file can then be downloaded using #gp_camera_file_get.
 *
 **/
int
gp_camera_capture (Camera *camera, CameraCaptureType type,
		   CameraFilePath *path, GPContext *context)
{
	CHECK_NULL (camera);
	CHECK_INIT (camera, context);

	if (!camera->functions->capture) {
		gp_context_error (context, _("This camera can not capture."));
		CAMERA_UNUSED (camera, context);
                return (GP_ERROR_NOT_SUPPORTED);
	}

	CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->capture (camera,
						type, path, context), context);

	CAMERA_UNUSED (camera, context);
	return (GP_OK);
}
Esempio n. 23
0
static int
get_info_func (CameraFilesystem *fs, const char *folder, const char *file,
		      CameraFileInfo *info, void *data, GPContext *context)
{
	char path[1024];
	const char *mime_type;
	struct stat st;
	Camera *camera = (Camera*)data;
	int result;

	gp_log (GP_LOG_DEBUG, "directory/get_info_func", "%s %s", folder, file);
	result = _get_path (camera->port, folder, file, path, sizeof(path));
	if (result < GP_OK)
		return result;

	if (lstat (path, &st) != 0) {
		gp_context_error (context, _("Could not get information "
			"about '%s' in '%s' (%m)."), file, folder);
		return (GP_ERROR);
	}

        info->preview.fields = GP_FILE_INFO_NONE;
        info->file.fields = GP_FILE_INFO_SIZE | GP_FILE_INFO_NAME |
                            GP_FILE_INFO_TYPE | GP_FILE_INFO_PERMISSIONS |
			    GP_FILE_INFO_MTIME;

	info->file.mtime = st.st_mtime;
	info->file.permissions = GP_FILE_PERM_NONE;
	if (st.st_mode & S_IRUSR)
		info->file.permissions |= GP_FILE_PERM_READ;
	if (st.st_mode & S_IWUSR)
		info->file.permissions |= GP_FILE_PERM_DELETE;
        strcpy (info->file.name, file);
        info->file.size = st.st_size;
	mime_type = get_mime_type (file);
	if (!mime_type)
		mime_type = "application/octet-stream";
	strcpy (info->file.type, mime_type);

        return (GP_OK);
}
Esempio n. 24
0
/**
 * Captures a preview that won't be stored on the camera but returned in 
 * supplied file. 
 *
 * @param camera a #Camera
 * @param file a #CameraFile
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * For example, you could use #gp_capture_preview for taking some sample
 * pictures before calling #gp_capture.
 *
 **/
int
gp_camera_capture_preview (Camera *camera, CameraFile *file, GPContext *context)
{
	CHECK_NULL (camera && file);
	CHECK_INIT (camera, context);

	CR (camera, gp_file_clean (file), context);

	if (!camera->functions->capture_preview) {
		gp_context_error (context, _("This camera can "
			"not capture previews."));
		CAMERA_UNUSED (camera, context);
                return (GP_ERROR_NOT_SUPPORTED);
	}

	CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->capture_preview (
					camera, file, context), context);

	CAMERA_UNUSED (camera, context);
	return (GP_OK);
}
Esempio n. 25
0
static int
delete_file_func (CameraFilesystem *fs, const char *folder,
		  const char *file, void *data, GPContext *context)
{
	char path[2048];
	int result;
	Camera *camera = (Camera*)data;

	result = _get_path (camera->port, folder, file, path, sizeof(path));
	if (result < GP_OK)
		return result;
	result = unlink (path);
	if (result) {
		gp_context_error (context, _("Could not delete file '%s' "
			"in folder '%s' (error code %i: %m)."),
			file, folder, result);
		return (GP_ERROR);
	}

	return (GP_OK);
}
Esempio n. 26
0
int
gp_camera_list_config (Camera *camera, CameraList *list, GPContext *context)
{
	CameraWidget		*rootwidget;
	int			ret;
	C_PARAMS (camera);
	CHECK_INIT (camera, context);

	if (camera->functions->list_config) {
		CHECK_RESULT_OPEN_CLOSE (camera, camera->functions->list_config (
						camera, list, context), context);

		CAMERA_UNUSED (camera, context);
		return GP_OK;
	}
	if (!camera->functions->get_config) {
		gp_context_error (context, _("This camera does not provide any configuration options."));
		CAMERA_UNUSED (camera, context);
		return GP_ERROR_NOT_SUPPORTED;
	}
	/* emulate it ... */
	CHECK_OPEN (camera, context);

	ret = camera->functions->get_config ( camera, &rootwidget, context);
	if (ret != GP_OK) {
		CHECK_CLOSE (camera, context);
		CAMERA_UNUSED (camera, context);
		return ret;
	}

	_get_widget_names (rootwidget, list);


	gp_widget_free (rootwidget);
	CHECK_CLOSE (camera, context);
	CAMERA_UNUSED (camera, context);
	return ret;
}
Esempio n. 27
0
static int camera_capture (Camera *camera, CameraCaptureType type, CameraFilePath *path, GPContext *context) {

	if (type != GP_CAPTURE_IMAGE)
	{
		gp_context_error (context, _("Capture type is not supported"));
		return (GP_ERROR_NOT_SUPPORTED);
	}

	if (camera->pl->auto_flash) {
		CHECK (mesa_snap_picture( camera->port, camera->pl->exposure*4 ));
	}
	else {
		CHECK (mesa_snap_image( camera->port, camera->pl->exposure*4 ));
	}

	/*
	 * User must download special RAM_IMAGE_TEMPLATE file.
	 */
	strncpy (path->folder, "/", sizeof (path->folder));
	strncpy (path->name, RAM_IMAGE_TEMPLATE, sizeof (path->name));

	return (GP_OK);
}
Esempio n. 28
0
static int
delete_all_func (CameraFilesystem *fs, const char* folder, void *data,
                 GPContext *context)
{
        Camera *camera = data;
        unsigned int not_erased = 0;
	KncCamRes cr;

        if (strcmp (folder, "/")) return (GP_ERROR_DIRECTORY_NOT_FOUND);

        CR (knc_erase_all (camera->pl->c, &cr, KNC_SOURCE_CARD, &not_erased),
	    context);
	CCR (cr, context);

        if (not_erased) {
                gp_context_error (context, _("%i pictures could not be "
                        "deleted because they are protected"), not_erased);
                gp_filesystem_reset (camera->fs);
                return (GP_ERROR);
        }

        return (GP_OK);
}
Esempio n. 29
0
int camera_init (Camera *camera, GPContext *context)
{
    GPPortSettings settings;
    int ret;

    /* First, set up all the function pointers */
    camera->functions->summary              = camera_summary;
    camera->functions->about                = camera_about;
    camera->functions->capture_preview	= camera_capture_preview;
    camera->functions->capture		= camera_capture;

    gp_port_get_settings(camera->port, &settings);
    switch(camera->port->type) {
    case GP_PORT_USB:
	/* Modify the default settings the core parsed */
	settings.usb.altsetting=1;/* we need to use interface 0 setting 1 */
	settings.usb.inep=2;
	settings.usb.intep=3;
	settings.usb.outep=5;

	/* Use the defaults the core parsed */
	break;
    default:
	return (GP_ERROR_UNKNOWN_PORT);
	break;
    }

    ret = gp_port_set_settings (camera->port, settings);
    if (ret != GP_OK) {
	gp_context_error (context, _("Could not apply USB settings"));
	return ret;
    }
    /* Set up the filesystem */
    gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);
    /* test camera */
    return stv0674_ping(camera->port);
}
Esempio n. 30
0
static int get_info_func (CameraFilesystem *fs, const char *folder, const char *filename, CameraFileInfo *info, void *data, GPContext *context) {

	Camera *camera = data;
	int num, std_res;

	num = gp_filesystem_number (fs, folder, filename, context);
	if (num < 0)
		return num;

	if ( (std_res = mesa_read_image_info( camera->port, num, NULL )) < 0 )
	{
		ERROR("Can't get Image Info");
		gp_context_error (context, _("Problem getting image information"));
		return std_res;
	}

	info->preview.fields = GP_FILE_INFO_ALL;
	strcpy(info->preview.type, GP_MIME_PGM);
	info->preview.size = MESA_THUMB_SZ + sizeof( Dimera_thumbhdr ) - 1;
	info->preview.width = 64;
	info->preview.height = 48;

	info->file.fields = GP_FILE_INFO_TYPE|GP_FILE_INFO_PERMISSIONS|GP_FILE_INFO_WIDTH|GP_FILE_INFO_HEIGHT|GP_FILE_INFO_SIZE;
	strcpy(info->file.type, GP_MIME_PPM);
	info->file.permissions = GP_FILE_PERM_READ;

	if (std_res) {
	    info->file.width = 320;
	    info->file.height = 240;
	} else {
	    info->file.width = 640;
	    info->file.height = 480;
	}
	info->file.size = info->file.height*info->file.width*3 + sizeof( Dimera_finehdr ) - 1;

	return GP_OK;
}