/* Camicro - Microscope camera viewer. * * 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 "device.h" #include "utils.h" #include "moticam.h" static const struct device_driver *drivers[] = { &moticam_device_driver, NULL }; struct device * device_open(libusb_context *usb) { libusb_device **list; libusb_device *found_usb_device = NULL; char *found_device_name = NULL; const struct device_driver *found_device_driver = NULL; ssize_t cnt = libusb_get_device_list(usb, &list); if (cnt < 0) utils_fatal("can not list devices: %s", libusb_strerror(cnt)); for (ssize_t i = 0; i < cnt; i++) { libusb_device *usb_device = list[i]; struct libusb_device_descriptor desc; int r = libusb_get_device_descriptor(usb_device, &desc); if (r) utils_fatal("can not get device descriptor: %s", libusb_strerror(r)); for (const struct device_driver **dd = drivers; *dd; dd++) { char *device_name = (*dd)->usb_poll(&desc); if (device_name) { if (found_device_name) utils_fatal("more than one matching device, not" " supported"); else { found_usb_device = usb_device; found_device_name = device_name; found_device_driver = *dd; } } } } struct device *device = NULL; if (found_usb_device) { free(found_device_name); device = found_device_driver->usb_open(found_usb_device); } libusb_free_device_list(list, 1); return device; } const struct device_info * device_get_info(struct device *device) { return device->get_info(device); } void device_set_exposure(struct device *device, double exposure_ms) { device->set_exposure(device, exposure_ms); } void device_set_gain(struct device *device, double gain) { device->set_gain(device, gain); } void device_set_resolution(struct device *device, int width, int height, int stride) { device->set_resolution(device, width, height, stride); } const struct device_image * device_read(struct device *device) { return device->read(device); } void device_close(struct device *device) { device->close(device); }