Exemplo n.º 1
0
static struct bbc_i2c_bus *find_bus_for_device(struct linux_ebus_child *echild)
{
    struct bbc_i2c_bus *bp = all_bbc_i2c;

    while (bp != NULL) {
        if (find_device(bp, echild) != 0)
            break;
        bp = bp->next;
    }

    return bp;
}
Exemplo n.º 2
0
int init()
{
    usb_init();
    usbhandle = find_device(VENDOR_ID, PRODUCT_ID);
    if (usbhandle == NULL) {
        fprintf(stderr,
                "Could not find USB device with vid=0x%x pid=0x%x\n",
                VENDOR_ID, PRODUCT_ID);
        return -1;
    }
    return 0;
}
Exemplo n.º 3
0
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyaxis(JNIEnv * env, jobject obj, jint p_device, jint p_axis, jfloat p_value) {

	InputEvent ievent;
	ievent.type = InputEvent::JOYSTICK_MOTION;
	ievent.device = find_device(p_device);
	ievent.joy_motion.axis = p_axis;
	ievent.joy_motion.axis_value = p_value;

	input_mutex->lock();
	key_events.push_back(ievent);
	input_mutex->unlock();
};
Exemplo n.º 4
0
// The procedure for the child process.
void child(void) {
    message_t data_received;
    next_device = 0;
    int current_device;
    struct sigaction cleanup;

    cleanup.sa_handler = cleanup_child;
    sigemptyset(&cleanup.sa_mask);
    cleanup.sa_flags = 0;

    sigaction(SIGTERM, &cleanup, 0);

    shared_mem = shmat(shmid, (void *) 0, 0);
    if (shared_mem == (void *) -1) {
        fprintf(stderr, "shmat failed\n");
        exit(EXIT_FAILURE);
    }

    printf("Memory attached at %X\n", (long int)shared_mem);

    for (int i = 0; i < MAX_DEVICES; i++) {
        devices[i].has_partner = 0;
    }

    while(1) {

        receive_msg(msgid, (void *)&data_received, sizeof(packet_t), RECEIVE_TYPE, 0);

        // Registration vs Message Section
        if (data_received.msg_type == REGISTER_KEY) {
            register_device(&data_received, next_device++);
            continue;
        } else if (data_received.msg_type == MESSAGE_KEY) {
            current_device = find_device(data_received.packet.pid);
            // Ignore if the device hasn't registered yet
            if (current_device == -1) {
                fprintf(stderr, "Could not find device: %d\n", data_received.packet.pid);
                continue;
            }
        }
        // If the device dosen't have a partner then skip to the next message.
        if (!devices[current_device].has_partner) {
            continue;
        }

        // Message Recieved From Device
        if (data_received.packet.type) { // Actuator
            actuator(&data_received, current_device);
        } else { // Sensor
            sensor(&data_received, current_device);
        }
    }
}
Exemplo n.º 5
0
JNIEXPORT void JNICALL Java_com_android_godot_GodotLib_joybutton(JNIEnv * env, jobject obj, jint p_device, jint p_button, jboolean p_pressed) {

	InputEvent ievent;
	ievent.type = InputEvent::JOYSTICK_BUTTON;
	ievent.device = find_device(p_device);
	ievent.joy_button.button_index = p_button;
	ievent.joy_button.pressed = p_pressed;

	input_mutex->lock();
	key_events.push_back(ievent);
	input_mutex->unlock();
};
Exemplo n.º 6
0
/*-----------------------------------------------------------------*
*
*-----------------------------------------------------------------*/
PIC_device *init_pic(char *pic_type)
{
    char long_name[PIC14_STRING_LEN];

    pic = find_device(pic_type);

    if (pic == NULL) {
        /* check for shortened "16xxx" form */
        sprintf(long_name, "16%s", pic_type);
        pic = find_device(long_name);
        if (pic == NULL) {
            if(pic_type != NULL && pic_type[0] != '\0')
                fprintf(stderr, "'%s' was not found.\n", pic_type);
            else
                fprintf(stderr, "No processor has been specified (use -pPROCESSOR_NAME)\n");

            list_valid_pics(7);
            exit(1);
        }
    }
    return pic;
}
Exemplo n.º 7
0
int port_unregister(const char *path)
{
	struct serial_device *device;

	device = find_device(devices, path);
	if (!device)
		return -ENOENT;

	g_slist_free_full(device->ports, serial_port_free);

	g_dbus_unregister_interface(device->conn, path, SERIAL_PORT_INTERFACE);

	return 0;
}
Exemplo n.º 8
0
static int ca_open(struct inode *inode, struct file *file)
{
	struct ca_device *cadev = find_device(iminor(inode));

	if (!cadev)
		return -ENODEV;
	if (!cadev->users)
		return -EBUSY;

	dprintk("ca_open adapter%d - ca%d\n", cadev->adapter_num, cadev->device_num);

	cadev->users--;
	try_module_get(THIS_MODULE);
	return 0;
}
Exemplo n.º 9
0
int input_device_close_channels(const bdaddr_t *src, const bdaddr_t *dst)
{
    struct input_device *idev = find_device(src, dst);

    if (!idev)
        return -ENOENT;

    if (idev->intr_io)
        g_io_channel_shutdown(idev->intr_io, TRUE, NULL);

    if (idev->ctrl_io)
        g_io_channel_shutdown(idev->ctrl_io, TRUE, NULL);

    return 0;
}
Exemplo n.º 10
0
static int validate_device_opt(struct mp_log *log, const m_option_t *opt,
                               struct bstr name, struct bstr param)
{
    // Note: we do not check whether the device actually exist, because this
    //       might break elaborate configs with several AOs trying several
    //       devices. We do it merely for making "help" special.
    if (bstr_equals0(param, "help")) {
        if (!check_pa_ret(log, Pa_Initialize()))
            return M_OPT_EXIT;
        find_device(log, "help");
        Pa_Terminate();
        return M_OPT_EXIT - 1;
    }
    return 0;
}
Exemplo n.º 11
0
/* DoPrinter()
 * ===================================================================
 */
