예제 #1
0
파일: pcsensor.c 프로젝트: longjos/temper
/**
 * Initialize all Temper Devices currently attached to the system
 * @return pcsensor_devices*
 */
pcsensor_devices* setup_libusb_access() {
    static pcsensor_devices *available_devices;

    if (debug) {
        usb_set_debug(255);
    } else {
        usb_set_debug(0);
    }

    usb_init();
    usb_find_busses();
    usb_find_devices();

    // Get an array of MAX_SENSORS
    available_devices = find_lvr_winusb();

    if (available_devices->sensor_count == 0) {
        if (debug) {
            printf("Couldn't find the USB device, Exiting\n");
        }
        return NULL;
    }
    int i;

    for (i = 0; i < available_devices->sensor_count; i++) {
        usb_dev_handle *lvr_winusb = available_devices->sensors[i];

        usb_detach(lvr_winusb, INTERFACE1);

        usb_detach(lvr_winusb, INTERFACE2);


        if (usb_set_configuration(lvr_winusb, 0x01) < 0) {
            if (debug) {
                printf("Could not set configuration 1\n");
            }
            return NULL;
        }

        // Microdia tiene 2 interfaces
        if (usb_claim_interface(lvr_winusb, INTERFACE1) < 0) {
            if (debug) {
                printf("Could not claim interface\n");
            }
            return NULL;
        }

        if (usb_claim_interface(lvr_winusb, INTERFACE2) < 0) {
            if (debug) {
                printf("Could not claim interface\n");
            }
            return NULL;
        }
    }
    return available_devices;
}
예제 #2
0
파일: pcsensor.c 프로젝트: raff/temper
static usb_dev_handle* setup_libusb_access() {
	usb_dev_handle *lvr_winusb;

	if(debug) {
		usb_set_debug(255);
	} else {
		usb_set_debug(0);
	}
	usb_init();
	usb_find_busses();
	usb_find_devices();

 
	if(!(lvr_winusb = find_lvr_winusb())) {
		if(debug){
			printf("Couldn't find the USB device, Exiting\n");
		}
		return NULL;
	}
        
        
	usb_detach(lvr_winusb, INTERFACE1);
        

	usb_detach(lvr_winusb, INTERFACE2);
        
 
	if (usb_set_configuration(lvr_winusb, 0x01) < 0) {
		if(debug){
			printf("Could not set configuration 1\n");
		}
		return NULL;
	}
 

	// Microdia tiene 2 interfaces
	if (usb_claim_interface(lvr_winusb, INTERFACE1) < 0) {
		if(debug){
			printf("Could not claim interface\n");
		}
		return NULL;
	}
 
	if (usb_claim_interface(lvr_winusb, INTERFACE2) < 0) {
		if(debug){
			printf("Could not claim interface\n");
		}
		return NULL;
	}
 
	return lvr_winusb;
}
예제 #3
0
파일: keene.c 프로젝트: cw7/keene-usb-audio
usb_dev_handle * GetFirstDevice(int vendorid, int productid) {
  struct usb_bus    *bus;
  struct usb_device *dev;

  usb_dev_handle    *device_handle = NULL; // it's a null

  usb_init();
  usb_set_debug(0);     /* 3 is the max setting */

  usb_find_busses();
  usb_find_devices();
 
  // Loop through each bus and device until you find the first match
  // open it and return it's usb device handle

  for (bus = usb_busses; bus; bus = bus->next) {
    for (dev = bus->devices; dev; dev = dev->next) {
      //if (dev->descriptor.idVendor == vendorid && dev->descriptor.idProduct == productid) {  
      if (dev->descriptor.idVendor == vendorid) {  
    device_handle = usb_open(dev);
    //
    // No device found
    if(!device_handle) {
      return NULL;
    }
    //fprintf(stderr," + Found audio transmiter on bus %s dev %s\n", dev->bus->dirname, dev->filename);
    return (device_handle);    
      }
    }
  }
  errno = ENOENT;       // No such device
  return (device_handle);  
}
예제 #4
0
/**
 * initialize this plugin
 */
