summaryrefslogtreecommitdiff
path: root/src/device.h
diff options
context:
space:
mode:
authorNicolas Schodet2019-11-22 23:52:08 +0100
committerNicolas Schodet2019-11-23 20:00:13 +0100
commit7a80b3a140ced43f79f8c9c62aa2f286234342ff (patch)
tree6ff8510cae0611488f352a778dcf97d5152adf6a /src/device.h
parente85cdfe8a3b6645c10071fd39efff490b4e9401b (diff)
Build with meson, add icon and desktop file
Diffstat (limited to 'src/device.h')
-rw-r--r--src/device.h188
1 files changed, 188 insertions, 0 deletions
diff --git a/src/device.h b/src/device.h
new file mode 100644
index 0000000..7028ebb
--- /dev/null
+++ b/src/device.h
@@ -0,0 +1,188 @@
+#ifndef device_h
+#define device_h
+/* Camicro - Microscope camera viewer.
+ *
+ * Device interface.
+ *
+ * Copyright (C) 2019 Nicolas Schodet
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Contact :
+ * Web: http://ni.fr.eu.org/
+ * Email: <nico at ni.fr.eu.org>
+ */
+#include <libusb.h>
+#include <stdint.h>
+#include <glib.h>
+
+#include "image.h"
+
+/* Error domain for device related errors. */
+#define DEVICE_ERROR device_error_quark()
+
+struct device;
+
+/* USB poll function. If the device is handled by this driver, it should
+ * return a dynamically allocated string naming this device. */
+typedef char *(*device_driver_usb_poll_f)(
+ struct libusb_device_descriptor *desc);
+
+/* USB open function. The device driver previously declared that it handles
+ * this device. */
+typedef struct device *(*device_driver_usb_open_f)(
+ libusb_context *usb, libusb_device *usb_device, GError **error);
+
+/* Information on a device driver. */
+struct device_driver {
+ /* Driver name. */
+ const char *name;
+ /* Poll this driver for support for an USB device. */
+ device_driver_usb_poll_f usb_poll;
+ /* Open an USB device. */
+ device_driver_usb_open_f usb_open;
+};
+
+/* Information on a supported resolution. */
+struct device_info_resolution {
+ /* Image width. */
+ int width;
+ /* Image height. */
+ int height;
+};
+
+/* Informations on an open device. */
+struct device_info {
+ /* Exposure minimum and maximum values. */
+ double exposure_min_ms, exposure_max_ms;
+ /* Exposure default value. */
+ double exposure_default_ms;
+ /* Exposure increment between two settable values. */
+ double exposure_step_ms;
+ /* Gain minimum and maximum values. */
+ double gain_min, gain_max;
+ /* Gain default value. */
+ double gain_default;
+ /* Gain increment between two settable values. */
+ double gain_step;
+ /* Number of supported resolutions. */
+ int resolutions;
+ /* Table of supported resolutions. */
+ const struct device_info_resolution *resolution;
+};
+
+/* Retrieve informations. */
+typedef const struct device_info *(*device_get_info_f)(
+ struct device *device);
+
+/* Set new exposure value. */
+typedef void (*device_set_exposure_f)(
+ struct device *device, double exposure_ms);
+
+/* Set new gain value. */
+typedef void (*device_set_gain_f)(
+ struct device *device, double gain);
+
+/* Set resolution, must be called before first image read. If stride is zero,
+ * let the device decide. */
+typedef void (*device_set_resolution_f)(
+ struct device *device, int width, int height, int stride);
+
+/* Start streaming. */
+typedef bool (*device_start_f)(
+ struct device *device, GError **error);
+
+/* Return an image if one is available, else, return NULL. */
+typedef struct image *(*device_read_f)(
+ struct device *device, GError **error);
+
+/* Stop streaming. */
+typedef bool (*device_stop_f)(
+ struct device *device, GError **error);
+
+/* Close device. */
+typedef bool (*device_close_f)(
+ struct device *device, GError **error);
+
+/* Open device. */
+struct device {
+ /* Retrieve informations. */
+ device_get_info_f get_info;
+ /* Change exposure. */
+ device_set_exposure_f set_exposure;
+ /* Change gain. */
+ device_set_gain_f set_gain;
+ /* Change resolution. */
+ device_set_resolution_f set_resolution;
+ /* Start streaming. */
+ device_start_f start;
+ /* Read an image. */
+ device_read_f read;
+ /* Stop streaming. */
+ device_stop_f stop;
+ /* Close device. */
+ device_close_f close;
+};
+
+/* Error codes. */
+enum DeviceError {
+ /* Error listing devices. */
+ DEVICE_ERROR_LIST,
+ /* Generic USB error. */
+ DEVICE_ERROR_USB,
+};
+
+/* Return quark of error domain for device related errors. */
+GQuark
+device_error_quark(void);
+
+/* Find and open device. */
+struct device *
+device_open(libusb_context *usb, GError **error);
+
+/* Retrieve informations. */
+const struct device_info *
+device_get_info(struct device *device);
+
+/* Set new exposure value. */
+void
+device_set_exposure(struct device *device, double exposure_ms);
+
+/* Set new gain value. */
+void
+device_set_gain(struct device *device, double gain);
+
+/* Set resolution. */
+void
+device_set_resolution(struct device *device, int width, int height,
+ int stride);
+
+/* Start streaming. */
+bool
+device_start(struct device *device, GError **error);
+
+/* Read an image. */
+struct image *
+device_read(struct device *device, GError **error);
+
+/* Stop streaming. */
+bool
+device_stop(struct device *device, GError **error);
+
+/* Close device. */
+bool
+device_close(struct device *device, GError **error);
+
+#endif /* device_h */