From 7a80b3a140ced43f79f8c9c62aa2f286234342ff Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 22 Nov 2019 23:52:08 +0100 Subject: Build with meson, add icon and desktop file --- src/device.h | 188 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 src/device.h (limited to 'src/device.h') 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: + */ +#include +#include +#include + +#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 */ -- cgit v1.2.3