69 lines
2.2 KiB
C
69 lines
2.2 KiB
C
/* ****************************************************************************
|
|
* stream/open_usb.c -- open a USB stream.
|
|
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
*
|
|
* This file is part of libcasio.
|
|
* libcasio is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation; either version 3.0 of the License,
|
|
* or (at your option) any later version.
|
|
*
|
|
* libcasio 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 Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
|
|
* ************************************************************************* */
|
|
#include "stream.h"
|
|
|
|
#if !defined(LIBCASIO_DISABLED_LIBUSB)
|
|
# define OUF &casio_open_libusb_usb
|
|
#elif !defined(LIBCASIO_DISABLED_WINDOWS)
|
|
# define OUF &casio_open_windows_usb
|
|
#else
|
|
# define OUF NULL
|
|
#endif
|
|
|
|
CASIO_LOCAL casio_open_usb_stream_t *open_usb_stream_func = OUF;
|
|
|
|
/**
|
|
* casio_set_open_usb_stream_func:
|
|
* Set the USB streams opener.
|
|
*
|
|
* NULL rests the function to its default.
|
|
*
|
|
* @arg function the function pointer to set.
|
|
* @return the error code (0 if ok).
|
|
*/
|
|
|
|
int CASIO_EXPORT casio_set_open_usb_stream_func(casio_open_usb_stream_t *func)
|
|
{
|
|
open_usb_stream_func = func ? func : OUF;
|
|
return (0);
|
|
}
|
|
|
|
/**
|
|
* casio_open_usb_stream:
|
|
* Open the USB stream.
|
|
*
|
|
* @arg stream the stream to make.
|
|
* @arg bus the USB bus on which to find the device.
|
|
* -1 if any device on any bus (and address is not read).
|
|
* @arg address the address on the bus of the device.
|
|
* -1 if any device on the bus.
|
|
* @return the error code (0 if ok).
|
|
*/
|
|
|
|
int CASIO_EXPORT casio_open_usb_stream(casio_stream_t **streamp,
|
|
int bus, int address)
|
|
{
|
|
if (bus < -1 || bus > 255 || address < -1 || address > 255)
|
|
return (casio_error_op);
|
|
if (!open_usb_stream_func)
|
|
return (casio_error_op);
|
|
|
|
return ((*open_usb_stream_func)(streamp, bus, address));
|
|
}
|