void
DoPrinter( void )
{
    DEV_PTR  curptr;
    FON_PTR  fonptr;
    int      i;

    Reset_Tree( ad_printer );

    /* Read in the UnUsed fonts, if necessary
     * This way, we have a list of ALL fonts.
     */
    
    if( !Fonts_Loaded )
    {
      MF_Save();
      Scan_Message( ad_scan, TRUE );	

      read_fonts( TRUE, FALSE );

      Scan_Message( ad_scan, FALSE );
      MF_Restore();
    }  

    free_arena_links();
    print_count = build_specific_list( &print_list, &print_last, BITMAP_FONT );

    /* Find the printer device */
    curptr = find_device( 21 );

    /* Find and set to SELECTED, the printer fonts on the device */
    if( curptr )
    {
      for( i = 0; i < DFCOUNT( curptr ); i++ )
      {
          fonptr = DFONT( curptr )[i];
	  if( fonptr )
	      AFLAG( fonptr ) = TRUE;
      }
    }

    mover_setup( print_list, print_count,
		 PRNTBASE, PRNTSLDR, PRNTUP, PRNTDOWN,
		 PLINE0, PLINE8, PLINE, 0, PRINT_HEIGHT );

    PrintInternalFlag = FALSE;    
    Objc_draw( tree, ROOT, MAX_DEPTH, NULL ); 
}
Exemplo n.º 12
0
static u32 pci_inl(u32 reg)
{
	u32 basereg = (reg & 0xfffc);
	pci_dev_t *dev;

	if (basereg == 0xcf8) {
		return pci_conf_addr;
	}

	/* still here? so we're 0xCFC */
	dev = find_device(pci_conf_addr);
	if (!dev || !dev->config)
		return 0xffffffff;

	return *(u32 *) (dev->config + (pci_conf_addr & 0xff));
}
Exemplo n.º 13
0
static char *get_disk_devname(const char *device)
{
	struct stat st;
	dev_t diskno = 0;
	char diskname[128];

	if (stat(device, &st) != 0)
		return NULL;

	/* get whole-disk devno */
	if (sysfs_devno_to_wholedisk(st.st_rdev, diskname,
				sizeof(diskname), &diskno) != 0)
		return NULL;

	return st.st_rdev == diskno ? NULL : find_device(diskname);
}
Exemplo n.º 14
0
static void
remove_device (const char *uuid)
{
        GtkWidget *treeview;
        GtkTreeModel *model;
        GtkTreeIter iter;
       
        treeview = GTK_WIDGET(gtk_builder_get_object (builder, "device-details-treeview"));
        g_assert (treeview != NULL);
        model = gtk_tree_view_get_model (GTK_TREE_VIEW (treeview));
        g_assert (model != NULL);
      
        if (find_device (model, uuid, &iter)) {
                gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
        }
}
Exemplo n.º 15
0
static void detect_dellink(unsigned short type, int index,
					unsigned flags, unsigned change)
{
	struct connman_device *device;

	DBG("type %d index %d", type, index);

	device = find_device(index);
	if (device == NULL)
		return;

	device_list = g_slist_remove(device_list, device);

	connman_device_unregister(device);
	connman_device_unref(device);
}
int usb_request(uint8_t bRequest, uint16_t wValue, uint16_t wIndex)
{
    if (usbhandle == NULL) {
        usbhandle = find_device(VENDOR_ID, PRODUCT_ID, usbSerialNum);
        if (usbhandle == NULL) {
            return -1;
        }

    }
    int result = libusb_control_transfer(usbhandle, 0x40, bRequest, wValue, wIndex, 0, 0, 1000);
    if (result < 0) {
        fprintf(stderr, "Warning: Problem communicating with USB device, closing handle: %s\n", libusb_strerror(result));
        libusb_close(usbhandle);
        usbhandle = NULL;
    }
    return result;
}
Exemplo n.º 17
0
int device_connect(struct device **devp, const char *device,
		   struct auplay_st *auplay, struct ausrc_st *ausrc)
{
	struct device *dev;
	int err = 0;