static NftResult _init(void **privdata, LedHardware * hw)
{
        /** create niftylino descriptor */
        Niftylino *n;
        if(!(n = calloc(1, sizeof(Niftylino))))
        {
                NFT_LOG_PERROR("calloc");
                return NFT_FAILURE;
        }

        /* save Niftylino descriptor as private-data */
        *privdata = n;

        /* initialize default usb timeout */
        n->usb_timeout = 2500;

        /* save our hardware descriptor for later */
        n->hw = hw;

        /* initialize usb subsystem */
        usb_init();

        /* enable debugging */
        int level = 0;
        if(nft_log_level_is_noisier_than(nft_log_level_get(), L_VERBOSE))
                level = 3;
        else if(nft_log_level_is_noisier_than(nft_log_level_get(), L_INFO))
                level = 2;
        else if(nft_log_level_is_noisier_than(nft_log_level_get(), L_ERROR))
                level = 1;

        usb_set_debug(level);

        return NFT_SUCCESS;
}
예제 #5
0
struct usb_dev_handle* easyAVR_Open()
{
  struct usb_bus *busses;

  usb_set_debug(2);
  usb_init();
  usb_find_busses();
  usb_find_devices();

  busses = usb_get_busses();

  struct usb_dev_handle* usb_handle;
  struct usb_bus *bus;


  unsigned char send_data=0xff;

