summaryrefslogtreecommitdiff
path: root/camlibs/aox/aox.c
blob: 95b365a5cba50204a0275d953fdd6e5461c430bc (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
/* aox.c
 *
 * Copyright (C) 2003 Theodore Kilgore <kilgota@auburn.edu>
 *
 * 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., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>

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

#include "aox.h"

#define GP_MODULE "aox" 

#define WRITE gp_port_usb_msg_write
#define READ  gp_port_usb_msg_read


int aox_init (GPPort *port, Model *model, Info *info) 
{
	unsigned char c[4];
	unsigned char hi[2];
	unsigned char lo[2];
	memset(c,0,sizeof(c));
	memset (hi,0,2);
	memset (lo,0,2);

	GP_DEBUG("Running aox_init\n");

	READ(port, 1, 0, 0, c,0x10);
	WRITE(port, 8, 1, 0, c, 0x10);
        READ(port, 0xff, 0x07, 0xfffc, c, 4); /* Returns version number, apparently */	
        READ(port, 0x06, 0x0, 0x0, c, 2);	
        READ(port, 0x04, 0x1, 0x1, lo, 2);	
	GP_DEBUG("%02x %02x number of lo-res pics\n", lo[0],lo[1]); 
	/* We need to keep this information. We presume that 
	 * more than 255 pictures is impossible with this camera. 
	 */
	memcpy (info, &lo[0], 1);
        READ(port, 0x04, 0x2, 0x1, c, 2);	
        READ(port, 0x04, 0x3, 0x1, c, 2);	
        READ(port, 0x04, 0x4, 0x1, c, 2);	
        READ(port, 0x04, 0x5, 0x1, hi, 2);	
	GP_DEBUG("%02i %02i number of hi-res pics\n", hi[0], hi[1]); 
	/* This information, too. */
	memcpy (info +1, &hi[0], 1);
        READ(port, 0x04, 0x6, 0x1, c, 2);	/* "Completion" flag.*/
	GP_DEBUG("info[0] = 0x%x\n", info[0]);
	GP_DEBUG("info[1] = 0x%x\n", info[1]);
	GP_DEBUG("Leaving aox_init\n");

        return GP_OK;
}

int aox_get_num_lo_pics      (Info *info) 
{
	GP_DEBUG("Running aox_get_num_lo_pics\n");
	return info[0];
}
	
int aox_get_num_hi_pics      (Info *info) 
{
	GP_DEBUG("Running aox_get_num_hi_pics\n");
	return info[1];
}

int aox_get_picture_size  (GPPort *port, int lo, int hi, int n, int k) 
{
	GP_DEBUG("Running aox_get_picture_size\n");

	unsigned char c[4];
        unsigned int size;
	memset (c,0,4);


	if ( ( (lo) && ( n ==k ) && (k ==0)) ) {
	    	READ(port, 0x04, 0x1, 0x1, c, 2);	
	}
	if ( ( (hi) && ( n < k ) && (n == 0))   ) {
	        READ(port, 0x04, 0x5, 0x1, c, 2);	
	}
	READ(port, 0x05, n+1, 0x1, c, 4);	       
	size = (int)c[0] + (int)c[1]*0x100 + (int)c[2]*0x10000;
	GP_DEBUG(" size of picture %i is 0x%x\n", k, size);
	if ( (size >= 0xfffff ) ) {return GP_ERROR;} 
	GP_DEBUG("Leaving aox_get_picture_size\n");
	
	return size;
}

int aox_read_data         (GPPort *port, char *data, int size) 
{ 
	int MAX_BULK = 0x1000;

	while(size > 0) {
		int len = (size>MAX_BULK)?MAX_BULK:size;
	        gp_port_read  (port, data, len); /* 0x84 = EP IN NEEDED HERE.*/
    		data += len;
		size -= len;
	}
        return 1;
}

int aox_read_picture_data (GPPort *port, char *data, int size, int n) {
	char c[4];
	memset(c,0,4);

    	READ(port, 0x06, n+1, 0x1, c, 4);	
        aox_read_data (port, data , size);
		
        return GP_OK;
}