[aravis] camera: simple use case based API.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] camera: simple use case based API.
- Date: Tue, 18 May 2010 20:18:12 +0000 (UTC)
commit 5e4f8862f8a230476d779ef9d2bf29ed63839465
Author: Emmanuel Pacaud <emmanuel gnome org>
Date: Tue May 18 22:13:03 2010 +0200
camera: simple use case based API.
From now, I will try to stick to the following definition for the
camera API: it should provide a nice API for the common use of a
camera. For all advanced camera use, the user should use the underlying
device object, and its genicam interface.
src/Makefile.am | 1 +
src/arvcamera.c | 137 ++++++++++++++++++++++----------------------------
src/arvcamera.h | 20 +++-----
src/arvcameratest.c | 26 +++-------
src/arvenums.c | 53 ++++++++++++++++++++
src/arvenums.h | 17 ++++++
6 files changed, 146 insertions(+), 108 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 4ddf90c..6e90627 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,6 +27,7 @@ libaravis_la_LIBADD = \
$(ARAVIS_LIBS)
libaravis_la_SOURCES = \
+ arvenums.c \
arvenumtypes.c \
arvdebug.c \
arvtools.c \
diff --git a/src/arvcamera.c b/src/arvcamera.c
index 605e251..065134b 100644
--- a/src/arvcamera.c
+++ b/src/arvcamera.c
@@ -158,132 +158,115 @@ arv_camera_get_pixel_format (ArvCamera *camera)
/* Acquisition control */
void
-arv_camera_set_acquisition_mode (ArvCamera *camera, const char *value)
+arv_camera_start_acquisition (ArvCamera *camera)
{
g_return_if_fail (ARV_IS_CAMERA (camera));
- arv_device_set_string_feature_value (camera->priv->device, "AcquisitionMode", value);
+ arv_device_execute_command (camera->priv->device, "AcquisitionStart");
}
-const char *
-arv_camera_get_acquisition_mode (ArvCamera *camera)
+void
+arv_camera_stop_acquisition (ArvCamera *camera)
{
- g_return_val_if_fail (ARV_IS_CAMERA (camera), NULL);
+ g_return_if_fail (ARV_IS_CAMERA (camera));
- return arv_device_get_string_feature_value (camera->priv->device, "AcquisitionMode");
+ arv_device_execute_command (camera->priv->device, "AcquisitionStop");
}
void
-arv_camera_start_acquisition (ArvCamera *camera)
+arv_camera_set_acquisition_mode (ArvCamera *camera, ArvAcquisitionMode mode)
{
g_return_if_fail (ARV_IS_CAMERA (camera));
- arv_device_execute_command (camera->priv->device, "AcquisitionStart");
+ arv_device_set_string_feature_value (camera->priv->device, "AcquisitionMode",
+ arv_acquisition_mode_to_string (mode));
}
-void
-arv_camera_stop_acquisition (ArvCamera *camera)
+ArvAcquisitionMode
+arv_camera_get_acquisition_mode (ArvCamera *camera)
{
- g_return_if_fail (ARV_IS_CAMERA (camera));
+ const char *string;
- arv_device_execute_command (camera->priv->device, "AcquisitionStop");
+ g_return_val_if_fail (ARV_IS_CAMERA (camera), 0);
+
+ string = arv_device_get_string_feature_value (camera->priv->device, "AcquisitionMode");
+
+ return arv_acquisition_mode_from_string (string);
}
void
-arv_camera_set_acquisition_frame_rate (ArvCamera *camera, double frame_rate)
+arv_camera_set_fixed_frame_rate (ArvCamera *camera, double frame_rate)
{
g_return_if_fail (ARV_IS_CAMERA (camera));
switch (camera->priv->vendor) {
case ARV_CAMERA_VENDOR_BASLER:
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerSelector",
+ "AcquisitionStart");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerMode", "Off");
arv_device_set_integer_feature_value (camera->priv->device, "AcquisitionFrameRateEnable",
1);
arv_device_set_float_feature_value (camera->priv->device, "AcquisitionFrameRateAbs",
frame_rate);
break;
case ARV_CAMERA_VENDOR_PROSILICA:
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerSelector",
+ "FrameStart");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerMode", "Off");
arv_device_set_float_feature_value (camera->priv->device, "AcquisitionFrameRateAbs",
frame_rate);
break;
case ARV_CAMERA_VENDOR_UNKNOWN:
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerSelector",
+ "FrameStart");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerMode", "Off");
arv_device_set_float_feature_value (camera->priv->device, "AcquisitionFrameRate", frame_rate);
break;
}
}
-double
-arv_camera_get_acquisition_frame_rate (ArvCamera *camera)
+void
+arv_camera_set_external_trigger (ArvCamera *camera, ArvTriggerSource source)
{
- g_return_val_if_fail (ARV_IS_CAMERA (camera), 0.0);
+ const char *string;
+
+ g_return_if_fail (ARV_IS_CAMERA (camera));
+
+ string = arv_trigger_source_to_string (source);
switch (camera->priv->vendor) {
case ARV_CAMERA_VENDOR_BASLER:
- return arv_device_get_integer_feature_value (camera->priv->device, "AcquisitionFrameRateAbs");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerSelector",
+ "AcquisitionStart");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerMode", "On");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerActivation",
+ "RisingEdge");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerSource", string);
+ break;
case ARV_CAMERA_VENDOR_PROSILICA:
- return arv_device_get_integer_feature_value (camera->priv->device, "AcquisitionFrameRateAbs");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerSelector",
+ "AcquisitionStart");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerMode", "Off");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerSelector", "FrameStart");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerMode", "On");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerActivation",
+ "RisingEdge");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerSource", string);
+ break;
case ARV_CAMERA_VENDOR_UNKNOWN:
- default:
- return arv_device_get_integer_feature_value (camera->priv->device, "AcquisitionFrameRate");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerSelector",
+ "AcquisitionStart");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerMode", "Off");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerSelector", "FrameStart");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerMode", "On");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerActivation",
+ "RisingEdge");
+ arv_device_set_string_feature_value (camera->priv->device, "TriggerSource", string);
+ break;
}
}
void
-arv_camera_set_trigger_selector (ArvCamera *camera, const char *value)
-{
- g_return_if_fail (ARV_IS_CAMERA (camera));
-
- arv_device_set_string_feature_value (camera->priv->device, "TriggerSelector", value);
-}
-
-void
-arv_camera_set_trigger_mode (ArvCamera *camera, const char *value)
-{
- g_return_if_fail (ARV_IS_CAMERA (camera));
-
- arv_device_set_string_feature_value (camera->priv->device, "TriggerMode", value);
-}
-
-const char *
-arv_camera_get_trigger_mode (ArvCamera *camera)
-{
- g_return_val_if_fail (ARV_IS_CAMERA (camera), NULL);
-
- return arv_device_get_string_feature_value (camera->priv->device, "TriggerMode");
-}
-
-void
-arv_camera_set_trigger_source (ArvCamera *camera, const char *value)
-{
- g_return_if_fail (ARV_IS_CAMERA (camera));
-
- arv_device_set_string_feature_value (camera->priv->device, "TriggerSource", value);
-}
-
-const char *
-arv_camera_get_trigger_source (ArvCamera *camera)
-{
- g_return_val_if_fail (ARV_IS_CAMERA (camera), NULL);
-
- return arv_device_get_string_feature_value (camera->priv->device, "TriggerSource");
-}
-
-void
-arv_camera_set_trigger_activation (ArvCamera *camera, const char *value)
-{
- g_return_if_fail (ARV_IS_CAMERA (camera));
-
- arv_device_set_string_feature_value (camera->priv->device, "TriggerActivation", value);
-}
-
-const char *
-arv_camera_get_trigger_activation (ArvCamera *camera)
-{
- g_return_val_if_fail (ARV_IS_CAMERA (camera), NULL);
-
- return arv_device_get_string_feature_value (camera->priv->device, "TriggerActivation");
-}
-
-void
arv_camera_set_exposure_time (ArvCamera *camera, double exposure_time_us)
{
g_return_if_fail (ARV_IS_CAMERA (camera));
@@ -291,7 +274,7 @@ arv_camera_set_exposure_time (ArvCamera *camera, double exposure_time_us)
arv_device_set_float_feature_value (camera->priv->device, "ExposureTimeAbs", exposure_time_us);
}
-gboolean
+double
arv_camera_get_exposure_time (ArvCamera *camera)
{
g_return_val_if_fail (ARV_IS_CAMERA (camera), 0.0);
diff --git a/src/arvcamera.h b/src/arvcamera.h
index 057e8b8..723769e 100644
--- a/src/arvcamera.h
+++ b/src/arvcamera.h
@@ -77,21 +77,17 @@ ArvPixelFormat arv_camera_get_pixel_format (ArvCamera *camera);
/* Acquisition control */
-void arv_camera_set_acquisition_mode (ArvCamera *camera, const char *value);
-const char * arv_camera_get_acquisition_mode (ArvCamera *camera);
void arv_camera_start_acquisition (ArvCamera *camera);
void arv_camera_stop_acquisition (ArvCamera *camera);
-void arv_camera_set_acquisition_frame_rate (ArvCamera *camera, double frame_rate);
-double arv_camera_get_acquisition_frame_rate (ArvCamera *camera);
-void arv_camera_set_trigger_selector (ArvCamera *camera, const char *value);
-void arv_camera_set_trigger_mode (ArvCamera *camera, const char *value);
-const char * arv_camera_get_trigger_mode (ArvCamera *camera);
-void arv_camera_set_trigger_source (ArvCamera *camera, const char *value);
-const char * arv_camera_get_trigger_source (ArvCamera *camera);
-void arv_camera_set_trigger_activation (ArvCamera *camera, const char *value);
-const char * arv_camera_get_trigger_activation (ArvCamera *camera);
+
+void arv_camera_set_acquisition_mode (ArvCamera *camera, ArvAcquisitionMode value);
+ArvAcquisitionMode arv_camera_get_acquisition_mode (ArvCamera *camera);
+
+void arv_camera_set_fixed_frame_rate (ArvCamera *camera, double frame_rate);
+void arv_camera_set_external_trigger (ArvCamera *camera, ArvTriggerSource source);
+
void arv_camera_set_exposure_time (ArvCamera *camera, double exposure_time_us);
-gboolean arv_camera_get_exposure_time (ArvCamera *camera);
+double arv_camera_get_exposure_time (ArvCamera *camera);
/* Analog control */
diff --git a/src/arvcameratest.c b/src/arvcameratest.c
index 9ef6022..faf0c47 100644
--- a/src/arvcameratest.c
+++ b/src/arvcameratest.c
@@ -113,25 +113,13 @@ main (int argc, char **argv)
for (i = 0; i < 200; i++)
arv_stream_push_buffer (stream, arv_buffer_new (payload, NULL));
- arv_camera_set_acquisition_mode (camera, "Continuous");
-
- if (arv_option_frequency > 0.0) {
- arv_camera_set_trigger_selector (camera, "FrameStart");
- arv_camera_set_trigger_mode (camera, "Off");
- arv_camera_set_acquisition_frame_rate (camera, arv_option_frequency);
- }
-
- if (arv_option_trigger != NULL) {
- arv_camera_set_trigger_selector (camera, "FrameStart");
- arv_camera_set_trigger_mode (camera, "On");
- arv_camera_set_trigger_activation (camera, "RisingEdge");
- arv_camera_set_trigger_source (camera, arv_option_trigger);
- }
-
- g_print ("acquisition mode = %s\n", arv_camera_get_acquisition_mode (camera));
- g_print ("trigger mode = %s\n", arv_camera_get_trigger_mode (camera));
- g_print ("trigger activation = %s\n", arv_camera_get_trigger_activation (camera));
- g_print ("trigger source = %s\n", arv_camera_get_trigger_source (camera));
+ arv_camera_set_acquisition_mode (camera, ARV_ACQUISITION_MODE_CONTINUOUS);
+
+ if (arv_option_frequency > 0.0)
+ arv_camera_set_fixed_frame_rate (camera, arv_option_frequency);
+
+ if (arv_option_trigger != NULL)
+ arv_camera_set_external_trigger (camera, arv_trigger_source_from_string (arv_option_trigger));
arv_camera_start_acquisition (camera);
diff --git a/src/arvenums.c b/src/arvenums.c
new file mode 100644
index 0000000..75b8d93
--- /dev/null
+++ b/src/arvenums.c
@@ -0,0 +1,53 @@
+#include <arvenums.h>
+
+static unsigned int
+_from_string (const char *string, const char **strings, unsigned int n_strings)
+{
+ int i;
+
+ if (string == NULL)
+ return 0;
+
+ for (i = 0; i < n_strings; i++)
+ if (g_strcmp0 (string, strings[i]) == 0)
+ return i;
+
+ return 0;
+}
+
+static const char *arv_acquisition_mode_strings[] = {
+ "Continuous",
+ "SingleFrame"
+};
+
+const char *
+arv_acquisition_mode_to_string (ArvAcquisitionMode value)
+{
+ return arv_acquisition_mode_strings[CLAMP (value, 0, ARV_ACQUISITION_MODE_SINGLE_FRAME)];
+}
+
+ArvAcquisitionMode
+arv_acquisition_mode_from_string (const char *string)
+{
+ return _from_string (string, arv_acquisition_mode_strings,
+ G_N_ELEMENTS (arv_acquisition_mode_strings));
+}
+
+static const char *arv_trigger_source_strings[] = {
+ "Line0",
+ "Line1",
+ "Line2"
+};
+
+const char *
+arv_trigger_source_to_string (ArvTriggerSource value)
+{
+ return arv_trigger_source_strings[CLAMP (value, 0, ARV_ACQUISITION_MODE_SINGLE_FRAME)];
+}
+
+ArvTriggerSource
+arv_trigger_source_from_string (const char *string)
+{
+ return _from_string (string, arv_trigger_source_strings,
+ G_N_ELEMENTS (arv_trigger_source_strings));
+}
diff --git a/src/arvenums.h b/src/arvenums.h
index afd8423..2158f49 100644
--- a/src/arvenums.h
+++ b/src/arvenums.h
@@ -46,6 +46,17 @@ typedef enum {
} ArvGcCachable;
typedef enum {
+ ARV_ACQUISITION_MODE_CONTINUOUS,
+ ARV_ACQUISITION_MODE_SINGLE_FRAME
+} ArvAcquisitionMode;
+
+typedef enum {
+ ARV_TRIGGER_SOURCE_LINE_0,
+ ARV_TRIGGER_SOURCE_LINE_1,
+ ARV_TRIGGER_SOURCE_LINE_2
+} ArvTriggerSource;
+
+typedef enum {
ARV_PIXEL_FORMAT_MONO_8 = 0x01080001,
ARV_PIXEL_FORMAT_MONO_10 = 0x01100003,
ARV_PIXEL_FORMAT_MONO_12 = 0x01100005,
@@ -85,6 +96,12 @@ typedef enum {
ARV_PIXEL_FORMAT_BAYER_BG_16 = 0x81100009
} ArvPixelFormat;
+const char * arv_acquisition_mode_to_string (ArvAcquisitionMode value);
+ArvAcquisitionMode arv_acquisition_mode_from_string (const char *string);
+
+const char * arv_trigger_source_to_string (ArvTriggerSource value);
+ArvTriggerSource arv_trigger_source_from_string (const char *string);
+
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]