  for (bus = busses; bus; bus = bus->next)
  {
    struct usb_device *dev;

    for (dev = bus->devices; dev; dev = dev->next)
    {
      if (dev->descriptor.idVendor == 0x0400)
      {
        int i,stat;
        //printf("vendor: %i\n",dev->descriptor.idVendor);
        usb_handle = usb_open(dev);
        stat = usb_set_configuration (usb_handle,1);
	return usb_handle;
      }
    }
  }

}
예제 #6
0
usb_dev_handle* setup_libusb_access() 
{
	usb_dev_handle *lvr_winusb;

	usb_set_debug(255);
	usb_init();
	usb_find_busses();
	usb_find_devices();

	if(!(lvr_winusb = find_lvr_winusb())) 
	{
		printf("Couldn't find the USB device, Exiting\n");
		return NULL;
	}

	if (usb_set_configuration(lvr_winusb, 1) < 0) 
	{
		printf("Could not set configuration 1 : \n");
		return NULL;
	}

	if (usb_claim_interface(lvr_winusb, INTERFACE) < 0) 
	{
		printf("Could not claim interface: \n");
		return NULL;
	}

	return lvr_winusb;
}
예제 #7
0
//---------------------------------------------------------------------------
// Initialize the DS2490
//
void usb_ds2490_init(void)
{
	struct usb_bus *bus;
	struct usb_device *dev;

	// initialize USB subsystem
	usb_init();
	usb_set_debug(0);
	usb_find_busses();
	usb_find_devices();

      	//printf("bus/device  idVendor/idProduct\n");
	for (bus = usb_busses; bus; bus = bus->next) {
          for (dev = bus->devices; dev; dev = dev->next) {
	    //printf("%s/%s     %04X/%04X\n", bus->dirname, dev->filename,
            //  dev->descriptor.idVendor, dev->descriptor.idProduct);
            if (dev->descriptor.idVendor == 0x04FA &&
		dev->descriptor.idProduct == 0x2490) {
               ++usb_num_devices;
               usb_dev_list[usb_num_devices] = dev;
               //printf("Found DS2490 device #%d at %s/%s\n", usb_num_devices + 1,
               //bus->dirname, dev->filename);
            }
          }
        }

	initted_flag = 1;

}
예제 #8
0
파일: libusbses.c 프로젝트: rmanders/owpy
//---------------------------------------------------------------------------
// Discover all DS2490s on bus
//
void DS2490Discover(void)
{
	struct usb_bus *bus;
	struct usb_device *dev;

	// initialize USB subsystem
#ifdef LIBUSB_DEBUG_DISABLE  // Use this define at compile time to turn off LIBUSB debug info
   usb_set_debug(0);
#endif
   usb_init();
   usb_find_busses();
   usb_find_devices();

   usb_num_devices = 0; // avoid port zero to make it look like other builds

	for (bus = usb_get_busses(); bus; bus = bus->next) 
	{
		for (dev = bus->devices; dev; dev = dev->next) 
		{
			if (dev->descriptor.idVendor == 0x04FA &&
				 dev->descriptor.idProduct == 0x2490) 
			{
				usb_dev_list[++usb_num_devices] = dev;
			}
		}
	}
}
예제 #9
0
int main(int argc, char *argv[])
{
  struct usb_bus *bus;

  if (argc > 1 && !strcmp(argv[1], "-v"))
    verbose = 1;

  usb_init();
  usb_set_debug(0);

  usb_find_busses();
  usb_find_devices();

  for (bus = usb_get_busses(); bus; bus = bus->next) {
    if (bus->root_dev && !verbose)
      print_device(bus->root_dev, 0);
    else {
      struct usb_device *dev;

      for (dev = bus->devices; dev; dev = dev->next)
        print_device(dev, 0);
    }
  }

  return 0;
}
예제 #10
0
void CVolcraftCO20::GetSensorDetails()
{
	try
	{
		uint16_t voc;

		usb_init ();
		usb_set_debug (0);
		usb_find_busses ();
		usb_find_devices ();

		get_voc_value(USB_VENDOR_CO2_STICK,USB_PRODUCT_CO2_STICK,voc);
		if (voc!=0)
		{
			if (voc==3000)
			{
				_log.Log(LOG_ERROR, "Voltcraft CO-20: Sensor data out of range!!");
				return;
			}
			SendAirQualitySensor(1, 1, 255, voc, "Air Quality");
		}
	}
	catch (...)
	{
	
	}
}
예제 #11
0
파일: usb.c 프로젝트: helaibai/usbip
void usb_init(void)
{
  if (getenv("USB_DEBUG"))
    usb_set_debug(atoi(getenv("USB_DEBUG")));

  usb_os_init();
}
예제 #12
0
LibUsb::LibUsb()
{
    // dynamic load of libusb on Windows, it is statically linked in Linux
    // this is to avoid dll conflicts where the lib has already been installed
    this->intf = NULL;
    this->device = NULL;
    usb_set_debug(0);
}
예제 #13
0
파일: usb_io.cpp 프로젝트: z80/chassis
UsbIo::UsbIo()
{
    pd = new PD();
    pd->handle = 0;
    pd->timeout = PD::TIMEOUT;
    usb_init();
    usb_set_debug( 3 );
    pd->res.resize( 8 );
}
예제 #14
0
파일: keene.c 프로젝트: cw7/keene-usb-audio
// ** cleanup() *****************************************************
void cleanup() {
    usb_set_debug(0);
    // if we have the USB device, hand it back
    if (keenehandle) {
        usb_release_interface(keenehandle,2);
    }
    usb_close(keenehandle);
    exit(errno);
}
예제 #15
0
int
main(void)
{
	Temper *t;
	char buf[256];
	int i, ret;

	usb_set_debug(0);
	usb_init();
	usb_find_busses();
	usb_find_devices();

	t = TemperCreateFromDeviceNumber(0, USB_TIMEOUT, 0);
	if(!t) {
		perror("TemperCreate");
		exit(-1);
	}

	bzero(buf, 256);
	ret = TemperGetOtherStuff(t, buf, 256);
	if(t->debug) {
	  printf("Other Stuff (%d bytes):\n", ret);
	  for(i = 0; i < ret; i++) {
	    printf(" %02x", buf[i]);
	    if(i % 16 == 15) {
	      printf("\n");
	    }
	  }
	  printf("\n");
	}

	double tempc;
	double rh;

	if(TemperGetTempAndRelHum(t, &tempc, &rh) < 0) {
	  perror("TemperGetTemperatureAndRelHum");
	  exit(1);
	}
	/* printf("Temperature: %.2f°F, %.2f°C\tRelative humidity: %.2f%%\n", (9.0 / 5.0 * tempc + 32.0), tempc, rh); */
	double dew, tn, m;
	if (tempc > 0)
	{
		tn = 243.12;
		m = 17.62;
	}
	else
	{
		tn = 272.62;
		m = 22.46;
	}
	dew = tn * (log(rh/100)+(m*tempc/(tn+tempc))) / (m - log(rh/100) - (m*tempc/(tn+tempc)));

	printf("%.2f %.2f %.2f\n", tempc, rh, dew);

	return 0;
}
예제 #16
0
void initialise_usb(int verbose)
{
	usb_init();
	
	if (verbose) {
		fprintf(stderr, "Verbose mode enabled\n");
		usb_set_debug(2);
		debug = verbose;
	}
}
예제 #17
0
static int initialize(int dbg) {
	int n;
	/* Initialize libusb. */
	usb_init();
	if(dbg&1) usb_set_debug(1);
	n=usb_find_busses();
	if(n<0) return n;
	n=usb_find_devices();
	if(n<0) return n;
	return 1;
}
예제 #18
0
void LibUSButils::closeUsbDev(usb_dev_handle* portnum)
{
    usb_set_debug(0);       // We don't need this here

    if (portnum != 0)
    {
        Logger::Log(INFO, "Closing usb device");
        usb_release_interface(portnum, 0);
        usb_close(portnum);
        portnum = 0;
    }
}
예제 #19
0
LibUsb::LibUsb(int type) : type(type)
{

    intf = NULL;
    readBufIndex = 0;
    readBufSize = 0;

    // Initialize the library.
    usb_init();
    usb_set_debug(0);
    usb_find_busses();
    usb_find_devices();
}
예제 #20
0
	bool FalconCommLibFTDI::initLibFTDI()
	{
#if defined(LIBUSB_DEBUG)
		//Spam libusb messages
		usb_set_debug(10);
#endif
		if((m_deviceErrorCode = ftdi_init((m_falconDevice))) < 0)
		{
			m_errorCode = FALCON_COMM_DEVICE_ERROR;
			return false;
		}
		m_isInitialized = true;
		return true;
	}
