diff options
author | Scott Fritzinger <scottf@unr.edu> | 2000-07-17 16:45:58 +0000 |
---|---|---|
committer | Scott Fritzinger <scottf@unr.edu> | 2000-07-17 16:45:58 +0000 |
commit | 7587674d6a95c99eef251b1b54d0da913071448a (patch) | |
tree | 3218f74abedf340758856802e19348971dc8aff3 | |
parent | d129ef4ccafcec329158fd164e1cc474498bb46b (diff) | |
download | libgphoto2-7587674d6a95c99eef251b1b54d0da913071448a.tar.gz |
Added panasonic library. Thanx Mariusz.
git-svn-id: https://svn.code.sf.net/p/gphoto/code/trunk/libgphoto2@680 67ed7778-7388-44ab-90cf-0a291f65f57c
-rw-r--r-- | camlibs/Makefile.am | 6 | ||||
-rw-r--r-- | camlibs/panasonic/Makefile.am | 10 | ||||
-rw-r--r-- | camlibs/panasonic/dc.c | 190 | ||||
-rw-r--r-- | camlibs/panasonic/dc.h | 162 | ||||
-rw-r--r-- | camlibs/panasonic/dc1580.c | 573 | ||||
-rw-r--r-- | camlibs/panasonic/dc1580.h | 53 |
6 files changed, 993 insertions, 1 deletions
diff --git a/camlibs/Makefile.am b/camlibs/Makefile.am index bee3ddd6f..5a1254db5 100644 --- a/camlibs/Makefile.am +++ b/camlibs/Makefile.am @@ -1,3 +1,7 @@ ## Process this file with automake to generate a GNU Makefile -SUBDIRS = directory fujitsu barbie +SUBDIRS = \ + directory \ + fujitsu \ + barbie \ + panasonic diff --git a/camlibs/panasonic/Makefile.am b/camlibs/panasonic/Makefile.am new file mode 100644 index 000000000..5e22a6e1d --- /dev/null +++ b/camlibs/panasonic/Makefile.am @@ -0,0 +1,10 @@ +camlibdir = $(prefix)/lib/gphoto2 +camlib_LTLIBRARIES = libgphoto2_panasonic_dc1580.la + +CFLAGS = @CFLAGS@ -g `gpio-config --cflags` +LDFLAGS = @LDFLAGS@ -g `gpio-config --libs` +INCLUDES = -I$(top_srcdir)/include + +libgphoto2_panasonic_dc1580_la_SOURCES = dc1580.c dc1580.h dc.c dc.h + +libgphoto2_panasonic_dc1580_la_LDFLAGS = -version-info 0:0:0 `gpio-config --libs` diff --git a/camlibs/panasonic/dc.c b/camlibs/panasonic/dc.c new file mode 100644 index 000000000..ccf83c8aa --- /dev/null +++ b/camlibs/panasonic/dc.c @@ -0,0 +1,190 @@ +/* + $Id$ + + Copyright (c) 2000 Mariusz Zynel <mariusz@mizar.org> (gPhoto port) + Copyright (C) 2000 Fredrik Roubert <roubert@df.lth.se> (idea) + Copyright (C) 1999 Galen Brooks <galen@nine.com> (DC1580 code) + + This file is part of the gPhoto project and may only be used, modified, + and distributed under the terms of the gPhoto project license, COPYING. + By continuing to use, modify, or distribute this file you indicate that + you have read the license, understand and accept it fully. + + THIS SOFTWARE IS PROVIDED AS IS AND COME WITH NO WARRANTY OF ANY KIND, + EITHER EXPRESSED OR IMPLIED. IN NO EVENT WILL THE COPYRIGHT HOLDER BE + LIABLE FOR ANY DAMAGES RESULTING FROM THE USE OF THIS SOFTWARE. + + Note: + + This is a Panasonic DC1580 camera gPhoto library source code. +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/time.h> +#include <sys/stat.h> +#include <unistd.h> +#include <string.h> +#include <memory.h> +#include "dc.h" + +#ifndef __FILE__ +# define __FILE__ "dc.c" +#endif + +dsc_t *dsc = NULL; +int glob_debug = 0; + +int dsc_setbaudrate(dsc_t *dsc, int speed) { + + u_int8_t s_bps; + int s; + + static const char + command[6] = /* set baud rate */ + { 0x00, 0x00, 0x00, 0x01, 0x04 }, + response[5] = /* response ok */ + { 0x00, 0x00, 0x00, 0x01 }; + + switch (speed) { + + case 9600: + s_bps = 0x02; + break; + + case 19200: + s_bps = 0x0d; + break; + + case 38400: + s_bps = 0x01; + break; + + case 57600: + s_bps = 0x03; + break; + + case 115200: + s_bps = 0x00; + break; + + default: + DBUG_RETURN(EDSCBPSRNG, dsc_setbaudrate, GP_ERROR); + } + + gpio_write(dsc->dev, (char *)c_prefix, 12); + gpio_write(dsc->dev, (char *)command, 5); + gpio_write(dsc->dev, &s_bps, 1); + + s = gpio_read(dsc->dev, dsc->buf, 18); + if (glob_debug) + dsc_dumpmem(dsc->buf, s); + if (s == 18) { + if (memcmp(dsc->buf, r_prefix, 12) != 0 || + memcmp(dsc->buf + 12, response, 4) != 0) + s = 0; + } + else + DBUG_RETURN(EDSCNOANSW, dsc_setbaudrate, GP_ERROR); + /* no answer from camera */ + + sleep(DSC_PAUSE/2); + + dsc->settings.serial.speed = speed; + gpio_set_settings(dsc->dev, dsc->settings); + + DBUG_PRINT_1("Baudrate set to: %d", speed); + + return GP_OK; +} + +int dsc_getmodel(dsc_t *dsc) { + + int s; + + static const char + command[6] = /* get camera model */ + { 0x00, 0x00, 0x00, 0x00, 0x02 }, + response[9] = + { 0x00, 0x00, 0x00, 0x04, 0x03, 'D', 'S', 'C' }; + + gpio_write(dsc->dev, (char *)c_prefix, 12); + gpio_write(dsc->dev, (char *)command, 5); + + s = gpio_read(dsc->dev, dsc->buf, 21); + if (glob_debug) + dsc_dumpmem(dsc->buf, s); + if (s != 21 && + memcmp(dsc->buf, r_prefix, 12) != 0 && + memcmp(dsc->buf + 12, response, 8) != 0) + DBUG_RETURN(EDSCNOANSW, dsc_getmodel, GP_ERROR); + /* no answer from camera */ + + DBUG_PRINT_1("Camera model is: %c", dsc->buf[20]); + + switch (dsc->buf[20]) { + case '1': + return DSC1; + + case '2': + return DSC2; + + default: + return 0; + } + return GP_ERROR; +} + +int dsc_handshake(dsc_t *dsc, int speed) { + + if (dsc_setbaudrate(dsc, speed) != GP_OK) + return GP_ERROR; + + if (dsc_getmodel(dsc) != DSC2) + DBUG_RETURN(EDSCBADDSC, dsc_handshake, GP_ERROR); + /* bad camera model */ + + DBUG_PRINT("Handshake: OK."); + + return GP_OK; +} + +int dsc_dumpmem(void *buf, int size) { + + int i; + + fprintf(stderr, "\ndc.c: dsc_dumpmem(): size: %i, contents:\n", size); + for (i = 0; i < size; i ++) + fprintf( + stderr, + *((char*)buf + i) >= 32 && + *((char*)buf + i) < 127 ? "%c" : "\\x%02x", + (uint8_t)*((char*)buf + i) + ); + fprintf(stderr, "\n\n"); + + return GP_OK; +} + +const char *dsc_strerror(dsc_error lasterror) { + + static const char * const errorlist[] = { + "Unknown error code!", + "Baud rate out of range", + "No answer from camera", + "Read time out", + "Could not reset camera", + "Bad image number", + "Bad protocol", + "Bad response", + "Bad camera model" + }; + + return lasterror.lerror == EDSCSERRNO ? + strerror(lasterror.lerrno) : + lasterror.lerror < 1 || lasterror.lerror > EDSCMAXERR ? + errorlist[0] : + errorlist[lasterror.lerror]; +} + +/* End of dc.c */ diff --git a/camlibs/panasonic/dc.h b/camlibs/panasonic/dc.h new file mode 100644 index 000000000..96f0f4a6a --- /dev/null +++ b/camlibs/panasonic/dc.h @@ -0,0 +1,162 @@ +/* + $Id$ + + Copyright (c) 2000 Mariusz Zynel <mariusz@mizar.org> (gPhoto port) + Copyright (C) 2000 Fredrik Roubert <roubert@df.lth.se> (idea) + Copyright (C) 1999 Galen Brooks <galen@nine.com> (DC1580 code) + + This file is part of the gPhoto project and may only be used, modified, + and distributed under the terms of the gPhoto project license, COPYING. + By continuing to use, modify, or distribute this file you indicate that + you have read the license, understand and accept it fully. + + THIS SOFTWARE IS PROVIDED AS IS AND COME WITH NO WARRANTY OF ANY KIND, + EITHER EXPRESSED OR IMPLIED. IN NO EVENT WILL THE COPYRIGHT HOLDER BE + LIABLE FOR ANY DAMAGES RESULTING FROM THE USE OF THIS SOFTWARE. + + Note: + + This header contains common typedefs, constants and utility functions + for Panasonic DC1000 and DC1580 cameras. +*/ + +#include <sys/types.h> +#include <stdio.h> +#include <errno.h> +#include <gphoto2.h> +#include <gpio/gpio.h> + +#ifdef sun + typedef uint8_t u_int8_t; + typedef uint32_t u_int32_t; +#endif + +#define DSC1 1 /* DC1000 */ +#define DSC2 2 /* DC1580 */ + +typedef enum { + unknown = 0, + dsc1 = DSC1, + dsc2 = DSC2 +} dsc_protocol_t; + +typedef enum { + unavailable = -1, + normal = 0, + fine = 1, + superfine = 2 +} dsc_quality_t; + +typedef struct { + int lerror, lerrno; +} dsc_error; + +typedef struct { + gpio_device *dev; + gpio_device_settings settings; + dsc_protocol_t type; + dsc_error lasterror; + char model[64]; + char *buf; +} dsc_t; + +#define DSC_BLOCKSIZE 0x400 /* amount of data transfered in a single packet */ +#define DSC_MAXIMAGE 0xff /* highest possible number of an image */ + +#ifndef DSC_PAUSE +# define DSC_PAUSE 5 /* seconds to wait for camera to redraw screen */ +#endif + +#define DSC_READTIMEOUT 2 /* seconds to wait for data from terminal */ + +#define DSC_FULLIMAGE 0 +#define DSC_THUMBNAIL 1 + +#define EDSCSERRNO -1 /* see errno value */ +#define EDSCUNKNWN 0 /* unknown error code */ +#define EDSCBPSRNG 1 /* bps out of range */ +#define EDSCNOANSW 2 /* no answer from camera */ +#define EDSCRTMOUT 3 /* read time out */ +#define EDSCNRESET 4 /* could not reset camera */ +#define EDSCBADNUM 5 /* bad image number */ +#define EDSCBADPCL 6 /* bad protocol */ +#define EDSCBADRSP 7 /* bad response */ +#define EDSCBADDSC 8 /* bad camera model */ +#define EDSCMAXERR 8 /* highest used error code */ + +extern dsc_t *dsc; +extern int glob_debug; /* 0 - debug mode off, 1 - debug mode on */ + +static const char + c_prefix[13] = /* generic command prefix */ + { 'M', 'K', 'E', ' ', 'D', 'S', 'C', ' ', 'P', 'C', ' ', ' ' }, + + r_prefix[13] = /* generic response prefix */ + { 'M', 'K', 'E', ' ', 'P', 'C', ' ', ' ', 'D', 'S', 'C', ' ' }; + +int dsc_setbaudrate(dsc_t *dsc, int speed); + /* Set baud rate of connection. Part of hand shake procedure */ + /* Returns GP_OK if succesful and GP_ERROR otherwise. */ + +int dsc_getmodel(dsc_t *dsc); + /* Returns camera (sub)model, DSC1: DC1000, DSC2: DC1580, */ + /* 0: unknown, or GP_ERROR. Part of hand shake procedure. */ + +int dsc_handshake(dsc_t *dsc, int speed); + /* Negotiate transmition speed, check camera model. */ + /* Returns GP_OK if succesful and GP_ERROR otherwise. */ + +int dsc_dumpmem(void *buf, int size); + /* Print size bytes of memory at the buf pointer. */ + +const char *dsc_strerror(dsc_error lasterror); + /* Convert error numbers into readable messages. */ + +/******************************************************************************/ + +/* Pre-procesor macros for verbose messaging and debugging */ + +#define DBUG_PRINT(FORMAT) \ + if (glob_debug) \ + fprintf( \ + stderr, \ + __FILE__ ": " FORMAT "\n" \ + ) + +#define DBUG_PRINT_1(FORMAT, ARG1) \ + if (glob_debug) \ + fprintf( \ + stderr, \ + __FILE__ ": " FORMAT "\n", ARG1 \ + ) + +#define DBUG_PRINT_2(FORMAT, ARG1, ARG2) \ + if (glob_debug) \ + fprintf( \ + stderr, \ + __FILE__ ": " FORMAT "\n", ARG1, ARG2 \ + ) + +#define DBUG_PRINT_3(FORMAT, ARG1, ARG2, ARG3) \ + if (glob_debug) \ + fprintf( \ + stderr, \ + __FILE__ ": " FORMAT "\n", ARG1, ARG2, ARG3 \ + ) + +#define DBUG_PRINT_ERROR(DSCERROR, FUNCTION) \ + if (glob_debug) \ + fprintf( \ + stderr, \ + __FILE__ ": " #FUNCTION \ + "() return from line %u, code: %u, errno: %u, %s\n", \ + __LINE__, DSCERROR.lerror, DSCERROR.lerrno, dsc_strerror(DSCERROR) \ + ) + +#define DBUG_RETURN(ERROR, FUNCTION, RESULT) { \ + dsc->lasterror.lerror = ERROR; \ + dsc->lasterror.lerrno = errno; \ + DBUG_PRINT_ERROR(dsc->lasterror, FUNCTION); \ + return RESULT; } + +/* End of dc.h */ diff --git a/camlibs/panasonic/dc1580.c b/camlibs/panasonic/dc1580.c new file mode 100644 index 000000000..1226a2a45 --- /dev/null +++ b/camlibs/panasonic/dc1580.c @@ -0,0 +1,573 @@ +/* + $Id$ + + Copyright (c) 2000 Mariusz Zynel <mariusz@mizar.org> (gPhoto port) + Copyright (C) 2000 Fredrik Roubert <roubert@df.lth.se> (idea) + Copyright (C) 1999 Galen Brooks <galen@nine.com> (DC1580 code) + + This file is part of the gPhoto project and may only be used, modified, + and distributed under the terms of the gPhoto project license, COPYING. + By continuing to use, modify, or distribute this file you indicate that + you have read the license, understand and accept it fully. + + THIS SOFTWARE IS PROVIDED AS IS AND COME WITH NO WARRANTY OF ANY KIND, + EITHER EXPRESSED OR IMPLIED. IN NO EVENT WILL THE COPYRIGHT HOLDER BE + LIABLE FOR ANY DAMAGES RESULTING FROM THE USE OF THIS SOFTWARE. + + Note: + + This is a Panasonic DC1580 camera gPhoto library source code. +*/ + +#include <stdlib.h> +#include <sys/time.h> +#include <sys/stat.h> +#include <unistd.h> +#include <memory.h> +#include <string.h> +#include "dc.h" +#include "dc1580.h" + +#ifndef __FILE__ +# define __FILE__ "dc1580.c" +#endif + +/******************************************************************************/ + +/* Internal utility functions */ + +/* dsc_sendcmd - send command with data to DSC */ + +int dsc_sendcmd(dsc_t *dsc, int cmd, int data, int sequence) { + + char databuf[16]; + + DBUG_PRINT_3("Sending command: %i, data: %i, sequence: %i", cmd, data, sequence); + + memset(databuf, 0, 16); + + databuf[0] = 0x08; + databuf[1] = sequence; + databuf[2] = 0xff - sequence; + databuf[3] = cmd; + databuf[4] = data; + databuf[14] = cmd + data - 1; /* checksum? */ + + return gpio_write(dsc->dev, databuf, 16); +} + +/* dsc_retrcmd - retrieve command and its data from DSC */ + +int dsc_retrcmd(dsc_t *dsc) { + + int result = GP_ERROR; + int s; + + s = gpio_read(dsc->dev, dsc->buf, 16); + if (glob_debug) + dsc_dumpmem(dsc->buf, s); + if (s != 16 || dsc->buf[DSC_BUF_BASE] != 0x08 || + dsc->buf[DSC_BUF_SEQ] != 0xff - (uint8_t)dsc->buf[DSC_BUF_SEQC]) { + DBUG_RETURN(EDSCBADRSP, dsc_retrcmd, GP_ERROR); + /* bad response */ + } + else + result = dsc->buf[DSC_BUF_CMD]; + + DBUG_PRINT_1("Retrieved command: %d", result); + + return result; +} + +/* dsc_connect - try hand shake with camera and establish connection */ + +int dsc_connect(dsc_t *dsc, int speed) { + + DBUG_PRINT("Connecting a camera."); + + if (dsc_handshake(dsc, speed) != GP_OK) + return GP_ERROR; + + dsc_sendcmd(dsc, DSC_CMD_CONNECT, 0, 0); + + if (dsc_retrcmd(dsc) != DSC_RSP_OK) + DBUG_RETURN(EDSCBADRSP, dsc_connect, GP_ERROR); + /* bad response */ + + DBUG_PRINT("Camera connected successfully"); + + return GP_OK; +} + +/* dsc_disconnect - reset camera, free buffers and close files */ + +int dsc_disconnect(dsc_t *dsc) +{ + DBUG_PRINT("Disconnecting the camera."); + + dsc_sendcmd(dsc, DSC_CMD_RESET, 0, 0); + + if (dsc_retrcmd(dsc) != DSC_RSP_OK) + DBUG_RETURN(EDSCNRESET, dsc_disconnect, GP_ERROR) + /* could not reset camera */ + else + sleep(DSC_PAUSE); /* let camera to redraw its screen */ + + DBUG_PRINT("Camera disconnected."); + + return GP_OK; +} + +/* dsc_getindex - retrieve the number of images stored in camera memory */ + +int dsc_getindex(dsc_t *dsc) { + + int result = GP_ERROR; + + DBUG_PRINT("Retrieving the index."); + + dsc_sendcmd(dsc, DSC_CMD_GET_INDEX, 0, 0); + + if (dsc_retrcmd(dsc) == DSC_RSP_INDEX) + result = dsc->buf[DSC_BUF_DATA]; + else + DBUG_RETURN(EDSCBADRSP, dsc_getindex, GP_ERROR); + /* bad response */ + + DBUG_PRINT_1("Index retrieved, number of images: %d", result); + + return result; +} + +/* dsc_delete - delete image #index from camera memory */ + +int dsc_delete(dsc_t *dsc, int index) { + + int s; + + DBUG_PRINT_1("Deletting the image of index: %d", index); + + if (index < 1 || index > DSC_MAXIMAGE) + DBUG_RETURN(EDSCBADNUM, dsc_delete, GP_ERROR); + /* bad image number */ + + dsc_sendcmd(dsc, DSC_CMD_DELETE, index, 0); + + if (dsc_retrcmd(dsc) != DSC_RSP_OK) + DBUG_RETURN(EDSCBADRSP, dsc_delete, GP_ERROR); + /* bad response */ + + DBUG_PRINT_1("Image index: %d deleted.", index); + + return GP_OK; +} + +/* dsc_selectimage - select image to download, return its size */ + +int dsc_selectimage(dsc_t *dsc, int index, int thumbnail) +{ + int size = 0; + + DBUG_PRINT_2("Selecting the image of index: %i, thumbnail: %i", index, thumbnail); + + if (index < 1 || index > DSC_MAXIMAGE) + DBUG_RETURN(EDSCBADNUM, dsc_selectimage, GP_ERROR); + /* bad image number */ + + if (thumbnail == DSC_THUMBNAIL) + dsc_sendcmd(dsc, DSC_CMD_THUMB, index, 0); + else + dsc_sendcmd(dsc, DSC_CMD_SELECT, index, 0); + + if (dsc_retrcmd(dsc) != DSC_RSP_IMGSIZE) + DBUG_RETURN(EDSCBADNUM, dsc_selectimage, GP_ERROR); + /* bad image number */ + + size = (u_int32_t)0 | + ((u_int8_t)dsc->buf[6] << 16) | + ((u_int8_t)dsc->buf[5] << 8); + + DBUG_PRINT_3("Selected image index: %i, thumbnail: %i, size: %i", index, thumbnail, size); + + return size; +} + +/* gpio_readimageblock - read #block block (1024 bytes) of an image into buf */ + +int dsc_readimageblock(dsc_t *dsc, int block, char *buffer) +{ + int size = DSC_BLOCKSIZE; /* always returns 1024 bytes */ + + DBUG_PRINT_1("Reading block: %i", block); + + dsc_sendcmd(dsc, DSC_CMD_GET_DATA, block, block); + + if (gpio_read(dsc->dev, dsc->buf, 4) != 4 || + (uint8_t)dsc->buf[0] != 1 || + (uint8_t)dsc->buf[1] != block || + (uint8_t)dsc->buf[3] != 5) + DBUG_RETURN(EDSCBADRSP, dsc_readimageblock, GP_ERROR); + /* bad response */ + + if (gpio_read(dsc->dev, buffer, size) != size) + DBUG_RETURN(EDSCNOANSW, dsc_readimageblock, GP_ERROR); + /* no answer from camera */ + + /* checksum */ + if (gpio_read(dsc->dev, dsc->buf + 4, 2) != 2) + DBUG_RETURN(EDSCNOANSW, dsc_readimageblock, GP_ERROR); + /* no answer from camera */ + + DBUG_PRINT_2("Block: %d of size: %d read in.", block, size); + + return size; +} + +/* dsc_readimage - read #index image or thumbnail and return its contents */ + +char *dsc_readimage(dsc_t *dsc, int index, int thumbnail, int *size) { + + char kind[16]; + int blocks, i; + char str[80]; + char *buffer = NULL; + + DBUG_PRINT_2("Reading the image of index: %i, thumbnail: %i", index, thumbnail); + + if ((*size = dsc_selectimage(dsc, index, thumbnail)) < 0) + return NULL; + + if (thumbnail == DSC_THUMBNAIL) + strcpy(kind, "thumbnail"); + else + strcpy(kind, "image"); + + sprintf(str, "Downloading %s #%i of size: %d bytes\n", + kind, index, *size); + gp_status(str); + gp_progress(0.00); + + if (!(buffer = (char*)malloc(*size))) { + DBUG_PRINT_1("Failed to allocate memory for %s data.", kind); + sprintf(str, "Failed to allocate memory for %s data.", kind); + gp_message(str); + return NULL; + } + + blocks = (*size - 1)/DSC_BLOCKSIZE + 1; + + for (i = 0; i < blocks; i++) { + if (dsc_readimageblock(dsc, i, &buffer[i*DSC_BLOCKSIZE]) == -1) { + DBUG_PRINT_1("Error during %s transfer.", kind); + sprintf(str, "Error during %s transfer.", kind); + gp_messageg(str); + free(buffer); + return NULL; + } + gp_progress((float)(i+1)/(float)blocks); + } + + /* gp_progress(0.00); */ /* reset progress bar or not? */ + + return buffer; +} + +/* dsc_setimageres - set image resolution to res */ +/* 0 - normal */ +/* 1 - fine */ +/* 2 - superfine */ + +int dsc_setimageres(dsc_t *dsc, dsc_quality_t res) +{ + DBUG_PRINT_1("Setting image resolution to: %i", res); + + dsc_sendcmd(dsc, DSC_CMD_SET_RES, res, res); + + if (dsc_retrcmd(dsc) != DSC_RSP_OK) + DBUG_RETURN(EDSCBADRSP, dsc_setimageres, GP_ERROR); + /* bad response */ + + DBUG_PRINT_1("Image resolution set to: %i", res); + + return GP_OK; +} + +/* gpio_writeimage - write an image to camera memory, size bytes at buffer */ + +int dsc_writeimage(dsc_t *dsc, char *buffer, int size) +{ + char databuf[8]; + + DBUG_PRINT_1("Writing an image of size: %i", size); + + memset(databuf, 0, 8); + + databuf[0] = (u_int8_t)(0x000000ff & size); + databuf[1] = (u_int8_t)(0x0000ff00 & size); + databuf[2] = (u_int8_t)(0x00ff0000 & size); + databuf[3] = (u_int8_t)(0xff000000 & size); + databuf[4] = DSC_CMD_SEND_DATA; + + if (glob_debug) + dsc_dumpmem(databuf, 5); + + if (gpio_write(dsc->dev, databuf, 5) != GP_OK) + DBUG_RETURN(EDSCSERRNO, dsc_writeimage, GP_ERROR); + /* see errno value */ + + if (gpio_write(dsc->dev, buffer, size) != GP_OK) + DBUG_RETURN(EDSCSERRNO, dsc_writeimage, GP_ERROR) + /* see errno value */ + else + return GP_OK; +} + +/* dsc_preview - ??? */ + +int dsc_preview(dsc_t *dsc, int index) +{ + if (index < 1 || index > DSC_MAXIMAGE) + DBUG_RETURN(EDSCBADNUM, dsc_preview, GP_ERROR); + /* bad image number */ + + dsc_sendcmd(dsc, DSC_CMD_PREVIEW, index, 0); + + if (dsc_retrcmd(dsc) != DSC_RSP_OK) + DBUG_RETURN(EDSCNOANSW, dsc_preview, GP_ERROR); + /* no answer from camera */ + + return GP_OK; +} + +/******************************************************************************/ + +/* Library interface functions */ + +int camera_id (char *id) { + + strcpy(id, "panasonic-dc1580"); + + return (GP_OK); +} + +int camera_debug_set (int onoff) { + + glob_debug = onoff; + return (GP_OK); +} + +int camera_abilities (CameraAbilities *abilities, int *count) { + + *count = 1; + + /* Fill in each camera model's abilities */ + /* Make separate entries for each conneciton type (usb, serial, etc...) + if a camera supported multiple ways. */ + + strcpy(abilities[0].model, "Panasonic DC1580"); + abilities[0].serial = 1; + abilities[0].parallel = 0; + abilities[0].usb = 0; + abilities[0].ieee1394 = 0; + abilities[0].speed[0] = 9600; + abilities[0].speed[1] = 19200; + abilities[0].speed[2] = 38400; + abilities[0].speed[3] = 57600; + abilities[0].speed[4] = 115200; + abilities[0].speed[5] = 0; + abilities[0].capture = 0; + abilities[0].config = 0; + abilities[0].file_delete = 1; + abilities[0].file_preview = 1; + abilities[0].file_put = 1; + + return (GP_OK); +} + +int camera_init (CameraInit *init) { + + dsc_error dscerror; + + DBUG_PRINT("Initializing Panasonic DC series camera."); + + if (dsc && dsc->dev) { + gpio_close(dsc->dev); + gpio_free(dsc->dev); + } + + /* first of all allocate memory for a dsc struct */ + if ((dsc = (dsc_t*)malloc(sizeof(dsc_t))) == NULL) { + dscerror.lerror = EDSCSERRNO; + dscerror.lerrno = errno; + DBUG_PRINT_ERROR(dscerror, camera_init); + return GP_ERROR; + } + + dsc->dev = gpio_new(GPIO_DEVICE_SERIAL); + + gpio_set_timeout(dsc->dev, 5000); + strcpy(dsc->settings.serial.port, init->port_settings.path); + dsc->settings.serial.speed = 9600; /* hand shake speed */ + dsc->settings.serial.bits = 8; + dsc->settings.serial.parity = 0; + dsc->settings.serial.stopbits = 1; + + gpio_set_settings(dsc->dev, dsc->settings); + + gpio_open(dsc->dev); + + strcpy(dsc->model, init->model); + + /* allocate memory for a dsc read/write buffer */ + if ((dsc->buf = (char *)malloc(sizeof(char)*(256))) == NULL) { + dscerror.lerror = EDSCSERRNO; + dscerror.lerrno = errno; + DBUG_PRINT_ERROR(dscerror, camera_init); + free(dsc); + return GP_ERROR; + } + + return dsc_connect(dsc, init->port_settings.speed); + /* connect with selected speed */ +} + +int camera_exit () { + + dsc_disconnect(dsc); + + if (dsc->dev) { + gpio_close(dsc->dev); + gpio_free(dsc->dev); + } + + return (GP_OK); +} + +int camera_folder_list(char *folder_name, CameraFolderInfo *list) { + + strcpy(list[0].name, "<photos>"); + + return (GP_OK); +} + +int camera_folder_set(char *folder_name) { + + return (GP_OK); +} + +int camera_file_count () { + + return dsc_getindex(dsc); +} + +int camera_file_get (int file_number, CameraFile *file) { + + /**********************************/ + /* file_number now starts at 0!!! */ + /**********************************/ + + int size; + + DBUG_PRINT_1("Retrieving an image %i from camera", file_number + 1); + + sprintf(file->name, "dsc%04i.jpg", file_number + 1); + file->type = GP_FILE_JPEG; + + if (!(file->data = dsc_readimage(dsc, file_number + 1, DSC_FULLIMAGE, &size))) + return GP_ERROR; + + file->size = size; + + return (GP_OK); +} + +int camera_file_get_preview (int file_number, CameraFile *preview) { + + /**********************************/ + /* file_number now starts at 0!!! */ + /**********************************/ + + int size; + + DBUG_PRINT_1("Retrieving a thumbnail %d from camera", file_number + 1); + + sprintf(preview->name, "dsc%04i-thumbnail.jpg", file_number + 1); + preview->type = GP_FILE_JPEG; + + if (!(preview->data = dsc_readimage(dsc, file_number + 1, DSC_THUMBNAIL, &size))) + return GP_ERROR; + + preview->size = size; + + return (GP_OK); +} + +int camera_file_put (CameraFile *file) { + + char str[80]; + + if (file->type != GP_FILE_JPEG) { + DBUG_PRINT("JPEG image format allowed only."); + sprintf(str, "JPEG image format allowed only."); + gp_message(str); + return GP_ERROR; + } + if (file->size > sizeof(uint32_t)) { + DBUG_PRINT_1("File size is %i. Too big to fit in the camera memory.", file->size); + sprintf(str, "File size is %i. Too big to fit in the camera memory.", file->size); + gp_message(str); + return GP_ERROR; + } + + if (dsc_setimageres(dsc, fine)) + return dsc_writeimage(dsc, file->data, file->size); + else + return GP_ERROR; +} + +int camera_file_delete (int file_number) { + + return dsc_delete(dsc, file_number + 1); +} + +int camera_config_get (CameraWidget *window) { + + return GP_ERROR; +} + +int camera_config_set (CameraSetting *setting, int count) { + + return (GP_ERROR); +} + +int camera_capture (CameraFileType type) { + + return (GP_ERROR); +} + +int camera_summary (char *summary) { + + strcpy(summary, "Summary Not Available"); + + return (GP_OK); +} + +int camera_manual (char *manual) { + + strcpy(manual, "Manual Not Available"); + + return (GP_OK); +} + +int camera_about (char *about) { + + strcpy(about, + "Panasonic PV-DC1580 gPhoto library\n" + "Mariusz Zynel <mariusz@mizar.org>\n\n" + "Based on dc1000 program written by\n" + "Fredrik Roubert <roubert@df.lth.se> and\n" + "Galen Brooks <galen@nine.com>."); + return (GP_OK); +} + +/* End of dc1580.c */ diff --git a/camlibs/panasonic/dc1580.h b/camlibs/panasonic/dc1580.h new file mode 100644 index 000000000..518c7fb3d --- /dev/null +++ b/camlibs/panasonic/dc1580.h @@ -0,0 +1,53 @@ +/* + $Id$ + + Copyright (c) 2000 Mariusz Zynel <mariusz@mizar.org> (gPhoto port) + Copyright (C) 2000 Fredrik Roubert <roubert@df.lth.se> (idea) + Copyright (C) 1999 Galen Brooks <galen@nine.com> (DC1580 code) + + This file is part of the gPhoto project and may only be used, modified, + and distributed under the terms of the gPhoto project license, COPYING. + By continuing to use, modify, or distribute this file you indicate that + you have read the license, understand and accept it fully. + + THIS SOFTWARE IS PROVIDED AS IS AND COME WITH NO WARRANTY OF ANY KIND, + EITHER EXPRESSED OR IMPLIED. IN NO EVENT WILL THE COPYRIGHT HOLDER BE + LIABLE FOR ANY DAMAGES RESULTING FROM THE USE OF THIS SOFTWARE. + + Note: + + This is a Panasonic DC1580 camera gPhoto library header file. +*/ + +/* DC1580 command codes */ + +#define DSC_CMD_SEND_DATA 0x00 +#define DSC_CMD_SET_BAUD 0x04 +#define DSC_CMD_GET_INDEX 0x07 +#define DSC_CMD_OK 0x08 +#define DSC_CMD_CONNECT 0x10 +#define DSC_CMD_DELETE 0x11 +#define DSC_CMD_PREVIEW 0x14 +#define DSC_CMD_SET_RES 0x15 +#define DSC_CMD_THUMB 0x16 +#define DSC_CMD_SELECT 0x1a +#define DSC_CMD_GET_DATA 0x1e +#define DSC_CMD_RESET 0x1f + +/* DC1580 response codes */ + +#define DSC_RSP_DATA 0x00 +#define DSC_RSP_OK 0x01 +#define DSC_RSP_MODEL 0x03 +#define DSC_RSP_INDEX 0x08 +#define DSC_RSP_IMGSIZE 0x1d + +/* DC1580 response buffer offsets, 0 - first byte in buffer */ + +#define DSC_BUF_BASE 0 +#define DSC_BUF_SEQ 1 +#define DSC_BUF_SEQC 2 +#define DSC_BUF_CMD 3 +#define DSC_BUF_DATA 4 + +/* End of dc1580.h */ |