diff --git a/camlibs/ricoh/ChangeLog b/camlibs/ricoh/ChangeLog index 17906aa38..31a847a8f 100644 --- a/camlibs/ricoh/ChangeLog +++ b/camlibs/ricoh/ChangeLog @@ -1,3 +1,8 @@ +2002-06-20 Lutz Müller + + * ricoh.[c,h] + * library.c: First step towards support of settings. + 2002-06-20 Lutz Müller * ricoh.h: diff --git a/camlibs/ricoh/library.c b/camlibs/ricoh/library.c index 0f419bffd..40c8621c4 100644 --- a/camlibs/ricoh/library.c +++ b/camlibs/ricoh/library.c @@ -89,7 +89,8 @@ camera_abilities (CameraAbilitiesList *list) strcpy (a.model, models[i].model); a.status = GP_DRIVER_STATUS_EXPERIMENTAL; a.port = GP_PORT_SERIAL; - a.operations = GP_OPERATION_CAPTURE_IMAGE; + a.operations = GP_OPERATION_CAPTURE_IMAGE | + GP_OPERATION_CONFIG; a.file_operations = GP_FILE_OPERATION_DELETE | GP_FILE_OPERATION_PREVIEW; a.folder_operations = GP_FOLDER_OPERATION_NONE; @@ -207,9 +208,7 @@ camera_summary (Camera *camera, CameraText *about, GPContext *context) time_t camtime; char model[128]; unsigned int i; - const char *cam_id; - CR (ricoh_get_cam_id (camera, context, &cam_id)); CR (ricoh_get_cam_amem (camera, context, &avail_mem)); CR (ricoh_get_cam_mem (camera, context, &total_mem)); CR (ricoh_get_cam_date (camera, context, &camtime)); @@ -225,10 +224,9 @@ camera_summary (Camera *camera, CameraText *about, GPContext *context) camera->pl->model); sprintf (about->text, _("Model: %s\n" - "Camera ID: %s\n" "Memory: %d byte(s) of %d available\n" "Camera time: %s\n"), - model, cam_id, avail_mem, total_mem, ctime (&camtime)); + model, avail_mem, total_mem, ctime (&camtime)); return (GP_OK); } @@ -253,6 +251,61 @@ camera_capture (Camera *camera, CameraCaptureType type, return (GP_OK); } +static int +camera_get_config (Camera *camera, CameraWidget **window, GPContext *context) +{ + CameraWidget *section, *widget; + const char *copyright; + time_t time; + + CR (gp_widget_new (GP_WIDGET_WINDOW, _("Configuration"), window)); + + CR (gp_widget_new (GP_WIDGET_SECTION, _("General"), §ion)); + CR (gp_widget_append (*window, section)); + + /* Copyright */ + CR (gp_widget_new (GP_WIDGET_TEXT, _("Copyright"), &widget)); + CR (gp_widget_set_name (widget, "copyright")); + CR (gp_widget_set_info (widget, _("Copyright"))); + CR (gp_widget_append (section, widget)); + CR (ricoh_get_copyright (camera, context, ©right)); + CR (gp_widget_set_value (widget, copyright)); + + /* Date */ + CR (gp_widget_new (GP_WIDGET_DATE, _("Date & Time"), &widget)); + CR (gp_widget_set_name (widget, "date")); + CR (gp_widget_set_info (widget, _("Date & Time"))); + CR (gp_widget_append (section, widget)); + CR (ricoh_get_date (camera, context, &time)); + CR (gp_widget_set_value (widget, &time)); + + return (GP_OK); +} + +static int +camera_set_config (Camera *camera, CameraWidget *window, GPContext *context) +{ + CameraWidget *widget; + const char *copyright; + time_t time; + + /* Copyright */ + CR (gp_widget_get_child_by_name (window, "copyright", &widget)); + if (gp_widget_changed (widget)) { + CR (gp_widget_get_value (widget, ©right)); + CR (ricoh_set_copyright (camera, context, copyright)); + } + + /* Date */ + CR (gp_widget_get_child_by_name (window, "date", &widget)); + if (gp_widget_changed (widget)) { + CR (gp_widget_get_value (widget, &time)); + CR (ricoh_set_date (camera, context, time)); + } + + return (GP_OK); +} + static struct { unsigned int speed; RicohSpeed rspeed; @@ -324,6 +377,8 @@ camera_init (Camera *camera, GPContext *context) camera->functions->summary = camera_summary; camera->functions->capture = camera_capture; camera->functions->about = camera_about; + camera->functions->get_config = camera_get_config; + camera->functions->set_config = camera_set_config; CR (gp_filesystem_set_list_funcs (camera->fs, file_list_func, NULL, camera)); diff --git a/camlibs/ricoh/ricoh.c b/camlibs/ricoh/ricoh.c index bec2698b9..ec7a6be9e 100644 --- a/camlibs/ricoh/ricoh.c +++ b/camlibs/ricoh/ricoh.c @@ -495,26 +495,20 @@ ricoh_get_pic_memo (Camera *camera, GPContext *context, unsigned int n, int ricoh_del_pic (Camera *camera, GPContext *context, unsigned int n) { - unsigned char p[2], cmd, buf[0xff], len; + unsigned char p[2], buf[0xff], len; GP_DEBUG ("Deleting picture %i...", n); /* Put camera in delete mode */ - CR (ricoh_send (camera, context, 0x97, 0, NULL, 0)); - CR (ricoh_recv (camera, context, &cmd, NULL, buf, &len)); - C_CMD (context, cmd, 0x97); + CR (ricoh_transmit (camera, context, 0x97, NULL, 0, buf, &len)); C_LEN (context, len, 0); /* Find and send picture to delete */ p[0] = n >> 0; p[1] = n >> 8; - CR (ricoh_send (camera, context, 0x93, 0, p, 2)); - CR (ricoh_recv (camera, context, &cmd, NULL, buf, &len)); - C_CMD (context, cmd, 0x93); + CR (ricoh_transmit (camera, context, 0x93, p, 2, buf, &len)); C_LEN (context, len, 0); - CR (ricoh_send (camera, context, 0x92, 0, p, 2)); - CR (ricoh_recv (camera, context, &cmd, NULL, buf, &len)); - C_CMD (context, cmd, 0x92); + CR (ricoh_transmit (camera, context, 0x92, p, 2, buf, &len)); C_LEN (context, len, 0); return (GP_OK); @@ -658,14 +652,13 @@ ricoh_get_pic (Camera *camera, GPContext *context, unsigned int n, return (GP_OK); } -/* get the date the camera is set to */ int -ricoh_get_cam_date (Camera *camera, GPContext *context, time_t *date) +ricoh_get_date (Camera *camera, GPContext *context, time_t *date) { unsigned char p[1], buf[0xff], len; struct tm time; - p[0] = 0xa; + p[0] = 0x0a; CR (ricoh_transmit (camera, context, 'Q', p, 1, buf, &len)); /* the camera only supplies 2 digits for year, so I will @@ -679,11 +672,36 @@ ricoh_get_cam_date (Camera *camera, GPContext *context, time_t *date) time.tm_min = ((buf[5] & 0xf0) >> 4) * 10 + (buf[5] & 0xf); time.tm_sec = ((buf[6] & 0xf0) >> 4) * 10 + (buf[6] & 0xf); time.tm_isdst = -1; - *date = mktime(&time); + *date = mktime (&time); return (GP_OK); } +#ifdef HEX +# undef HEX +#endif +#define HEX(x) ((x/10)<<4)+(x%10) + +int +ricoh_set_date (Camera *camera, GPContext *context, time_t time) +{ + unsigned char p[8], buf[0xff], len; + struct tm *t; + + p[0] = 0x0a; + t = localtime (&time); + p[1] = HEX (t->tm_year / 100 + 19); + p[2] = HEX (t->tm_year % 100); + p[3] = HEX (t->tm_mon + 1); + p[4] = HEX (t->tm_mday); + p[5] = HEX (t->tm_hour); + p[6] = HEX (t->tm_min); + p[7] = HEX (t->tm_sec); + CR (ricoh_transmit (camera, context, 0x50, p, 8, buf, &len)); + + return (GP_OK); +} + /* get the cameras memory size */ int ricoh_get_cam_mem (Camera *camera, GPContext *context, int *size) @@ -716,24 +734,35 @@ ricoh_get_cam_amem (Camera *camera, GPContext *context, int *size) return (GP_OK); } -/* get the camera ID aka copyright message */ int -ricoh_get_cam_id (Camera *camera, GPContext *context, const char **cam_id) +ricoh_get_copyright (Camera *camera, GPContext *context, const char **copyright) { unsigned char p[1], len; static char buf[1024]; - p[0] = 0xf; + p[0] = 0x0f; CR (ricoh_transmit (camera, context, 'Q', p, 1, buf, &len)); - if (cam_id && *cam_id) { - *cam_id = buf; + if (copyright && *copyright) { + *copyright = buf; buf[len] = '\0'; } return (GP_OK); } +int +ricoh_set_copyright (Camera *camera, GPContext *context, const char *copyright) +{ + unsigned char p[21], len, buf[0xff]; + + p[0] = 0x0f; + strncpy (p + 1, copyright, 20); + CR (ricoh_transmit (camera, context, 0x50, p, 21, buf, &len)); + + return (GP_OK); +} + int ricoh_take_pic (Camera *camera, GPContext *context) { diff --git a/camlibs/ricoh/ricoh.h b/camlibs/ricoh/ricoh.h index b5207c942..a3ff5f8e0 100644 --- a/camlibs/ricoh/ricoh.h +++ b/camlibs/ricoh/ricoh.h @@ -95,10 +95,15 @@ int ricoh_get_pic (Camera *camera, GPContext *context, unsigned int n, int ricoh_take_pic (Camera *camera, GPContext *context); -int ricoh_get_cam_date (Camera *camera, GPContext *context, time_t *time); +int ricoh_get_date (Camera *camera, GPContext *context, time_t *time); +int ricoh_set_date (Camera *camera, GPContext *context, time_t time); + int ricoh_get_cam_mem (Camera *camera, GPContext *context, int *mem); int ricoh_get_cam_amem (Camera *camera, GPContext *context, int *mem); -int ricoh_get_cam_id (Camera *camera, GPContext *context, - const char **cam_id); + +int ricoh_get_copyright (Camera *camera, GPContext *context, + const char **copyright); +int ricoh_set_copyright (Camera *camera, GPContext *context, + const char *copyright); #endif /* __RICOH_H__ */