summaryrefslogtreecommitdiffstats
path: root/src/cameras/uca-ufo-camera.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cameras/uca-ufo-camera.c')
-rw-r--r--src/cameras/uca-ufo-camera.c64
1 files changed, 45 insertions, 19 deletions
diff --git a/src/cameras/uca-ufo-camera.c b/src/cameras/uca-ufo-camera.c
index 66a42c4..51b984a 100644
--- a/src/cameras/uca-ufo-camera.c
+++ b/src/cameras/uca-ufo-camera.c
@@ -93,13 +93,25 @@ static guint N_PROPERTIES;
static GHashTable *ufo_property_table; /* maps from prop_id to RegisterInfo* */
struct _UcaUfoCameraPrivate {
- pcilib_t *handle;
- guint n_bits;
- guint bit_mode;
+ pcilib_t *handle;
+ pcilib_timeout_t timeout;
+ guint n_bits;
+ enum {
+ FPGA_48MHZ = 0,
+ FPGA_40MHZ
+ } frequency;
};
-static void ignore_messages(const char *format, ...)
+static void
+error_handler (const char *format, ...)
{
+ va_list args;
+ gchar *message;
+
+ va_start (args, format);
+ message = g_strdup_vprintf (format, args);
+ g_warning ("%s", message);
+ va_end (args);
}
static guint
@@ -145,7 +157,7 @@ UcaUfoCamera *uca_ufo_camera_new(GError **error)
return NULL;
}
- pcilib_set_error_handler(&ignore_messages, &ignore_messages);
+ pcilib_set_error_handler(&error_handler, &error_handler);
/* Generate properties from model description */
model_description = pcilib_get_model_description(handle);
@@ -194,7 +206,7 @@ UcaUfoCamera *uca_ufo_camera_new(GError **error)
UcaUfoCamera *camera = g_object_new(UCA_TYPE_UFO_CAMERA, NULL);
UcaUfoCameraPrivate *priv = UCA_UFO_CAMERA_GET_PRIVATE(camera);
- priv->bit_mode = read_register_value (handle, "bit_mode");
+ priv->frequency = read_register_value (handle, "bit_mode");
adc_resolution = read_register_value (handle, "adc_resolution");
switch (adc_resolution) {
@@ -216,16 +228,24 @@ UcaUfoCamera *uca_ufo_camera_new(GError **error)
static void uca_ufo_camera_start_recording(UcaCamera *camera, GError **error)
{
+ UcaUfoCameraPrivate *priv;
+ gdouble exposure_time;
+ int err;
+
g_return_if_fail(UCA_IS_UFO_CAMERA(camera));
- UcaUfoCameraPrivate *priv = UCA_UFO_CAMERA_GET_PRIVATE(camera);
- int err = pcilib_start(priv->handle, PCILIB_EVENT_DATA, PCILIB_EVENT_FLAGS_DEFAULT);
+
+ priv = UCA_UFO_CAMERA_GET_PRIVATE(camera);
+ err = pcilib_start(priv->handle, PCILIB_EVENT_DATA, PCILIB_EVENT_FLAGS_DEFAULT);
PCILIB_SET_ERROR(err, UCA_UFO_CAMERA_ERROR_START_RECORDING);
gboolean transfer_async = FALSE;
g_object_get(G_OBJECT(camera),
"transfer-asynchronously", &transfer_async,
+ "exposure-time", &exposure_time,
NULL);
+ priv->timeout = ((pcilib_timeout_t) (exposure_time * 1000 + 50.0) * 1000);
+
if (transfer_async) {
pcilib_trigger(priv->handle, PCILIB_EVENT0, 0, NULL);
pcilib_stream(priv->handle, &event_callback, camera);
@@ -251,15 +271,16 @@ static void uca_ufo_camera_grab(UcaCamera *camera, gpointer *data, GError **erro
{
g_return_if_fail(UCA_IS_UFO_CAMERA(camera));
UcaUfoCameraPrivate *priv = UCA_UFO_CAMERA_GET_PRIVATE(camera);
- const gsize size = SENSOR_WIDTH * SENSOR_HEIGHT * sizeof(guint16);
- pcilib_event_id_t event_id;
+ pcilib_event_id_t event_id;
pcilib_event_info_t event_info;
- size_t err = 0;
+ size_t err;
+
+ const gsize size = SENSOR_WIDTH * SENSOR_HEIGHT * sizeof(guint16);
err = pcilib_trigger(priv->handle, PCILIB_EVENT0, 0, NULL);
PCILIB_SET_ERROR(err, UCA_UFO_CAMERA_ERROR_TRIGGER);
- err = pcilib_get_next_event(priv->handle, PCILIB_TIMEOUT_INFINITE, &event_id, sizeof(pcilib_event_info_t), &event_info);
+ err = pcilib_get_next_event(priv->handle, priv->timeout, &event_id, sizeof(pcilib_event_info_t), &event_info);
PCILIB_SET_ERROR(err, UCA_UFO_CAMERA_ERROR_NEXT_EVENT);
if (*data == NULL)
@@ -289,15 +310,17 @@ static void uca_ufo_camera_grab(UcaCamera *camera, gpointer *data, GError **erro
PCILIB_SET_ERROR(err, UCA_UFO_CAMERA_ERROR_MAYBE_CORRUPTED);
}
-static void uca_ufo_camera_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
+static void
+uca_ufo_camera_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
UcaUfoCameraPrivate *priv = UCA_UFO_CAMERA_GET_PRIVATE(object);
switch (property_id) {
case PROP_EXPOSURE_TIME:
{
- pcilib_register_value_t reg_value = (pcilib_register_value_t) EXPOSURE_TIME_SCALE * g_value_get_double(value);
- pcilib_write_register(priv->handle, NULL, "exp_time", reg_value);
+ const guint frequency = priv->frequency == FPGA_40MHZ ? 40 : 48;
+ pcilib_register_value_t reg_value = (pcilib_register_value_t) 129 / frequency * 1000 * 1000 * g_value_get_double(value);
+ pcilib_write_register(priv->handle, NULL, "cmosis_exp_time", reg_value);
}
break;
case PROP_ROI_X:
@@ -353,12 +376,12 @@ uca_ufo_camera_get_property(GObject *object, guint property_id, GValue *value, G
break;
case PROP_SENSOR_TEMPERATURE:
{
- const double a = priv->bit_mode == 0 ? 0.3 : 0.25;
- const double b = priv->bit_mode == 0 ? 1000 : 1200;
+ const double a = priv->frequency == FPGA_48MHZ ? 0.3 : 0.25;
+ const double b = priv->frequency == FPGA_48MHZ ? 1000 : 1200;
guint32 temperature;
temperature = read_register_value (priv->handle, "sensor_temperature");
- g_value_set_double (value, a * temperature - b);
+ g_value_set_double (value, a * (temperature - b));
}
break;
case PROP_FPGA_TEMPERATURE:
@@ -372,7 +395,10 @@ uca_ufo_camera_get_property(GObject *object, guint property_id, GValue *value, G
}
break;
case PROP_EXPOSURE_TIME:
- g_value_set_double (value, read_register_value (priv->handle, "exp_time") / EXPOSURE_TIME_SCALE);
+ {
+ const gdouble frequency = priv->frequency == FPGA_40MHZ ? 40.0 : 48.0;
+ g_value_set_double (value, read_register_value (priv->handle, "cmosis_exp_time") * 129 / frequency / 1000 / 1000 );
+ }
break;
case PROP_HAS_STREAMING:
g_value_set_boolean(value, TRUE);