gphoto4ruby 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/CHANGELOG.rdoc +5 -0
  2. data/README.rdoc +24 -37
  3. data/example.rb +17 -29
  4. data/ext/gphoto4ruby.c +27 -11
  5. metadata +3 -3
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.1.5
2
+
3
+ * GPhoto2::Camera.ports now returns only ports with cameras and
4
+ doesn't return empty array if there is one camera connected.
5
+
1
6
  == 0.1.4
2
7
 
3
8
  * Added option to download first and last files with save method
data/README.rdoc CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == Summary
4
4
 
5
- GPhoto4Ruby is Ruby wrapping around libgphoto2 C library
5
+ GPhoto4Ruby is Ruby wrapping around gphoto2 C library
6
6
  (See http://gphoto.org for more information on libgphoto2 and gphoto2).
7
7
  It maps a digital camera to Ruby object and allows operating it by
8
8
  calling object methods.
@@ -19,7 +19,7 @@ calling object methods.
19
19
 
20
20
  * On Ubuntu 8.04 it is:
21
21
 
22
- sudo apt-get install gphoto2
22
+ sudo apt-get install gphoto2 libgphoto2-2-dev
23
23
 
24
24
  * On Mac OS X gphoto2 is installed through DarwinPorts
25
25
 
@@ -54,50 +54,38 @@ connected through usb in PTP mode.
54
54
 
55
55
  require "rubygems"
56
56
  require "gphoto4ruby"
57
-
57
+
58
58
  ports = GPhoto2::Camera.ports
59
- if ports.empty?
60
-
61
- # ports array can be empty if there is only one camera plugged in
62
- # or there are no cameras connected to the computer
63
- # assuming there is one
64
- c = GPhoto2::Camera.new()
65
-
66
- # list available configuration items with current values and lists
67
- # of allowed values
68
- c.config.each_key do |cfg_key|
69
- puts cfg_key + " value is: " + c.config[cfg_key].to_s # or c[cfg_key].to_s
70
- puts "values available are: " + c[cfg_key, :all].inspect
59
+ if ports.any?
60
+ puts ports.length.to_s + "cameras connected"
61
+ cams = []
62
+ ports.each do |port|
63
+ c = GPhoto2::Camera.new(port)
64
+ puts "camera in port: " + port
65
+ c.config.each do |key, value|
66
+ puts key + " value is: " + value.to_s
67
+ puts "values available are: " + c[key, :all].inspect
68
+ end
69
+ cams.push c
71
70
  end
72
71
 
73
72
  # capture image
74
- c.capture
75
-
73
+ cams.first.capture
74
+
76
75
  # now camera virtual path is in the folder with images
77
76
  # list image file names
78
- puts "files on camera: " + c.files.inspect
79
-
77
+ puts "files on camera: " + cams.first.files.inspect
78
+
80
79
  # just an example of camera browsing
81
- puts "some folder stuff: " + c.folder_up.subfolders.inspect
82
-
80
+ puts "some folder stuff: " + cams.first.folder_up.subfolders.inspect
81
+
83
82
  # save preview of captured image in the current directory on hard drive
84
- c.capture.save :type => :preview, :new_name => "PREVIEW.JPG"
85
-
83
+ cams.first.capture.save :type => :preview, :new_name => "PREVIEW.JPG"
84
+
86
85
  # save captured file in the current directory on hard drive and delete
87
86
  # it from camera
88
- c.capture.save.delete
89
- else
90
- puts ports.length.to_s + "cameras connected"
91
- cams = []
92
- ports.each do |port|
93
- c = GPhoto2::Camera.new(port)
94
- puts "camera in port: " + port
95
- c.config.each_key do |cfg_key|
96
- puts cfg_key + " value is: " + c[cfg_key].to_s
97
- puts "values available are: " + c[cfg_key, :all].inspect
98
- end
99
- cams.push c
100
- end
87
+ cams.first.capture.save.delete
88
+
101
89
  # to capture image with all attached cameras simultaneously use:
102
90
  cams.each_index do |index|
103
91
  if index < cams.length - 1
@@ -107,7 +95,6 @@ connected through usb in PTP mode.
107
95
  end
108
96
  end
109
97
  end
110
-
111
98
  == Contact
112
99
 
113
100
  neq4 company:: http://neq4.com
data/example.rb CHANGED
@@ -2,48 +2,36 @@ require "rubygems"
2
2
  require "gphoto4ruby"
3
3
 
4
4
  ports = GPhoto2::Camera.ports
5
- if ports.empty?
6
-
7
- # ports array can be empty if there is only one camera plugged in
8
- # or there are no cameras connected to the computer
9
- # assuming there is one
10
- c = GPhoto2::Camera.new()
11
-
12
- # list available configuration items with current values and lists
13
- # of allowed values
14
- c.config.each_key do |cfg_key|
15
- puts cfg_key + " value is: " + c.config[cfg_key].to_s # or c[cfg_key].to_s
16
- puts "values available are: " + c[cfg_key, :all].inspect
5
+ if ports.any?
6
+ puts ports.length.to_s + "cameras connected"
7
+ cams = []
8
+ ports.each do |port|
9
+ c = GPhoto2::Camera.new(port)
10
+ puts "camera in port: " + port
11
+ c.config.each do |key, value|
12
+ puts key + " value is: " + value.to_s
13
+ puts "values available are: " + c[key, :all].inspect
14
+ end
15
+ cams.push c
17
16
  end
18
17
 
19
18
  # capture image
20
- c.capture
19
+ cams.first.capture
21
20
 
22
21
  # now camera virtual path is in the folder with images
23
22
  # list image file names
24
- puts "files on camera: " + c.files.inspect
23
+ puts "files on camera: " + cams.first.files.inspect
25
24
 
26
25
  # just an example of camera browsing
27
- puts "some folder stuff: " + c.folder_up.subfolders.inspect
26
+ puts "some folder stuff: " + cams.first.folder_up.subfolders.inspect
28
27
 
29
28
  # save preview of captured image in the current directory on hard drive
30
- c.capture.save :type => :preview, :new_name => "PREVIEW.JPG"
29
+ cams.first.capture.save :type => :preview, :new_name => "PREVIEW.JPG"
31
30
 
32
31
  # save captured file in the current directory on hard drive and delete
33
32
  # it from camera
34
- c.capture.save.delete
35
- else
36
- puts ports.length.to_s + "cameras connected"
37
- cams = []
38
- ports.each do |port|
39
- c = GPhoto2::Camera.new(port)
40
- puts "camera in port: " + port
41
- c.config.each_key do |cfg_key|
42
- puts cfg_key + " value is: " + c[cfg_key].to_s
43
- puts "values available are: " + c[cfg_key, :all].inspect
44
- end
45
- cams.push c
46
- end
33
+ cams.first.capture.save.delete
34
+
47
35
  # to capture image with all attached cameras simultaneously use:
48
36
  cams.each_index do |index|
49
37
  if index < cams.length - 1
data/ext/gphoto4ruby.c CHANGED
@@ -238,34 +238,50 @@ static VALUE camera_initialize(int argc, VALUE *argv, VALUE self) {
238
238
  * call-seq:
239
239
  * GPhoto2::Camera.ports => array
240
240
  *
241
- * Returns an array of usb port paths with cameras. If only one camera
242
- * is connected, returned array is empty.
241
+ * Returns an array of usb port paths with cameras. Port paths are the same
242
+ * as in <b>gphoto2 --auto-detect</b> output. Assuming that if there are
243
+ * cameras detected with long port paths, then the one with short port path
244
+ * is a duplicate of one of the others.
243
245
  *
244
246
  * Examples:
245
247
  *
246
248
  * # with one camera connected
247
- * GPhoto2::Camera.ports #=> []
249
+ * GPhoto2::Camera.ports #=> ["usb:"]
248
250
  * # with two cameras connected
249
251
  * GPhoto2::Camera.ports #=> ["usb:005,004", "usb:005,006"]
250
252
  *
251
253
  */
252
254
  static VALUE camera_class_ports(VALUE klass) {
253
- int i, portsTotal;
255
+ int i, camsTotal;
256
+ GPContext *context;
257
+ CameraAbilitiesList *abilList;
254
258
  GPPortInfoList *portInfoList;
255
- GPPortInfo p;
259
+ CameraList *camList;
260
+ const char *pName = NULL;
261
+ char *e = "";
256
262
  VALUE arr;
257
-
263
+
264
+ context = gp_context_new();
258
265
  gp_result_check(gp_port_info_list_new(&portInfoList));
259
266
  gp_result_check(gp_port_info_list_load(portInfoList));
260
- portsTotal = gp_result_check(gp_port_info_list_count(portInfoList));
267
+ gp_result_check(gp_abilities_list_new(&abilList));
268
+ gp_result_check(gp_abilities_list_load(abilList, context));
269
+ gp_result_check(gp_list_new(&camList));
270
+
271
+ gp_result_check(gp_abilities_list_detect(abilList, portInfoList, camList, context));
272
+
273
+ camsTotal = gp_result_check(gp_list_count(camList));
261
274
  arr = rb_ary_new();
262
- for(i = 0; i < portsTotal; i++) {
263
- gp_result_check(gp_port_info_list_get_info(portInfoList, i, &p));
264
- if ((strlen(p.path) > 4) && (strncmp(p.path, "usb:", 4) == 0)) {
265
- rb_ary_push(arr, rb_str_new2(p.path));
275
+ for(i = 0; i < camsTotal; i++) {
276
+ gp_result_check(gp_list_get_value(camList, i, &pName));
277
+ if ((camsTotal == 1) || (strlen(pName) > 4)) {
278
+ rb_ary_push(arr, rb_str_new2(pName));
266
279
  }
267
280
  }
281
+ gp_result_check(gp_list_free(camList));
268
282
  gp_result_check(gp_port_info_list_free(portInfoList));
283
+ gp_result_check(gp_abilities_list_free(abilList));
284
+ free(context);
269
285
  return arr;
270
286
  }
271
287
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gphoto4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - heq4 company
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-08-28 00:00:00 +04:00
13
+ date: 2008-09-05 00:00:00 +04:00
14
14
  default_executable:
15
15
  dependencies: []
16
16
 
@@ -70,6 +70,6 @@ rubyforge_project: gphoto4ruby
70
70
  rubygems_version: 1.1.1
71
71
  signing_key:
72
72
  specification_version: 2
73
- summary: GPhoto4Ruby is Ruby wrapping around libgphoto2 C library
73
+ summary: GPhoto4Ruby is Ruby wrapping around gphoto2 C library
74
74
  test_files: []
75
75