Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Hacked-together cm108-ptt library. Nearly 100% copied from Hamlib.
- * Do-not-trust and will-do-evil-things generally apply.
- *
- * Have fun with it :D
- */
- /*
- * Hamlib Interface - CM108 HID communication low-level support
- * Copyright (c) 2000-2012 by Stephane Fillod
- * Copyright (c) 2011 by Andrew Errington
- * CM108 detection code Copyright (c) Thomas Sailer used with permission
- *
- * This library is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Library 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 Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
- /**
- * \addtogroup rig_internal
- * @{
- */
- /**
- * \brief CM108 GPIO
- * \file cm108.c
- */
- #include <stdlib.h>
- #include <stdio.h> /* Standard input/output definitions */
- #include <string.h> /* String function definitions */
- #include <unistd.h> /* UNIX standard function definitions */
- #include <fcntl.h> /* File control definitions */
- #include <errno.h> /* Error number definitions */
- #include <sys/time.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/ioctl.h>
- #include <libudev.h>
- #include <sys/param.h>
- #include <linux/hidraw.h>
- #include "cm108.h"
- /**
- * Find the matching hidraw device for the given USB_VID and USB_PID.
- * Returns the path of the found hidraw device or a null pointer if none was found.
- */
- const char *cm108_find_device()
- {
- struct udev *udev;
- struct udev_enumerate *enumerate;
- struct udev_list_entry *devices, *dev_list_entry;
- struct udev_device *dev;
- const char *found_path;
- udev = udev_new();
- if(!udev) {
- printf("Can't create udev\n");
- exit(2);
- }
- enumerate = udev_enumerate_new(udev);
- udev_enumerate_add_match_subsystem(enumerate, "hidraw");
- udev_enumerate_scan_devices(enumerate);
- devices = udev_enumerate_get_list_entry(enumerate);
- udev_list_entry_foreach(dev_list_entry, devices) {
- const char *path, *hidraw;
- path = udev_list_entry_get_name(dev_list_entry);
- dev = udev_device_new_from_syspath(udev, path);
- hidraw = udev_device_get_devnode(dev);
- if((strcmp(udev_device_get_sysattr_value(dev, "idVendor"), CM108_VID) == 0)
- && (strcmp(udev_device_get_sysattr_value(dev, "idProduct"), CM108_PID) == 0)) {
- found_path = hidraw;
- goto clean;
- }
- }
- clean:
- udev_enumerate_unref(enumerate);
- udev_unref(udev);
- return found_path;
- }
- /**
- * \brief Open CM108 HID port (/dev/hidrawX)
- * \param port
- * \return file descriptor
- */
- int cm108_open(const char* path)
- {
- int fd;
- fd = open(path, O_RDWR);
- if (fd < 0) {
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement