summaryrefslogtreecommitdiff
path: root/camlibs/stv0674/library.c
blob: 0fcd546b62739435aeb0e08f04279ecbdf14e29d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
 * STV0674 Vision Camera Chipset Driver
 * Copyright 2000 Adam Harrison <adam@antispin.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301  USA
 */

#include "config.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <gphoto2/gphoto2.h>
#include <gphoto2/gphoto2-port.h>

#include "libgphoto2/i18n.h"

#include "stv0674.h"
#include "library.h"


int stv0674_ping(GPPort *port)
{
    int ret;
    unsigned char reply[4];

    ret = gp_port_usb_msg_read (port, CMDID_PING, 0, 0, (char *)reply, 1);
    if (ret < GP_OK)
	return ret;

    if(reply[0] != 0)
    {
	printf("CMDID_PING successful, but returned bad values?\n");
	return GP_ERROR_IO;
    }

    return GP_OK;

}

int stv0674_file_count(GPPort *port, int *count)
{
    int ret;
    unsigned char reply[4];

    ret = gp_port_usb_msg_read (port, CMDID_ENUMERATE_IMAGES, 0, 0, (char *)reply, 4);
    if (ret < GP_OK)
	return ret;


    *count= ((reply[3]) | (reply[2]<<8) | (reply[1]<<16) | (reply[0]<<24));

    return GP_OK;
}

/**
 * Get image
 */
int stv0674_get_image_raw(GPPort *port, int image_no, CameraFile *file)
{
    return GP_OK;
}

static int setval(unsigned char* where,unsigned long val)
{
    where[3]=(val & 0xff);
    where[2]=((val >> 8) & 0xff);
    where[1]=((val >> 16) & 0xff);
    where[0]=((val >> 24) & 0xff);
    return 0;
}


int stv0674_get_image(GPPort *port, int image_no, CameraFile *file)
{
    unsigned char header[0x200];/*block for header */
    int size;

    int whole,remain;

    int current;

    int ret;
    unsigned char imagno[8];
    unsigned char reply[4];
    unsigned char * data;

    memset(imagno,0,8);

    image_no+=2;

    setval(imagno,image_no);


    ret = gp_port_usb_msg_write (port, CMDID_SET_IMAGE, 0, 0, (char *)imagno, 4);
    if (ret < GP_OK)
	return ret;

    ret = gp_port_usb_msg_read (port, CMDID_IHAVENOIDEA, 0, 0, (char *)reply, 2);
    if (ret < GP_OK)
	return ret;

    setval(&imagno[4],0x200);/* we want 512 bytes */

    ret = gp_port_usb_msg_write (port,
				 CMDID_READ_IMAGE,
				 READ_IMAGE_VALUE_RESET,
				 0,
				 (char *)imagno,
				 8);
    if (ret < GP_OK)
	return ret;

    gp_port_read(port, (char *)header, 0x200);

    size=(header[0x47]<<8) | header[0x48];

    /*create data block */
    data=malloc(size);
    if (!data)
	return GP_ERROR_NO_MEMORY;

    setval(&imagno[4],0x1000);/* we want 4096 bytes */

    whole=size / 0x1000;
    remain=size % 0x1000;


    for(current=0;current<whole;current+=1)
    {


	ret = gp_port_usb_msg_write (port,
				     CMDID_READ_IMAGE,
				     READ_IMAGE_VALUE_READ,
				     0,
				     (char *)imagno,
				     8);
	if (ret < GP_OK) {
	    free (data);
	    return ret;
	}

	gp_port_read(port, (char *)&data[current*0x1000], 0x1000);
    }

    if(remain)
    {
	setval(&imagno[4],remain);/* we want remaining bytes */
	ret = gp_port_usb_msg_write (port,
				     CMDID_READ_IMAGE,
				     READ_IMAGE_VALUE_READ,
				     0,
				     (char *)imagno,
				     8);
	if (ret < GP_OK) {
	    free (data);
	    return ret;
	}

	gp_port_read(port, (char *)&data[current*0x1000], remain);

    }


    gp_file_append(file, (char *)data, size);
    free(data);

    ret = gp_port_usb_msg_write (port, CMDID_FINISH_READ, 0, 0, (char *)imagno, 4);
    if (ret < GP_OK)
	return ret;

    return GP_OK;
}

int stv0674_get_image_preview(GPPort *port, int image_no, CameraFile *file)
{
	return GP_OK;
}

int stv0674_capture(GPPort *port)
{
	return GP_OK;
}


int stv0674_capture_preview(GPPort *port, char **data, int *size)
{
	return GP_OK;
}


int stv0674_delete_all(GPPort *port) {
    /*    return stv0674_try_cmd(port,CMDID_SET_IMAGE_INDEX,0,NULL,0);*/
	return GP_OK;
}

int stv0674_summary(GPPort *port, char *txt)
{
    return GP_OK;
}