	if (!devp)
		return EINVAL;
	if (!str_isset(device))
		return ENODEV;

	dev = find_device(device);
	if (dev) {
		*devp = mem_ref(dev);
	}
	else {
		dev = mem_zalloc(sizeof(*dev), destructor);
		if (!dev)
			return ENOMEM;

		str_ncpy(dev->name, device, sizeof(dev->name));

		hash_append(ht_device, hash_joaat_str(device), &dev->le, dev);

		*devp = dev;

		debug("aubridge: created device '%s'\n", device);
	}

	if (auplay)
		dev->auplay = auplay;
	if (ausrc)
		dev->ausrc = ausrc;

	/* wait until we have both SRC+PLAY */
	if (dev->ausrc && dev->auplay && !dev->run) {

		dev->run = true;
		err = pthread_create(&dev->thread, NULL, device_thread, dev);
		if (err) {
			dev->run = false;
		}
	}

	return err;
}
Exemplo n.º 18
0
static void pci_outl(u32 reg, u32 val)
{
	u32 basereg = (reg & 0xfffc);
	pci_dev_t *dev;

	if (basereg == 0xcf8) {
		pci_conf_addr = val;
		return;
	}

	/* still here? so we're 0xCFC */
	dev = find_device(pci_conf_addr);
	if (!dev || !dev->config)
		return;

	*(u32 *) (dev->config + (pci_conf_addr & 0xff)) = val;
}
Exemplo n.º 19
0
static u8 pci_inb(u32 reg)
{
	u32 basereg = (reg & 0xfffc);
	u32 basepos = (reg & 0x03);
	pci_dev_t *dev;

	if (basereg == 0xcf8) {
		return (pci_conf_addr >> (basepos << 3));
	}

	/* still here? so we're 0xCFC */
	dev = find_device(pci_conf_addr);
	if (!dev || !dev->config)
		return 0xff;

	return dev->config[(pci_conf_addr + basepos) & 0xff];
}
Exemplo n.º 20
0
parsing_result_type_t joinPdoEntryMapping(EC_CONFIG * cfg, int pdo_index, EC_PDO_ENTRY_MAPPING * mapping)
{
    assert(mapping->device_position != -1);
    mapping->parent = find_device(cfg, mapping->device_position);
    if(mapping->parent == NULL)
    {
        printf("Can't find %d\n", mapping->device_position);
        return PARSING_ERROR;
    }
    mapping->pdo_entry = find_pdo_entry(mapping->parent, pdo_index, 
                                       mapping->index, mapping->sub_index);
    if(mapping->pdo_entry == NULL)
    {
        return PARSING_ERROR;
    }
    return ellAddOK(&mapping->parent->pdo_entry_mappings, &mapping->node);
}
Exemplo n.º 21
0
static u16 pci_inw(u32 reg)
{
	u32 basereg = (reg & 0xfffc);
	u32 basepos = (reg & 0x02);
	pci_dev_t *dev;

	if (basereg == 0xcf8) {
		return (pci_conf_addr >> (basepos << 3));
	}

	/* still here? so we're 0xCFC */
	dev = find_device(pci_conf_addr);
	if (!dev || !dev->config)
		return 0xffff;

	return *(u16 *) (dev->config + ((pci_conf_addr + basepos) & 0xff));
}
Exemplo n.º 22
0
Arquivo: uDMX.c Projeto: jte/udmx
void udmx_int(t_udmx *x, long n)	// x = the instance of the object; n = the int received in the left inlet
{
    unsigned char       buffer[8];
    int                 nBytes;

    if (n > 255) n=255;
    if (n < 0) n=0;
    if (x->channel > 512) x->channel=512;
    if (x->channel < 0) x->channel=0;

    if (!(x->dev_handle)) find_device(x);
    else {
        nBytes = usb_control_msg(x->dev_handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT,
                                 cmd_SetSingleChannel, n, x->channel, buffer, sizeof(buffer), 5000);
        if(nBytes < 0)
            if (x->debug_flag) error("udmx: USB error: %s", usb_strerror());
    }
}
Exemplo n.º 23
0
static int list_bootloader_devs(struct cli_state *state)
{
    int status;
    libusb_context *ctx;

    status = libusb_init(&ctx);
    if (status != 0) {
        return CMD_RET_UNKNOWN;
    }

    status = find_device(state, ctx, 0, 0, NULL, true);
    if (status == 0) {
        printf("\n");
    }

    libusb_exit(ctx);
    return status;
}
Exemplo n.º 24
0
Arquivo: uDMX.c Projeto: jte/udmx
void *udmx_new(long n)		// n = int argument typed into object box (A_DEFLONG) -- defaults to 0 if no args are typed
{
    t_udmx *x;				// local variable (pointer to a t_udmx data structure)

    x = (t_udmx *)pd_new(udmx_class); // create a new instance of this object

    // create a second int inlet (leftmost inlet is automatic - all objects have one inlet by default)
    // floatinlet_new(x, x->channel); //crashes on PD .... assigns float in inlet 2 directly to channel
    inlet_new(&x->p_ob, &x->p_ob.ob_pd, gensym("float"), gensym("ft1"));

    x->channel = 0;
    x->debug_flag = 0;
    x->dev_handle = NULL;

    find_device(x);

    return(x);					// return a reference to the object instance
}
Exemplo n.º 25
0
int main(int argc, char *argv[])
{
    printf("Headsetcontrol written by Sapd (Denis Arnst)\n\thttps://github.com/Sapd\n");

    if (argc != 2)
    {
        goto usage;
    }

    int loudness = strtol(argv[1], NULL, 10);
    if (loudness > 128 || loudness < 0)
        goto usage;


    if (init_libusb())
        return 1;

    libusb_device* device = find_device();
    if (!device)
    {
        printf("Couldn't find device");
        free_libusb();
        return 1;
    }

    if (open_device(device))
    {
        printf("Couldn't claim Device");
        close_device();
        free_libusb();
        return 1;
    }

    send_sidetone(loudness);

    close_device();
    free_libusb();

    return 0;

    usage:
    printf("Usage: %s 0-128\n\t(0 silent, 128 very loud)\n", argv[0]);
    return 0;
}
Exemplo n.º 26
0
//--------------------------------------------------------------------------
void *heavybox_new(t_symbol *s)		// s = optional argument typed into object box (A_SYM) -- defaults to 0 if no args are typed
{
	t_heavybox *x;									// local variable (pointer to a t_heavybox data structure)
	x = (t_heavybox *)pd_new(heavybox_class);			 // create a new instance of this object
    x->x_verbose = 0;
	x->dev_handle = NULL;
	find_device(x);
	
	int i;
	// create outlets and assign it to our outlet variable in the instance's data structure
	for (i=0; i < OUTLETS; i++) {
		x->outlets[i] = outlet_new(&x->p_ob, &s_float);
	}
	if (x->dev_handle) {
		usb_thread_start(x); //start polling the device
	}

	return x; // return a reference to the object instance
}
Exemplo n.º 27
0
static void pci_outb(u32 reg, u8 val)
{
	u32 basereg = (reg & 0xfffc);
	u32 basepos = (reg & 0x03);
	pci_dev_t *dev;

	if (basereg == 0xcf8) {
		pci_conf_addr &= (~(0xff << (basepos << 3)));
		pci_conf_addr |= (val << (basepos << 3));
		return;
	}

	/* still here? so we're 0xCFC */
	dev = find_device(pci_conf_addr);
	if (!dev || !dev->config)
		return;

	dev->config[pci_conf_addr & 0xff] = val;
}
Exemplo n.º 28
0
static int umount_partitions(const char *disk, int checkonly)
{
	struct sysfs_cxt cxt = UL_SYSFSCXT_EMPTY;
	dev_t devno;
	DIR *dir = NULL;
	struct dirent *d;
	int count = 0;

	devno = sysfs_devname_to_devno(disk, NULL);
	if (sysfs_init(&cxt, devno, NULL) != 0)
		return 0;

	/* open /sys/block/<wholedisk> */
	if (!(dir = sysfs_opendir(&cxt, NULL)))
		goto done;

	/* scan for partition subdirs */
	while ((d = readdir(dir))) {
		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
			continue;

		if (sysfs_is_partition_dirent(dir, d, disk)) {
			char *mnt = NULL;
			char *dev = find_device(d->d_name);

			if (dev && device_get_mountpoint(&dev, &mnt) == 0) {
				verbose(_("%s: mounted on %s"), dev, mnt);
				if (!checkonly)
					umount_one(mnt);
				count++;
			}
			free(dev);
			free(mnt);
		}
	}

done:
	if (dir)
		closedir(dir);
	sysfs_deinit(&cxt);

	return count;
}
Exemplo n.º 29
0
/** Search for a device under various product ID's. */
static libusb_device_handle *
find_device_list (int vendor,
	const int *products, size_t n_products, int *error)
{
	int err = 0;
	libusb_device_handle *handle;

	while (n_products--)
	{
		handle = find_device (vendor, *products++, &err);
		if (handle)
			return handle;
		if (err)
			break;
	}

	if (error != NULL && err != 0)
		*error = err;
	return NULL;
}
Exemplo n.º 30
0
/* DoPrintOK()
 * ===================================================================
 * Clear the printer devices fonts and then add in our newly selected ones.
 */
void
DoPrintOK( void )
{
    DEV_PTR  curptr;
    FON_PTR  fon_ptr;

    curptr = find_device(21);
    if( curptr )
    {
        ClearDeviceFont( curptr );

        fon_ptr = print_list;
	while( fon_ptr )
        {
	    if( AFLAG( fon_ptr ) )
		add_to_device( curptr, fon_ptr );
	    fon_ptr = FNEXT( fon_ptr );
        }
    }
}