Permalink
Browse files

Added the abilities function mainly to get the name of the camera

  • Loading branch information...
1 parent 08c9095 commit 895512d432391141a702f6ef9f48d9b102301e7d Tallak Tveide committed Feb 25, 2010
Showing with 83 additions and 3 deletions.
  1. +1 −0 .gitignore
  2. +70 −0 ext/gphoto2camera.c
  3. +2 −0 ext/gphoto2camera.h
  4. +5 −0 ext/gphoto2camera_utilities.c
  5. +1 −0 ext/gphoto2camera_utilities.h
  6. +1 −0 ext/gphoto4ruby.c
  7. +3 −3 gphoto4ruby.gemspec
View
1 .gitignore
@@ -7,3 +7,4 @@ ext/test.rb
ext/*test.rb
rdoc
.rake_complete~
+*.swp
View
70 ext/gphoto2camera.c
@@ -937,6 +937,76 @@ VALUE camera_set_value(VALUE self, VALUE str, VALUE newVal) {
/*
* call-seq:
+ * abilities => hash
+ *
+ * Contents of the returned hash:
+ * * <b>:model</b> - a string decribing the camera model
+ * * <b>:status</b> - one of :production, :testing, :experimental or :deprecated
+ * * <b>:operations</b> - an array containing a combination of :capture_image, :capture_video, :capture_audio, :capture_preview and :config
+ *
+ * Returns the camera abilities
+ *
+ * Examples:
+ *
+ * c = GPhoto2::Camera.new
+ * # with Canon EOS 40D
+ * c.abilities #=> {:status=>:production,
+ * :operations=>[:capture_image, :capture_preview, :config],
+ * :model=>"Canon EOS 40D (PTP mode)"}
+ *
+ */
+VALUE camera_get_abilities(VALUE self) {
+ GPhoto2Camera *c;
+ Data_Get_Struct(self, GPhoto2Camera, c);
+ CameraAbilities a;
+ if (gp_result_check(gp_camera_get_abilities (c->camera, &a)) >= GP_OK) {
+ VALUE abilities = rb_hash_new();
+ /* model */
+ rb_hash_aset(abilities, rb_new_sym("model"), rb_str_new2(a.model));
+
+ /* driver status */
+ switch (a.status) {
+ case GP_DRIVER_STATUS_PRODUCTION:
+ rb_hash_aset(abilities, rb_new_sym("status"), rb_new_sym("production"));
+ break;
+ case GP_DRIVER_STATUS_TESTING:
+ rb_hash_aset(abilities, rb_new_sym("status"), rb_new_sym("testing"));
+ break;
+ case GP_DRIVER_STATUS_EXPERIMENTAL:
+ rb_hash_aset(abilities, rb_new_sym("status"), rb_new_sym("experimental"));
+ break;
+ case GP_DRIVER_STATUS_DEPRECATED:
+ rb_hash_aset(abilities, rb_new_sym("status"), rb_new_sym("deprecated"));
+ break;
+ }
+
+ /* operations */
+ VALUE ops = rb_ary_new();
+ if (a.operations & GP_OPERATION_CAPTURE_IMAGE) {
+ rb_ary_push(ops, rb_new_sym("capture_image"));
+ }
+ if (a.operations & GP_OPERATION_CAPTURE_VIDEO) {
+ rb_ary_push(ops, rb_new_sym("capture_video"));
+ }
+ if (a.operations & GP_OPERATION_CAPTURE_AUDIO) {
+ rb_ary_push(ops, rb_new_sym("capture_audio"));
+ }
+ if (a.operations & GP_OPERATION_CAPTURE_PREVIEW) {
+ rb_ary_push(ops, rb_new_sym("capture_preview"));
+ }
+ if (a.operations & GP_OPERATION_CONFIG) {
+ rb_ary_push(ops, rb_new_sym("config"));
+ }
+ rb_hash_aset(abilities, rb_new_sym("operations"), ops);
+
+ return abilities;
+ } else {
+ return Qnil;
+ }
+}
+
+/*
+ * call-seq:
* folder => string
*
* Returns current camera path. When image is captured, folder changes to
View
2 ext/gphoto2camera.h
@@ -56,6 +56,8 @@ VALUE camera_config_merge(VALUE self, VALUE hash);
VALUE camera_get_value(int argc, VALUE *argv, VALUE self);
VALUE camera_set_value(VALUE self, VALUE str, VALUE newVal);
+VALUE camera_get_abilities(VALUE self);
+
VALUE camera_folder(VALUE self);
VALUE camera_subfolders(VALUE self);
VALUE camera_files(int argc, VALUE *argv, VALUE self);
View
5 ext/gphoto2camera_utilities.c
@@ -272,3 +272,8 @@ void populateWithConfigs(CameraWidget *cc, VALUE hash) {
break;
}
}
+
+
+VALUE rb_new_sym(char* name) {
+ return ID2SYM(rb_intern(name));
+}
View
1 ext/gphoto2camera_utilities.h
@@ -70,6 +70,7 @@ VALUE setDate(VALUE self, GPhoto2Camera *c, VALUE newNum, int save);
void saveConfigs(VALUE self, GPhoto2Camera *c);
void populateWithConfigs(CameraWidget *cc, VALUE arr);
+VALUE rb_new_sym(char* name);
#endif /* _INC_CAMERA_UTILITIES */
View
1 ext/gphoto4ruby.c
@@ -87,6 +87,7 @@ void Init_gphoto4ruby() {
rb_define_method(rb_cGPhoto2Camera, "initialize", camera_initialize, -1); /* in gphoto2camera.c */
rb_define_method(rb_cGPhoto2Camera, "config", camera_get_config, -1); /* in gphoto2camera.c */
rb_define_method(rb_cGPhoto2Camera, "config_merge", camera_config_merge, 1); /* in gphoto2camera.c */
+ rb_define_method(rb_cGPhoto2Camera, "abilities", camera_get_abilities, 0); /* in gphoto2camera.c */
rb_define_method(rb_cGPhoto2Camera, "[]", camera_get_value, -1); /* in gphoto2camera.c */
rb_define_method(rb_cGPhoto2Camera, "[]=", camera_set_value, 2); /* in gphoto2camera.c */
rb_define_method(rb_cGPhoto2Camera, "capture", camera_capture, -1); /* in gphoto2camera.c */
View
6 gphoto4ruby.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{gphoto4ruby}
- s.version = "0.4.1"
+ s.version = "0.4.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["neq4 company", "Sergey Kruk"]
- s.date = %q{2009-11-06}
+ s.date = %q{2010-02-25}
s.description = %q{GPhoto4Ruby is used to control PPTP cameras (the ones that can be controlled with gphoto2) using power of ruby.}
s.email = %q{sergey.kruk@gmail.com}
s.extensions = ["ext/extconf.rb"]
@@ -45,7 +45,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--main", "README.rdoc", "--charset", "UTF-8", "--webcvs", "http://github.com/lonelyelk/gphoto4ruby/tree/master", "--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{gphoto4ruby}
- s.rubygems_version = %q{1.3.5}
+ s.rubygems_version = %q{1.3.6}
s.summary = %q{GPhoto4Ruby is Ruby wrapping around gphoto2 C library}
if s.respond_to? :specification_version then

0 comments on commit 895512d

Please sign in to comment.