예제 #21
0
	bool FalconCommLibFTDI::initLibFTDI()
	{
		LOG_INFO("Initializing communications");
#if defined(LIBUSB_DEBUG)
		//Spam libusb messages
		LOG_INFO("Setting libusb debug level");
		usb_set_debug(10);
#endif
		if((m_deviceErrorCode = ftdi_init((m_falconDevice))) < 0)
		{
			LOG_ERROR("Cannot initialize device");
			m_errorCode = FALCON_COMM_DEVICE_ERROR;
			return false;
		}
		m_isInitialized = true;
		return true;
	}
예제 #22
0
void initialize(void){
	int i, ret;

	usb_set_debug(0);
	usb_init();
	usb_find_busses();
	usb_find_devices();

	t = TemperCreateFromDeviceNumber(0, USB_TIMEOUT, 0);
	if(!t) {
		perror("TemperCreate");
		exit(-1);
	}



}
예제 #23
0
static int drv_BW_open(void)
{
    struct usb_bus *busses, *bus;
    struct usb_device *dev;

    lcd = NULL;

    info("%s: scanning USB for BWCT LCD...", Name);

    usb_set_debug(0);

    usb_init();
    usb_find_busses();
    usb_find_devices();
    busses = usb_get_busses();

    for (bus = busses; bus; bus = bus->next) {
	for (dev = bus->devices; dev; dev = dev->next) {
	    int c;
	    if (dev->descriptor.idVendor != LCD_USB_VENDOR)
		continue;
	    /* Loop through all of the configurations */
	    for (c = 0; c < dev->descriptor.bNumConfigurations; c++) {
		int i;
		for (i = 0; i < dev->config[c].bNumInterfaces; i++) {
		    int a;
		    for (a = 0; a < dev->config[c].interface[i].num_altsetting; a++) {
			if ((dev->descriptor.idProduct == LCD_USB_DEVICE) ||
			    ((dev->config[c].interface[i].altsetting[a].bInterfaceClass == 0xff) &&
			     (dev->config[c].interface[i].altsetting[a].bInterfaceSubClass == 0x01))) {
			    info("%s: found BWCT USB LCD on bus %s device %s", Name, bus->dirname, dev->filename);
			    interface = i;
			    lcd = usb_open(dev);
			    if (usb_claim_interface(lcd, interface) < 0) {
				error("%s: usb_claim_interface() failed!", Name);
				return -1;
			    }
			    return 0;
			}
		    }
		}
	    }
	}
    }
    return -1;
}
예제 #24
0
bool LibUsb::find()
{
    usb_set_debug(0);
    usb_find_busses();
    usb_find_devices();

    switch (type) {

    // Search USB busses for USB2 ANT+ stick host controllers
    default:
    case TYPE_ANT: return findAntStick();
              break;

    case TYPE_FORTIUS: return findFortius();
              break;
    }
}
예제 #25
0
static int
bulk_init(const char *device)
{
	struct usb_bus *bus;
	struct usb_device *dev;


	usb_init();

	if (verbose)
		usb_set_debug(verbose);

	usb_find_busses();
	usb_find_devices();

	xsv_handle = NULL;
	for (bus = usb_busses; bus; bus = bus->next) {
		for (dev = bus->devices; dev; dev = dev->next) {
			if (device && strcmp(dev->filename, device) != 0)
				continue;

			if (dev->descriptor.idVendor == 0x2207 &&
				(dev->descriptor.idProduct == 0x290a ||
				dev->descriptor.idProduct == 0x292a ||
				dev->descriptor.idProduct == 0x281a)) {
				xsv_handle = usb_open(dev);
				if (verbose) {
					printf("using rockchip device @ %s\n",
						dev->filename);
				}
				break;
			}
		}
	}

	if (xsv_handle) {
		usb_set_configuration(xsv_handle,1);
		usb_claim_interface(xsv_handle,0);
		usb_set_altinterface(xsv_handle,0);

		return 0;
	} else {
		return -1;
	}
}
예제 #26
0
파일: button.c 프로젝트: jaseg/takaratomy
struct usb_dev_handle *initPanel(unsigned int devnum) {
	struct usb_bus *bus;
	struct usb_bus *busses;
	struct usb_bus *GPbus;
	struct usb_device *dev;
	struct usb_device *GPdevice = NULL;
	struct usb_dev_handle *GPhandle = NULL;
	//Initialize libusb and have it scan for devices
	usb_init();
	usb_find_busses();
	usb_find_devices();
	busses = usb_get_busses();

