changed camera_capture API, added camera_file_info, added serial_flush
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@1680 67ed7778-7388-44ab-90cf-0a291f65f57c
This commit is contained in:
@@ -84,8 +84,9 @@ OPTION_CALLBACK(delete_picture);
|
||||
OPTION_CALLBACK(delete_all_pictures);
|
||||
OPTION_CALLBACK(upload_picture);
|
||||
OPTION_CALLBACK(capture_image);
|
||||
OPTION_CALLBACK(capture_movie);
|
||||
OPTION_CALLBACK(capture_preview);
|
||||
OPTION_CALLBACK(capture_movie);
|
||||
OPTION_CALLBACK(capture_sound);
|
||||
OPTION_CALLBACK(summary);
|
||||
OPTION_CALLBACK(manual);
|
||||
OPTION_CALLBACK(about);
|
||||
@@ -132,9 +133,10 @@ Option option[] = {
|
||||
{"d", "delete-picture", "range", "Delete pictures given in range", delete_picture, 0},
|
||||
{"D", "delete-all-pictures","", "Delete all pictures in folder",delete_all_pictures,0},
|
||||
{"u", "upload-picture", "filename", "Upload a picture to camera", upload_picture, 0},
|
||||
{"" , "capture-image", "", "Capture an image and download",capture_image, 0},
|
||||
{"" , "capture-movie", "duration", "Capture a movie and download", capture_movie, 0},
|
||||
{"" , "capture-preview","", "Capture a preview and download",capture_preview,0},
|
||||
{"" , "capture-preview","", "Capture a quick preview", capture_preview, 0},
|
||||
{"" , "capture-image", "resolution", "Capture an image", capture_image, 0},
|
||||
{"" , "capture-movie", "resolution:duration", "Capture a movie ", capture_movie, 0},
|
||||
{"" , "capture-sound", "resolution:duration", "Capture an audio clip", capture_sound, 0},
|
||||
{"", "summary", "", "Summary of camera status", summary, 0},
|
||||
{"", "manual", "", "Camera driver manual", manual, 0},
|
||||
{"", "about", "", "About the camera driver", about, 0},
|
||||
@@ -252,6 +254,13 @@ OPTION_CALLBACK(abilities) {
|
||||
}
|
||||
printf("Capture from computer support : %s\n",
|
||||
abilities.capture == 0? "no":"yes");
|
||||
printf("Capture choices :\n");
|
||||
x=0;
|
||||
while (abilities.capture_setting[x].type != GP_CAPTURE_NONE) {
|
||||
printf(" : %s\n",
|
||||
abilities.capture_setting[x].name);
|
||||
x++;
|
||||
}
|
||||
printf("Configuration support : %s\n",
|
||||
abilities.config == 0? "no":"yes");
|
||||
printf("Delete files on camera support : %s\n",
|
||||
@@ -451,36 +460,12 @@ OPTION_CALLBACK(num_pictures) {
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int save_picture_to_file(char *folder, char *filename, int thumbnail) {
|
||||
int save_camera_file_to_file (CameraFile *file, int thumbnail) {
|
||||
|
||||
char out_filename[1024], out_folder[1024], buf[1024], msg[1024];
|
||||
int result;
|
||||
char *f;
|
||||
int resp1, resp2;
|
||||
int result;
|
||||
|
||||
CameraFile *file;
|
||||
|
||||
file = gp_file_new();
|
||||
|
||||
if (thumbnail) {
|
||||
if ((result = gp_camera_file_get_preview(glob_camera, file, folder, filename)) != GP_OK) {
|
||||
cli_error_print("Can not get preview for %s.", filename);
|
||||
return (result);
|
||||
}
|
||||
} else {
|
||||
if ((result = gp_camera_file_get(glob_camera, file, folder, filename)) != GP_OK) {
|
||||
cli_error_print("Can not get picture %s", filename);
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
if (glob_stdout) {
|
||||
if (glob_stdout_size)
|
||||
printf("%li\n", file->size);
|
||||
fwrite(file->data, sizeof(char), file->size, stdout);
|
||||
gp_file_free(file);
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
/* Determine the folder and filename */
|
||||
strcpy(out_filename, "");
|
||||
@@ -499,7 +484,7 @@ int save_picture_to_file(char *folder, char *filename, int thumbnail) {
|
||||
sprintf(out_filename, glob_filename, glob_num++);
|
||||
}
|
||||
} else {
|
||||
strcat(out_filename, filename);
|
||||
strcat(out_filename, file->name);
|
||||
}
|
||||
|
||||
if (thumbnail)
|
||||
@@ -530,11 +515,46 @@ int save_picture_to_file(char *folder, char *filename, int thumbnail) {
|
||||
if ((result = gp_file_save(file, buf)) != GP_OK)
|
||||
cli_error_print("Can not save %s as %s", thumbnail ? "preview" : "image", buf);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
int save_picture_to_file(char *folder, char *filename, int thumbnail) {
|
||||
|
||||
int result;
|
||||
|
||||
CameraFile *file;
|
||||
|
||||
file = gp_file_new();
|
||||
|
||||
if (thumbnail) {
|
||||
if ((result = gp_camera_file_get_preview(glob_camera, file, folder, filename)) != GP_OK) {
|
||||
cli_error_print("Can not get preview for %s.", filename);
|
||||
return (result);
|
||||
}
|
||||
} else {
|
||||
if ((result = gp_camera_file_get(glob_camera, file, folder, filename)) != GP_OK) {
|
||||
cli_error_print("Can not get picture %s", filename);
|
||||
return (result);
|
||||
}
|
||||
}
|
||||
|
||||
if (glob_stdout) {
|
||||
if (glob_stdout_size)
|
||||
printf("%li\n", file->size);
|
||||
fwrite(file->data, sizeof(char), file->size, stdout);
|
||||
gp_file_free(file);
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
result = save_camera_file_to_file(file, thumbnail);
|
||||
|
||||
gp_file_free(file);
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
get_picture_common() - parse range, download specified images, or their
|
||||
thumbnails according to thumbnail argument, and save to files.
|
||||
@@ -631,6 +651,16 @@ OPTION_CALLBACK(delete_all_pictures) {
|
||||
if ((result = set_globals()) != GP_OK)
|
||||
return (result);
|
||||
|
||||
/* If the camera supports deleting all the files */
|
||||
if (glob_camera->abilities->file_delete_all) {
|
||||
printf("##################\n");
|
||||
result = gp_camera_file_delete_all (glob_camera, glob_folder);
|
||||
/* If that went OK, return. Otherwise, do it 1 by 1 */
|
||||
if (result == GP_OK)
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
|
||||
if (!glob_camera->abilities->file_delete) {
|
||||
cli_error_print("Camera can not delete pictures");
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -671,61 +701,77 @@ OPTION_CALLBACK(upload_picture) {
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int capture_generic (int type, int duration) {
|
||||
int capture_generic (int type, char *name) {
|
||||
|
||||
CameraCaptureInfo info;
|
||||
CameraFile *file;
|
||||
char out_filename[1024];
|
||||
CameraCaptureSetting info;
|
||||
CameraFilePath path;
|
||||
CameraFile* file;
|
||||
char *col;
|
||||
int result;
|
||||
|
||||
if ((result = set_globals()) != GP_OK)
|
||||
return (result);
|
||||
|
||||
info.type = type;
|
||||
info.duration = duration;
|
||||
switch (type) {
|
||||
case GP_CAPTURE_VIDEO:
|
||||
case GP_CAPTURE_AUDIO:
|
||||
col = strrchr(name, ':');
|
||||
if (!col) {
|
||||
printf("You need to specify a capture duration.\n");
|
||||
return GP_ERROR;
|
||||
}
|
||||
*col++ = 0;
|
||||
info.duration = -1;
|
||||
info.duration = atoi(col);
|
||||
if (info.duration == -1) {
|
||||
printf("You need to specify a capture duration.\n");
|
||||
return GP_ERROR;
|
||||
}
|
||||
case GP_CAPTURE_IMAGE:
|
||||
info.type = type;
|
||||
strcpy(info.name, name);
|
||||
|
||||
file = gp_file_new();
|
||||
|
||||
if ((result = gp_camera_capture(glob_camera, file, &info)) != GP_OK) {
|
||||
if ((result = gp_camera_capture(glob_camera, &path, &info)) != GP_OK) {
|
||||
cli_error_print("Could not capture.");
|
||||
return (result);
|
||||
}
|
||||
|
||||
if (glob_quiet)
|
||||
printf("%s/%s\n", path.folder, path.name);
|
||||
else
|
||||
printf("New file is in location %s/%s on the camera\n", path.folder, path.name);
|
||||
break;
|
||||
default:
|
||||
file = gp_file_new();
|
||||
if ((result = gp_camera_capture_preview(glob_camera, file)) != GP_OK) {
|
||||
cli_error_print("Could not capture the preview.");
|
||||
return (result);
|
||||
}
|
||||
save_camera_file_to_file(file, 0);
|
||||
gp_file_free(file);
|
||||
}
|
||||
|
||||
if ((glob_filename_override)&&(strlen(glob_filename)>0))
|
||||
strcpy(out_filename, glob_filename);
|
||||
else {
|
||||
if (strlen(file->name) == 0) {
|
||||
printf("Could not determine filename.\nRename to approprite filename and extension.\n");
|
||||
strcpy(out_filename, "capture.dat");
|
||||
} else {
|
||||
strcpy(out_filename, file->name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!glob_quiet)
|
||||
printf("Saving capture as %s\n", out_filename);
|
||||
if (gp_file_save(file, out_filename) != GP_OK)
|
||||
cli_error_print("Can not save capture as %s.\nSpecify a different filename using \"--filename\"\n", out_filename);
|
||||
|
||||
gp_file_free(file);
|
||||
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
|
||||
OPTION_CALLBACK(capture_image) {
|
||||
|
||||
return (capture_generic(GP_CAPTURE_IMAGE, 0));
|
||||
return (capture_generic(GP_CAPTURE_IMAGE, arg));
|
||||
}
|
||||
|
||||
OPTION_CALLBACK(capture_movie) {
|
||||
|
||||
return (capture_generic(GP_CAPTURE_VIDEO, atoi(arg)));
|
||||
return (capture_generic(GP_CAPTURE_VIDEO, arg));
|
||||
}
|
||||
|
||||
OPTION_CALLBACK(capture_sound) {
|
||||
|
||||
return (capture_generic(GP_CAPTURE_AUDIO, arg));
|
||||
}
|
||||
|
||||
OPTION_CALLBACK(capture_preview) {
|
||||
|
||||
return (capture_generic(GP_CAPTURE_PREVIEW, 0));
|
||||
return (capture_generic(GP_CAPTURE_PREVIEW, arg));
|
||||
}
|
||||
|
||||
OPTION_CALLBACK(summary) {
|
||||
@@ -887,7 +933,6 @@ void signal_exit (int signo) {
|
||||
int main (int argc, char **argv) {
|
||||
|
||||
int result;
|
||||
char test[25];
|
||||
|
||||
/* Initialize the globals */
|
||||
init_globals();
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
typedef struct {
|
||||
char short_id[3];
|
||||
char long_id[20];
|
||||
char argument[16];
|
||||
char argument[32];
|
||||
char description[35];
|
||||
OPTION_CALLBACK((*execute));
|
||||
int required;
|
||||
@@ -25,4 +25,4 @@ void cli_debug_print(char *format, ...);
|
||||
void cli_error_print(char *format, ...);
|
||||
int save_picture_to_file(char *folder, char *filename, int thumbnail);
|
||||
int get_picture_common(char *arg, int thumbnail);
|
||||
int capture_generic (int type, int duration);
|
||||
int capture_generic (int type, char *capture_choice);
|
||||
|
||||
@@ -69,7 +69,6 @@ int gp_camera_abilities_by_name (char *camera_name, CameraAbilities *abilities)
|
||||
|
||||
int gp_camera_new (Camera **camera)
|
||||
{
|
||||
if (camera == NULL) return (GP_ERROR_BAD_PARAMETERS);
|
||||
|
||||
*camera = (Camera*)malloc(sizeof(Camera));
|
||||
if (!*camera)
|
||||
@@ -107,7 +106,9 @@ int gp_camera_new (Camera **camera)
|
||||
(*camera)->functions->config_set = NULL;
|
||||
(*camera)->functions->file_put = NULL;
|
||||
(*camera)->functions->file_delete = NULL;
|
||||
(*camera)->functions->capture = NULL;
|
||||
(*camera)->functions->file_delete_all = NULL;
|
||||
(*camera)->functions->capture = NULL;
|
||||
(*camera)->functions->capture_preview = NULL;
|
||||
(*camera)->functions->summary = NULL;
|
||||
(*camera)->functions->manual = NULL;
|
||||
(*camera)->functions->about = NULL;
|
||||
@@ -235,9 +236,10 @@ int gp_camera_init (Camera *camera)
|
||||
if (x == glob_abilities_list->count)
|
||||
return GP_ERROR_MODEL_NOT_FOUND;
|
||||
camera->abilities->file_delete = glob_abilities_list->abilities[x]->file_delete;
|
||||
camera->abilities->file_preview = glob_abilities_list->abilities[x]->file_preview;
|
||||
camera->abilities->file_delete_all = glob_abilities_list->abilities[x]->file_delete_all;
|
||||
camera->abilities->file_preview = glob_abilities_list->abilities[x]->file_preview;
|
||||
camera->abilities->file_put = glob_abilities_list->abilities[x]->file_put;
|
||||
camera->abilities->capture = glob_abilities_list->abilities[x]->capture;
|
||||
camera->abilities->capture = glob_abilities_list->abilities[x]->capture;
|
||||
camera->abilities->config = glob_abilities_list->abilities[x]->config;
|
||||
|
||||
/* Load the library. */
|
||||
@@ -272,7 +274,7 @@ int gp_camera_folder_list(Camera *camera, CameraList *list, char *folder)
|
||||
CameraListEntry t;
|
||||
int x, ret, y, z;
|
||||
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (list == NULL) || (folder == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
|
||||
/* Initialize the folder list to a known state */
|
||||
@@ -306,7 +308,7 @@ int gp_camera_file_list(Camera *camera, CameraList *list, char *folder)
|
||||
CameraListEntry t;
|
||||
int x, ret, y, z;
|
||||
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (list == NULL) || (folder == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
|
||||
/* Initialize the folder list to a known state */
|
||||
@@ -333,11 +335,30 @@ int gp_camera_file_list(Camera *camera, CameraList *list, char *folder)
|
||||
return (GP_OK);
|
||||
}
|
||||
|
||||
int gp_camera_file_info (Camera *camera, CameraFileInfo *info,
|
||||
char *folder, char *filename)
|
||||
{
|
||||
if ((camera == NULL) || (info == NULL) || (folder == NULL) || (filename == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->file_get == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
|
||||
if (strlen (folder) == 0)
|
||||
return (GP_ERROR_DIRECTORY_NOT_FOUND);
|
||||
if (strlen (filename) == 0)
|
||||
return (GP_ERROR_FILE_NOT_FOUND);
|
||||
|
||||
memset(info, 0, sizeof(CameraFileInfo));
|
||||
|
||||
return (camera->functions->file_info(camera, info, folder, filename));
|
||||
}
|
||||
|
||||
|
||||
int gp_camera_file_get (Camera *camera, CameraFile *file,
|
||||
char *folder, char *filename)
|
||||
{
|
||||
if (camera == NULL)
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if ((camera == NULL) || (file == NULL) || (folder == NULL) || (filename == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->file_get == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
|
||||
@@ -357,7 +378,7 @@ int gp_camera_file_get (Camera *camera, CameraFile *file,
|
||||
int gp_camera_file_get_preview (Camera *camera, CameraFile *file,
|
||||
char *folder, char *filename)
|
||||
{
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (file == NULL) || (folder == NULL) || (filename == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->file_get_preview == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -370,7 +391,7 @@ int gp_camera_file_get_preview (Camera *camera, CameraFile *file,
|
||||
int gp_camera_file_config_get (Camera *camera, CameraWidget **window,
|
||||
char *folder, char *filename)
|
||||
{
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (folder == NULL) || (filename == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->file_config_get == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -381,7 +402,7 @@ int gp_camera_file_config_get (Camera *camera, CameraWidget **window,
|
||||
int gp_camera_file_config_set (Camera *camera, CameraWidget *window,
|
||||
char *folder, char *filename)
|
||||
{
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (window == NULL) || (folder == NULL) || (filename == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->file_config_set == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -392,7 +413,7 @@ int gp_camera_file_config_set (Camera *camera, CameraWidget *window,
|
||||
int gp_camera_folder_config_get (Camera *camera, CameraWidget **window,
|
||||
char *folder)
|
||||
{
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (folder == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->folder_config_get == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -403,7 +424,7 @@ int gp_camera_folder_config_get (Camera *camera, CameraWidget **window,
|
||||
int gp_camera_folder_config_set (Camera *camera, CameraWidget *window,
|
||||
char *folder)
|
||||
{
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (window == NULL) || (folder == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->folder_config_set == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -423,7 +444,7 @@ int gp_camera_config_get (Camera *camera, CameraWidget **window)
|
||||
|
||||
int gp_camera_config_set (Camera *camera, CameraWidget *window)
|
||||
{
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (window == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->config_set == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -433,7 +454,7 @@ int gp_camera_config_set (Camera *camera, CameraWidget *window)
|
||||
|
||||
int gp_camera_file_put (Camera *camera, CameraFile *file, char *folder)
|
||||
{
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (file == NULL) || (folder == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->file_put == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -443,7 +464,7 @@ int gp_camera_file_put (Camera *camera, CameraFile *file, char *folder)
|
||||
|
||||
int gp_camera_file_delete (Camera *camera, char *folder, char *filename)
|
||||
{
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (folder == NULL) || (filename == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->file_delete == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -451,30 +472,51 @@ int gp_camera_file_delete (Camera *camera, char *folder, char *filename)
|
||||
return (camera->functions->file_delete(camera, folder, filename));
|
||||
}
|
||||
|
||||
int gp_camera_file_delete_all (Camera *camera, char *folder)
|
||||
{
|
||||
if ((camera == NULL) || (folder == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->file_delete_all == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
|
||||
return (camera->functions->file_delete_all(camera, folder));
|
||||
}
|
||||
|
||||
|
||||
int gp_camera_config (Camera *camera)
|
||||
{
|
||||
|
||||
if (camera == NULL)
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->config == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
|
||||
return (camera->functions->config(camera));
|
||||
}
|
||||
|
||||
int gp_camera_capture (Camera *camera, CameraFile *file, CameraCaptureInfo *info)
|
||||
int gp_camera_capture (Camera *camera, CameraFilePath *path, CameraCaptureSetting *setting)
|
||||
{
|
||||
if (camera == NULL)
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if ((camera == NULL) || (path == NULL) || (setting == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
|
||||
if (camera->functions->capture == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
|
||||
gp_file_clean(file);
|
||||
return (camera->functions->capture(camera, path, setting));
|
||||
}
|
||||
|
||||
return (camera->functions->capture(camera, file, info));
|
||||
int gp_camera_capture_preview (Camera *camera, CameraFile *file)
|
||||
{
|
||||
if ((camera == NULL) || (file == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->capture_preview == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
|
||||
return (camera->functions->capture_preview(camera, file));
|
||||
}
|
||||
|
||||
int gp_camera_summary (Camera *camera, CameraText *summary)
|
||||
{
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (summary == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->summary == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -484,7 +526,7 @@ int gp_camera_summary (Camera *camera, CameraText *summary)
|
||||
|
||||
int gp_camera_manual (Camera *camera, CameraText *manual)
|
||||
{
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (manual == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->manual == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -494,7 +536,7 @@ int gp_camera_manual (Camera *camera, CameraText *manual)
|
||||
|
||||
int gp_camera_about (Camera *camera, CameraText *about)
|
||||
{
|
||||
if (camera == NULL)
|
||||
if ((camera == NULL) || (about == NULL))
|
||||
return (GP_ERROR_BAD_PARAMETERS);
|
||||
if (camera->functions->about == NULL)
|
||||
return (GP_ERROR_NOT_SUPPORTED);
|
||||
@@ -504,6 +546,7 @@ int gp_camera_about (Camera *camera, CameraText *about)
|
||||
|
||||
char *gp_camera_result_as_string (Camera *camera, int result)
|
||||
{
|
||||
|
||||
/* Camlib error? */
|
||||
if (result <= -1000 && (camera != NULL)) {
|
||||
if (camera->functions->result_as_string == NULL)
|
||||
|
||||
@@ -23,14 +23,24 @@ int gp_abilities_dump (CameraAbilities *abilities) {
|
||||
NETWORK_SUPPORTED(abilities->port)? "yes":"no");
|
||||
if (abilities->speed[0] != 0) {
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "Transfer speeds supported :");
|
||||
do {
|
||||
x=0;
|
||||
do {
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", " : %i", abilities->speed[x]);
|
||||
x++;
|
||||
} while (abilities->speed[x]!=0);
|
||||
}
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "Capture from computer support : %s",
|
||||
abilities->capture == 0? "no":"yes");
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "Configuration support : %s",
|
||||
if (abilities->capture > 0) {
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "Capture choices :");
|
||||
x=0;
|
||||
while (abilities->capture_setting[x].type != GP_CAPTURE_NONE) {
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", " : %s",
|
||||
abilities->capture_setting[x].name);
|
||||
x++;
|
||||
}
|
||||
}
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "Configuration support : %s",
|
||||
abilities->config == 0? "no":"yes");
|
||||
gp_debug_printf(GP_DEBUG_LOW, "core", "Delete files on camera support : %s",
|
||||
abilities->file_delete == 0? "no":"yes");
|
||||
|
||||
@@ -56,9 +56,10 @@
|
||||
|
||||
#define GP_ERROR_IO_SERIAL_SPEED -19
|
||||
#define GP_ERROR_IO_SERIAL_BREAK -20
|
||||
#define GP_ERROR_IO_SERIAL_FLUSH -21
|
||||
|
||||
#define GP_ERROR_IO_USB_CLEAR_HALT -21
|
||||
#define GP_ERROR_IO_USB_FIND -22
|
||||
#define GP_ERROR_IO_USB_CLEAR_HALT -22
|
||||
#define GP_ERROR_IO_USB_FIND -23
|
||||
|
||||
/* Debugging definitions for init */
|
||||
#define GP_DEBUG_NONE 0
|
||||
@@ -122,10 +123,11 @@ struct gp_port_operations {
|
||||
/* Pointers to devices. Please note these are stubbed so there is
|
||||
no need to #ifdef GP_PORT_* anymore. */
|
||||
|
||||
/* for serial and parallel devices */
|
||||
/* for serial devices */
|
||||
int (*get_pin) (gp_port *, int, int*);
|
||||
int (*set_pin) (gp_port *, int, int);
|
||||
int (*send_break)(gp_port *, int);
|
||||
int (*flush) (gp_port *, int);
|
||||
|
||||
/* for USB devices */
|
||||
int (*find_device)(gp_port * dev, int idvendor, int idproduct);
|
||||
@@ -300,6 +302,11 @@ struct gp_port {
|
||||
int gp_port_send_break (gp_port *dev, int duration);
|
||||
/* send a break (duration is in seconds) */
|
||||
|
||||
int gp_port_flush (gp_port *dev, int direction);
|
||||
/* Flush either an input or output line */
|
||||
/* Input line is 0, Output is 1 */
|
||||
/* (think STDIO/STDOUT file descriptors */
|
||||
|
||||
/* USB specific functions
|
||||
-------------------------------------------------------------- */
|
||||
|
||||
|
||||
@@ -92,8 +92,9 @@ char *gp_port_result_as_string (int result) {
|
||||
GP_ERR_RES(-18, "Error with the port");
|
||||
GP_ERR_RES(-19, "Error setting the serial port speed");
|
||||
GP_ERR_RES(-20, "Error sending a break to the serial port");
|
||||
GP_ERR_RES(-21, "Error clearing a halt condition on the USB port");
|
||||
GP_ERR_RES(-22, "Could not find the requested device on the USB port");
|
||||
GP_ERR_RES(-21, "Error flushing the serial line");
|
||||
GP_ERR_RES(-22, "Error clearing a halt condition on the USB port");
|
||||
GP_ERR_RES(-23, "Could not find the requested device on the USB port");
|
||||
|
||||
return (N_("Unknown error"));
|
||||
}
|
||||
@@ -384,7 +385,7 @@ int gp_port_settings_set(gp_port *dev, gp_port_settings settings)
|
||||
|
||||
int gp_port_settings_get(gp_port *dev, gp_port_settings * settings)
|
||||
{
|
||||
memcpy(settings, &dev->settings, sizeof(gp_port_settings));
|
||||
memcpy(settings, &(dev->settings), sizeof(gp_port_settings));
|
||||
gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_get_settings: ok");
|
||||
|
||||
return GP_OK;
|
||||
@@ -438,6 +439,22 @@ int gp_port_send_break (gp_port *dev, int duration)
|
||||
return (retval);
|
||||
}
|
||||
|
||||
int gp_port_flush (gp_port *dev, int direction)
|
||||
{
|
||||
int retval;
|
||||
|
||||
if (!dev->ops->flush) {
|
||||
gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level, "gp_port_flush: gp_port_flush NULL");
|
||||
return (GP_ERROR);
|
||||
}
|
||||
|
||||
retval = dev->ops->flush(dev, direction);
|
||||
gp_port_debug_printf(GP_DEBUG_LOW, dev->debug_level,
|
||||
"gp_port_flush: flush %s", retval < 0? "error":"ok");
|
||||
return (retval);
|
||||
}
|
||||
|
||||
|
||||
/* USB-specific functions */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"POT-Creation-Date: 2001-03-03 11:54-0800\n"
|
||||
"POT-Creation-Date: 2001-03-07 08:48-0800\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
@@ -14,6 +14,6 @@ msgstr ""
|
||||
"Content-Type: text/plain; charset=CHARSET\n"
|
||||
"Content-Transfer-Encoding: ENCODING\n"
|
||||
|
||||
#: libgphoto2_port/gp_port.c:72 libgphoto2_port/gp_port.c:98
|
||||
#: libgphoto2_port/gp_port.c:72 libgphoto2_port/gp_port.c:99
|
||||
msgid "Unknown error"
|
||||
msgstr ""
|
||||
|
||||
@@ -74,6 +74,7 @@ int gp_port_serial_update (gp_port *dev);
|
||||
int gp_port_serial_get_pin(gp_port *dev, int pin, int *level);
|
||||
int gp_port_serial_set_pin(gp_port *dev, int pin, int level);
|
||||
int gp_port_serial_send_break (gp_port *dev, int duration);
|
||||
int gp_port_serial_flush(gp_port *dev, int direction);
|
||||
|
||||
|
||||
/* private */
|
||||
@@ -105,6 +106,7 @@ gp_port_operations *gp_port_library_operations () {
|
||||
ops->get_pin = gp_port_serial_get_pin;
|
||||
ops->set_pin = gp_port_serial_set_pin;
|
||||
ops->send_break = gp_port_serial_send_break;
|
||||
ops->flush = gp_port_serial_flush;
|
||||
|
||||
return (ops);
|
||||
}
|
||||
@@ -181,10 +183,11 @@ int gp_port_serial_exit (gp_port *dev) {
|
||||
|
||||
int gp_port_serial_open(gp_port * dev)
|
||||
{
|
||||
int fd;
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
dev->device_fd = open(dev->settings.serial.port, O_RDWR | O_NOCTTY | O_NONBLOCK);
|
||||
#elif OS2
|
||||
int fd;
|
||||
fd = open(dev->settings.serial.port, O_RDWR | O_BINARY);
|
||||
dev->device_fd = open(dev->settings.serial.port, O_RDWR | O_BINARY);
|
||||
|
||||
@@ -382,6 +385,34 @@ int gp_port_serial_set_pin(gp_port * dev, int pin, int level)
|
||||
return GP_OK;
|
||||
}
|
||||
|
||||
int gp_port_serial_flush (gp_port * dev, int direction)
|
||||
{
|
||||
|
||||
#if HAVE_TERMIOS_H
|
||||
int q;
|
||||
|
||||
switch (direction) {
|
||||
case 0:
|
||||
q = TCIFLUSH;
|
||||
break;
|
||||
case 1:
|
||||
q = TCOFLUSH;
|
||||
break;
|
||||
default:
|
||||
return GP_ERROR_IO_SERIAL_FLUSH;
|
||||
}
|
||||
|
||||
if (tcflush (dev->device_fd, q) < 0)
|
||||
return (GP_ERROR_IO_SERIAL_FLUSH);
|
||||
|
||||
return GP_OK;
|
||||
#else
|
||||
#warning SERIAL FLUSH NOT IMPLEMENTED FOR NON TERMIOS SYSTEMS!
|
||||
return GP_ERROR_IO_SERIAL_FLUSH;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This function will apply the settings to
|
||||
* the device. The device has to be opened
|
||||
@@ -530,6 +561,7 @@ int gp_port_serial_send_break (gp_port *dev, int duration) {
|
||||
tcdrain(dev->device_fd);
|
||||
#else
|
||||
/* ioctl */
|
||||
#warning SEND BREAK NOT IMPLEMENTED FOR NON TERMIOS SYSTEMS!
|
||||
return GP_ERROR_IO_SERIAL_BREAK;
|
||||
#endif
|
||||
return GP_OK;
|
||||
|
||||
@@ -183,6 +183,7 @@ int gp_port_usb_clear_halt_lib(gp_port * dev, int ep)
|
||||
int gp_port_usb_write(gp_port * dev, char *bytes, int size)
|
||||
{
|
||||
int ret;
|
||||
/*
|
||||
if (dev->debug_level) {
|
||||
int i;
|
||||
|
||||
@@ -191,7 +192,7 @@ int gp_port_usb_write(gp_port * dev, char *bytes, int size)
|
||||
printf("%02x ",(unsigned char)bytes[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
*/
|
||||
ret = usb_bulk_write(dev->device_handle, dev->settings.usb.outep,
|
||||
bytes, size, dev->timeout);
|
||||
if (ret < 0)
|
||||
@@ -205,9 +206,10 @@ int gp_port_usb_read(gp_port * dev, char *bytes, int size)
|
||||
|
||||
ret = usb_bulk_read(dev->device_handle, dev->settings.usb.inep,
|
||||
bytes, size, dev->timeout);
|
||||
if (ret < 0)
|
||||
if (ret < 0)
|
||||
return GP_ERROR_IO_READ;
|
||||
|
||||
/*
|
||||
if (dev->debug_level) {
|
||||
int i;
|
||||
|
||||
@@ -216,6 +218,7 @@ int gp_port_usb_read(gp_port * dev, char *bytes, int size)
|
||||
printf("%02x ",(unsigned char)(bytes[i]));
|
||||
printf("\n");
|
||||
}
|
||||
*/
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user