File: konica_qm100.c

package info (click to toggle)
gphoto 0.3.5-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,636 kB
  • ctags: 1,973
  • sloc: ansic: 23,035; sh: 4,851; makefile: 175
file content (201 lines) | stat: -rw-r--r-- 5,388 bytes parent folder | download
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
/* Konica QM100 Camera Functions */

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <gdk_imlib.h>
#include <gdk/gdk.h>

#include "defs.h"
#include "transmission.h"
#include "open.h"
#include "close.h"
#include "formatCF.h"
#include "erasePic.h"
#include "savePic.h"
#include "getPicInfo.h"
#include "setSpeed.h"
#include "takePic.h"
#include "saveThumb.h"
#include "../src/gphoto.h"
#include "konica_qm100.h"

int konica_qm100_initialize()
{
  return(1);
}

int konica_qm100_number_of_pictures ()
{
  qm100_packet_block packet;
  char cmd_status[QM100_STATUS_LEN]=QM100_STATUS;
  int serialdev;
  
  serialdev = qm100_open(serial_port);
  packet = qm100_transmit(serialdev, cmd_status, sizeof(cmd_status));
  qm100_close(serialdev);
  return PICTURE_COUNT;
}

int konica_qm100_take_picture() {
  int serialdev;
  qm100_packet_block packet;
  char cmd_status[QM100_STATUS_LEN]=QM100_STATUS;
  
  serialdev = qm100_open(serial_port);
  qm100_setSpeed(serialdev, B115200);
  
  qm100_takePic(serialdev);
  qm100_setSpeed(serialdev, B9600);

  packet = qm100_transmit(serialdev, cmd_status, sizeof(cmd_status));

  qm100_close(serialdev);

  return PICTURE_COUNT;
}

struct Image *konica_qm100_get_picture (int picNum, int thumbnail)
{
  int serialdev;
  int pid;
  char tempName[1024], rm[1024];

  struct Image *im;
  FILE *fp;
  int imagesize;
  char *imagedata;

  pid = getpid();

  serialdev = qm100_open(serial_port);
  qm100_setSpeed(serialdev, B115200);

  sprintf(tempName, "%s/gphoto-konica-%i.jpg", gphotoDir, picNum);

  picNum = qm100_getRealPicNum(serialdev, picNum);

  if (thumbnail) {
    qm100_saveThumb(serialdev, tempName, picNum);
  } else {
    qm100_savePic(serialdev, tempName, picNum);
  }
  
  qm100_setSpeed(serialdev, B9600);
  qm100_close(serialdev); 
	/* Updates    -Scott */
	fp = fopen(tempName, "r");
	fseek(fp, 0, SEEK_END);
	imagesize = ftell(fp);
	rewind(fp);
	imagedata = (char *)malloc(sizeof(char)*imagesize);
	fread(imagedata, (size_t)imagesize, (size_t)sizeof(char),fp);
	fclose(fp);
	im = (struct Image*)malloc(sizeof(struct Image));
	im->image = imagedata;
	im->image_size = imagesize;
	im->image_info_size = 0;
	strcpy(im->image_type, "jpg");
  remove (tempName);
  return (im);
}

int konica_qm100_delete_picture (int picNum)
{
  int serialdev;
  serialdev = qm100_open(serial_port);
  picNum = qm100_getRealPicNum(serialdev, picNum);
  qm100_erasePic(serialdev, picNum);
  qm100_close(serialdev);
  return (1);
}

int konica_qm100_formatCF()
{
  int serialdev;
  serialdev = qm100_open(serial_port);
  qm100_formatCF(serialdev);
  qm100_close(serialdev);
  return (1);
}

struct Image *konica_qm100_get_preview () {
  return(0);
}

int konica_qm100_configure ()
{
  GtkWidget *dialog;
  GtkWidget *button;
  GtkWidget *buttonbox;

  /* Set the Window Dialog up */
  dialog = gtk_window_new(GTK_WINDOW_DIALOG);
  gtk_window_set_title(GTK_WINDOW(dialog), "Camera Configuration");
  gtk_window_position(GTK_WINDOW(dialog), GTK_WIN_POS_MOUSE);

  /* Set the buttonbox up */
  buttonbox = gtk_hbutton_box_new();
  gtk_container_border_width(GTK_CONTAINER(buttonbox), 10);

  /* One nice button which calls formatCf please... */
  button = gtk_button_new_with_label ( "Format CF Card" );
  gtk_signal_connect ( GTK_OBJECT(button), "clicked",
		       GTK_SIGNAL_FUNC(konica_qm100_formatCF),
		       NULL);
  gtk_signal_connect_object ( GTK_OBJECT(button), "clicked",
			      GTK_SIGNAL_FUNC(gtk_widget_destroy),
			      GTK_OBJECT(dialog) );
  gtk_container_add ( GTK_CONTAINER(buttonbox), GTK_WIDGET(button));
  gtk_widget_show ( button );

  /* Another to kill this whole window if you will Sir */
  button = gtk_button_new_with_label ( " Cancel " );
  gtk_signal_connect_object ( GTK_OBJECT(button), "clicked",
			      GTK_SIGNAL_FUNC(gtk_widget_destroy),
			      GTK_OBJECT(dialog) );
  gtk_container_add ( GTK_CONTAINER(buttonbox), GTK_WIDGET(button));
  gtk_widget_show ( button );

  /* Stick the buttonbox to the window and show it all */
  gtk_container_add ( GTK_CONTAINER(dialog), GTK_WIDGET(buttonbox));
  gtk_widget_show( buttonbox );
  gtk_widget_show ( dialog );
  
  return(1);
}

char summary_string[500];

char *konica_qm100_summary()
{
  char cmd_status[QM100_STATUS_LEN]=QM100_STATUS;
  int serialdev;
  qm100_packet_block packet;
  
  update_progress(0);
  serialdev = qm100_open(serial_port);
  packet = qm100_transmit(serialdev, cmd_status, sizeof(cmd_status));
  qm100_close(serialdev);
  update_progress(1);
  sprintf(summary_string, "This camera is a Konica QM100 or Hewlett Packard C20/C30\nIt has taken %d pictures and currently contains %d picture(s)\nThe time according to the Camera is %d:%d:%d %d/%d/%d",COUNTER, PICTURE_COUNT, TIME_HOUR,TIME_MIN,TIME_SEC,TIME_DAY,TIME_MON,TIME_YEAR);
  return (summary_string);
}

char *konica_qm100_description()
{
  return("Konica QM-100 Digital Camera gPhoto Plugin (C) 1999 Phill Hugo / Jesper Skov Works for QM100 / HP C20 / HP C30");
}

/* Declare the camera function pointers */

struct _Camera konica_qm100 = {konica_qm100_initialize,
			       konica_qm100_get_picture,
			       konica_qm100_get_preview,
			       konica_qm100_delete_picture,
			       konica_qm100_take_picture,
			       konica_qm100_number_of_pictures,
			       konica_qm100_configure,
			       konica_qm100_summary,
			       konica_qm100_description};