	for(bus = busses; bus; bus = bus->next) {  //iterate over the linked list of USB busses.  usb_bus->next = NULL on the last device
		for(dev = bus->devices; dev; dev = dev->next) {  //iterate over the linked list of devices in this bus.  usb_bu
			//fprintf(stderr, "%s %s %X %X\n", bus->dirname, dev->filename, dev->descriptor.idVendor, dev->descriptor.idProduct);
			if((dev->descriptor.idVendor == VENDORID) && (dev->descriptor.idProduct == PRODUCTID)) {
				if(devnum == 0) {
					GPbus = bus;
					GPdevice = dev;
				} else {
					devnum--;
				}
			}
		}
	}
	if(GPdevice == NULL) {
		fprintf(stderr, "ERROR: USB button was not found!\n");
		printf("Did you perhaps forget to sudo or add a udev rule?\n");
		return NULL;
	}
	GPhandle = usb_open(GPdevice);
	if(GPhandle == NULL) {
		fprintf(stderr, "ERROR: USB button could not be opened!\n");
		printf("Did you perhaps forget to sudo or add a udev rule?\n");
		return NULL;
	}
	usb_set_debug(1);
	if(usb_claim_interface(GPhandle, 0) < 0){
		fprintf(stderr, "ERROR: Cannot claim interface!\n");
		return NULL;
	}
	return GPhandle;
}
예제 #27
0
파일: client.c 프로젝트: DerGenaue/usbprog
int main (int argc,char **argv)
{
	struct usb_dev_handle *usbprog_handle;
	struct usb_device *usbprog_device;
	int send_status;
	int open_status;
	unsigned char send_data[10000];
	unsigned char receive_data[64];

	usb_init();
	usb_set_debug(2);

 	if ((usbprog_handle = locate_usbprog())==0) 
	{
		printf("Could not open the USBprog device\n");
		return (-1);
	}  

	open_status = usb_set_configuration(usbprog_handle,1);
	printf("conf_stat=%d\n",open_status);
	
	open_status = usb_claim_interface(usbprog_handle,0);
	printf("claim_stat=%d\n",open_status);
	
	open_status = usb_set_altinterface(usbprog_handle,0);
	printf("alt_stat=%d\n",open_status);


	int k;
	for(k=0;k<10000;k++)
		send_data[k]=(unsigned char)k;


	send_data[0] = 0x77;
	send_data[1] = 0x88;

	usb_bulk_write(usbprog_handle,2,send_data,320,500);
	usb_bulk_read(usbprog_handle,2,receive_data,320,500);	

	usb_close(usbprog_handle);
}	
예제 #28
0
usb_dev_handle* LibUSButils::GetFirstDevice(int vendorid, int productid)
{
    struct usb_bus*    bus;
    struct usb_device* dev;

    usb_dev_handle*    device_handle = NULL; // it's a null

    usb_init();
    usb_set_debug(0);       /* 3 is the max setting */

    usb_find_busses();
    usb_find_devices();

    // Loop through each bus and device until you find the first match
    // open it and return it's usb device handle

    for (bus = usb_busses; bus; bus = bus->next)
    {
        for (dev = bus->devices; dev; dev = dev->next)
        {
            if (dev->descriptor.idVendor == vendorid && dev->descriptor.idProduct == productid)
            {
                device_handle = usb_open(dev);
                // Need error checking for when the device isn't found!
                if (!device_handle)
                {
                    Logger::Log(ERROR, "Couldn't open usb device: %s", strerror(errno));
                    // errno = Exxxxx;      // usb_open should set the error code.
                    return NULL;
                }

                Logger::ClearLastError();
                return (device_handle);
            }
        }
    }
    Logger::SetLastError("No Such device");
    errno = ENOENT;     // No such device
    return (device_handle);
}
예제 #29
0
gboolean 
output_init (void)
{
  struct usb_bus *bus;
  struct usb_device *_dev, *dev = NULL;
  gint intno = 0;

  usb_init ();
  usb_find_busses ();
  usb_find_devices ();
  
  usb_set_debug (10);
  
  for (bus = usb_busses; bus; bus = bus->next)
    for (_dev = bus->devices; _dev; _dev = _dev->next)
      if (_dev->descriptor.idVendor == VENDOR_ID &&
          _dev->descriptor.idProduct == PRODUCT_ID)
        dev = _dev;
  
  if (!dev) {
    g_warning ("device not found\n");
    return FALSE;
  }
  
  g_print ("device found: %s/%s (0x%04x/0x%04x)\n", 
           dev->bus->dirname, dev->filename,
           dev->descriptor.idVendor, dev->descriptor.idProduct);
  
  handle = usb_open (dev);

  if (usb_claim_interface (handle, intno) >= 0)
    g_print ("successfully claimed interface %d\n", intno);
  else
    {
      g_warning ("failed to claim interface %d\n", intno);
      return FALSE;
    }
      
  return TRUE;
}
예제 #30
0
파일: temper.c 프로젝트: czytom/temper
int
main(void)
{
	Temper *t;
	char buf[256];
	int i, ret;

	usb_set_debug(0);
	usb_init();
	usb_find_busses();
	usb_find_devices();

	t = TemperCreateFromDeviceNumber(0, USB_TIMEOUT, 0);
	if(!t) {
		perror("TemperCreate");
		exit(-1);
	}

/*
	TemperSendCommand(t, 10, 11, 12, 13, 0, 0, 2, 0);
	TemperSendCommand(t, 0x43, 0, 0, 0, 0, 0, 0, 0);
	TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0);
	TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0);
	TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0);
	TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0);
	TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0);
	TemperSendCommand(t, 0, 0, 0, 0, 0, 0, 0, 0);
*/


		float tempc;

		if(TemperGetTemperatureInC(t, &tempc) < 0) {
			perror("TemperGetTemperatureInC");
			exit(1);
		}
		printf("temperature %.2fF %.2fC\n", (9.0 / 5.0 * tempc + 32.0),
		       tempc);
	return 0;
}