HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path) { hid_device *dev; HIDP_CAPS caps; HIDP_PREPARSED_DATA *pp_data = NULL; BOOLEAN res; NTSTATUS nt_res; #ifndef HIDAPI_USE_DDK if (!initialized) lookup_functions(); #endif dev = new_hid_device(); // Open a handle to the device dev->device_handle = open_device(path); // Check validity of write_handle. if (dev->device_handle == INVALID_HANDLE_VALUE) { // Unable to open the device. register_error(dev, "CreateFile"); goto err; } // Get the Input Report length for the device. res = HidD_GetPreparsedData(dev->device_handle, &pp_data); if (!res) { register_error(dev, "HidD_GetPreparsedData"); goto err; } nt_res = HidP_GetCaps(pp_data, &caps); if (nt_res != HIDP_STATUS_SUCCESS) { register_error(dev, "HidP_GetCaps"); goto err_pp_data; } dev->input_report_length = caps.InputReportByteLength; HidD_FreePreparsedData(pp_data); dev->read_buf = (char*) malloc(dev->input_report_length); return dev; err_pp_data: HidD_FreePreparsedData(pp_data); err: CloseHandle(dev->device_handle); free(dev); return NULL; }
HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path) { hid_device *dev; HIDP_CAPS caps; PHIDP_PREPARSED_DATA pp_data = NULL; BOOLEAN res; NTSTATUS nt_res; if (hid_init() < 0) { return NULL; } dev = new_hid_device(); /* Open a handle to the device */ dev->device_handle = open_device(path, FALSE); /* Check validity of write_handle. */ if (dev->device_handle == INVALID_HANDLE_VALUE) { /* Unable to open the device. */ register_error(dev, "CreateFile"); goto err; } /* Get the Input Report length for the device. */ res = HidD_GetPreparsedData(dev->device_handle, &pp_data); if (!res) { register_error(dev, "HidD_GetPreparsedData"); goto err; } nt_res = HidP_GetCaps(pp_data, &caps); if (nt_res != HIDP_STATUS_SUCCESS) { register_error(dev, "HidP_GetCaps"); goto err_pp_data; } dev->output_report_length = caps.OutputReportByteLength; dev->input_report_length = caps.InputReportByteLength; HidD_FreePreparsedData(pp_data); dev->read_buf = (char*) malloc(dev->input_report_length); return dev; err_pp_data: HidD_FreePreparsedData(pp_data); err: CloseHandle(dev->device_handle); free(dev); return NULL; }
/* This function parses generic wscons status events. Actually, it * handles the screen switch event to enable or disable the mouse, * depending if we are entering or leaving the X console. */ static void generic_wscons_event(struct wscons_event evt) { switch (evt.type) { case WSCONS_EVENT_SCREEN_SWITCH: if (evt.value == X_Console) { Mouse.m_disabled = 1; (void)close(Mouse.m_devfd); Mouse.m_devfd = -1; } else { if (Mouse.m_disabled) { open_device(X_Console_Delay); Mouse.m_disabled = 0; } else { (void)close(Mouse.m_devfd); Mouse.m_devfd = -1; open_device(0); } } break; } }
int ploop_complete_running_operation(const char *device) { struct ploop_balloon_ctl b_ctl; int fd, ret; fd = open_device(device); if (fd == -1) return SYSEXIT_OPEN; bzero(&b_ctl, sizeof(b_ctl)); b_ctl.keep_intact = 1; ret = ioctl(fd, PLOOP_IOC_BALLOON, &b_ctl); if (ret) { ploop_err(errno, "Unable to get in-kernel maintenance state"); ret = SYSEXIT_DEVIOC; goto err; } if (b_ctl.mntn_type == PLOOP_MNTN_OFF) goto err; ploop_log(0, "Completing an on-going operation %s for device %s", mntn2str(b_ctl.mntn_type), device); switch (b_ctl.mntn_type) { case PLOOP_MNTN_MERGE: ret = ioctl_device(fd, PLOOP_IOC_MERGE, 0); break; case PLOOP_MNTN_GROW: ret = ioctl_device(fd, PLOOP_IOC_GROW, 0); break; case PLOOP_MNTN_RELOC: case PLOOP_MNTN_FBLOADED: ret = ploop_balloon_complete(device); break; case PLOOP_MNTN_TRACK: ret = ioctl_device(fd, PLOOP_IOC_TRACK_ABORT, 0); break; case PLOOP_MNTN_DISCARD: ret = ploop_balloon_complete(device); break; case PLOOP_MNTN_BALLOON: /* FIXME : ploop_balloon_check_and_repair(device, mount_point, 1; */ ret = 0; break; } err: close(fd); return ret; }
int libaacs_open(BD_AACS *p, const char *device, void *file_open_handle, void *file_open_fp, const char *keyfile_path) { int error_code = 0; fptr_p_void open; fptr_p_void open2; fptr_p_void init; fptr_int open_device; fptr_int aacs_get_mkb_version; fptr_p_void aacs_get_disc_id; _libaacs_close(p); *(void **)(&open) = dl_dlsym(p->h_libaacs, "aacs_open"); *(void **)(&open2) = dl_dlsym(p->h_libaacs, "aacs_open2"); *(void **)(&init) = dl_dlsym(p->h_libaacs, "aacs_init"); *(void **)(&aacs_get_mkb_version) = dl_dlsym(p->h_libaacs, "aacs_get_mkb_version"); *(void **)(&aacs_get_disc_id) = dl_dlsym(p->h_libaacs, "aacs_get_disc_id"); *(void **)(&open_device) = dl_dlsym(p->h_libaacs, "aacs_open_device"); if (init && open_device) { p->aacs = init(); DL_CALL(p->h_libaacs, aacs_set_fopen, p->aacs, file_open_handle, file_open_fp); error_code = open_device(p->aacs, device, keyfile_path); } else if (open2) { BD_DEBUG(DBG_BLURAY, "Using old aacs_open2(), no UDF support available\n"); p->aacs = open2(device, keyfile_path, &error_code); } else if (open) { BD_DEBUG(DBG_BLURAY, "Using old aacs_open(), no verbose error reporting available\n"); p->aacs = open(device, keyfile_path); } else { BD_DEBUG(DBG_BLURAY, "aacs_open() not found\n"); } if (p->aacs) { if (aacs_get_mkb_version) { p->mkbv = aacs_get_mkb_version(p->aacs); } if (aacs_get_disc_id) { p->disc_id = (const uint8_t *)aacs_get_disc_id(p->aacs); } return error_code; } return error_code ? error_code : 1; }
static int slot_msg_wrapper(const char* devname, int mode, const void* argp) { int rc = 0; struct sbd_context *st; const struct slot_msg_arg_t* arg = (const struct slot_msg_arg_t*)argp; st = open_device(devname, LOG_WARNING); if (!st) return -1; cl_log(LOG_INFO, "Delivery process handling %s", devname); rc = slot_msg(st, arg->name, arg->msg); close_device(st); return rc; }
DmtSensor::DmtSensor() : SensorBase(ACC_DEV_PATH_NAME, ACC_INPUT_NAME), mEnabled(1), mDelay(10000), mLayout(1), mInputReader(32), mHasPendingEvent(false) { mPendingEvent.version = sizeof(sensors_event_t); mPendingEvent.sensor = ID_A; mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER; memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); open_device(); }
TSS_RESULT Tddli_Open() { TSS_RESULT res; tddli_mutex_lock(&tddli_lock); if (tddli_dh != -1) { res = TDDL_E_ALREADY_OPENED; } else { res = open_socket(tpmd_socket_name); if (res != TDDL_SUCCESS) { res = open_device(tpm_device_name); } } tddli_mutex_unlock(&tddli_lock); return res; }
static void setup(void) { tst_require_root(); fd = open_uinput(); SAFE_IOCTL(NULL, fd, UI_SET_EVBIT, EV_KEY); SAFE_IOCTL(NULL, fd, UI_SET_EVBIT, EV_REP); SAFE_IOCTL(NULL, fd, UI_SET_KEYBIT, KEY_X); create_device(fd); fd2 = open_device(); SAFE_IOCTL(NULL, fd2, EVIOCGRAB, 1); }
struct libinput * tools_open_backend(struct tools_context *context) { struct libinput *li = NULL; struct tools_options *options = &context->options; if (options->backend == BACKEND_UDEV) { li = open_udev(&interface, context, options->seat, options->verbose); } else if (options->backend == BACKEND_DEVICE) { li = open_device(&interface, context, options->device, options->verbose); } else abort(); return li; }
void* startcapture(void* dev) { can_stop = 1; capture* d = get_cap(); dev_name = d->device; wigth = d->weigth; heigth = d->height; open_device(); init_device(); start_capturing(); mainloop(d->refresh); stop_capturing(); uninit_device(); close_device(); return 0; }
int main() { int file = open_device("/dev/i2c-2", 0x42); char line[512]; uint16_t more = 0; while (1) { more = read_line3(file, line, 512); if (more) { printf("%x -> %s\n", more, line); } } return 0; }
static int KSAPI beeperr(ks_reader_dev_t *dev) { int ret=0; int len; unsigned char data[256]; if(!g_dev_hd) { ret=open_device(dev); if(ret) return ret; } // len = 5; memcpy(data,"\x90\xB0\x0D\xA0\x00",len); do_send_recv_pos_cmd(data,len,data,len,g_default_timeout); return 0; }
transport_t rf2500_open(const char *devpath, const char *requested_serial) { struct rf2500_transport *tr = malloc(sizeof(*tr)); struct usb_device *dev; char buf[64]; if (!tr) { pr_error("rf2500: can't allocate memory"); return NULL; } tr->base.destroy = usbtr_destroy; tr->base.send = usbtr_send; tr->base.recv = usbtr_recv; usb_init(); usb_find_busses(); usb_find_devices(); if (devpath) dev = usbutil_find_by_loc(devpath); else dev = usbutil_find_by_id(USB_FET_VENDOR, USB_FET_PRODUCT, requested_serial); if (!dev) { free(tr); return NULL; } if (open_device(tr, dev) < 0) { printc_err("rf2500: failed to open RF2500 device\n"); return NULL; } /* Flush out lingering data. * * The timeout apparently doesn't work on OS/X, and this loop * just hangs once the endpoint buffer empties. */ #ifndef __APPLE__ while (usb_bulk_read(tr->handle, USB_FET_IN_EP, buf, sizeof(buf), 100) > 0); #endif return (transport_t)tr; }
int camera_work() { cam_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (cam_window), 0); gtk_window_set_title (GTK_WINDOW (cam_window), "Camera"); gtk_window_set_position(GTK_WINDOW(cam_window), GTK_WIN_POS_CENTER); gtk_widget_set_size_request(cam_window, preview_width, preview_height + 40 + 30); g_signal_connect (G_OBJECT (cam_window), "delete_event", G_CALLBACK (delete_event), NULL); layout = gtk_fixed_new (); gtk_widget_set_size_request(layout, preview_width, preview_height + 40 + 30); gtk_container_add(GTK_CONTAINER(cam_window), layout); image_face = gtk_drawing_area_new (); gtk_widget_set_size_request(image_face, preview_width, preview_height); gtk_fixed_put(GTK_FIXED(layout), image_face, 0, 0); ok_btn = gtk_button_new_with_label("OK"); gtk_widget_set_size_request(ok_btn, 50, 30); gtk_fixed_put(GTK_FIXED(layout), ok_btn, preview_width - 20 - 20 - 50 * 2, preview_height + 20); g_signal_connect (G_OBJECT (ok_btn), "clicked", G_CALLBACK (ok_btn_cb), cam_window); ng_btn = gtk_button_new_with_label("NG"); gtk_widget_set_size_request(ng_btn, 50, 30); gtk_fixed_put(GTK_FIXED(layout), ng_btn, preview_width - 50 - 20, preview_height + 20); g_signal_connect (G_OBJECT (ng_btn), "clicked", G_CALLBACK (ng_btn_cb), cam_window); gtk_widget_show_all(cam_window); open_device(); init_device(); stream_on(); // defined in color.h, and used to pixel format changing initLut(); timeId = g_timeout_add(1000/FPS, show_camera, NULL); gtk_main (); freeLut(); stream_off(); mem_unmap_and_close_dev(); return 0; }
/** open the is major switching function. Depending on node, * the type of Entity is constructed and returned. */ VFS::Entity* open( int pid, const char *node ) { printf("%s(%i,%s)\n","open: ", pid, node ); // Determine what kind of Entity must be created. // Device Tree if ( strncmp( node, "/device/", strlen("/device/") ) == 0 ) { return open_device( pid, node ); } // Finally, a FileEntity. return open_file( pid, node ); }
int rdopen(dev_t dev, int mode, int flag) { int root = major(dev); if (root > MAXDEV) return ENODEV; int unit = disks[root].unit; int e = open_device(root, flag); if (e != 0) return e; e = disks[root].open(unit, mode, flag); if (e != 0) return e; return 0; }
struct libinput * tools_open_backend(struct tools_options *options, void *userdata, const struct libinput_interface *interface) { struct libinput *li = NULL; if (options->backend == BACKEND_UDEV) { li = open_udev(interface, userdata, options->seat, options->verbose); } else if (options->backend == BACKEND_DEVICE) { li = open_device(interface, userdata, options->device, options->verbose); } else abort(); return li; }
/*===========================================================================*/ int pointit_init_cap(int w, int h) { /* TODO: Make this load from a config file */ cam_width = w; cam_height = h; cam_dev_name = "/dev/video0"; /* Make room for an RGB bitmap */ rgb_img = (unsigned char*)malloc(cam_width * cam_height * 3); if (open_device() != 0) return -1; if (init_device() != 0) return -1; if (start_capturing() != 0) return -1; return 0; }
int write_gpio(unsigned char *val) { int fd; if((fd = open_device()) < 0) return -1; if(i2c_smbus_write_byte_data(fd, OUTPUT0, val[0]) == -1){ printf("ERR%d: %s\n", __LINE__, strerror(errno)); close(fd); return -1; } close(fd); return 0; }
SensorKXTF9::SensorKXTF9() : SensorBase(KXTF9_DEVICE_NAME, "accelerometer"), mEnabled(0), mInputReader(32) { mPendingEvent.version = sizeof(sensors_event_t); mPendingEvent.sensor = SENSOR_TYPE_ACCELEROMETER; mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER; mPendingEvent.acceleration.status = SENSOR_STATUS_ACCURACY_HIGH; open_device(); mEnabled = isEnabled(); if (!mEnabled) close_device(); }
/* handle -x option */ static void set_device_speed(char *name) { int fd; if (!x_option) return; if (x_arg == 0) verbose(_("setting CD-ROM speed to auto")); else verbose(_("setting CD-ROM speed to %ldX"), x_arg); fd = open_device(name); select_speed(fd, x_arg); exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { max_maxfile_t *maxfile = max_maxfile_init_PassThrough(); max_device_handle_t *device = open_device(maxfile, argc, argv); float *x = (float *) malloc( n * sizeof(float) ); float *res = (float *) malloc( n * sizeof(float) ); printf("Initializing data ... "); int i; for (i = 0; i < n; i++) { res[i]=0; x[i] = 2 * i; } printf("done!\n"); printf("Initializing FPGA ... "); max_kernel_set_cycles(device, "PassThroughKernel", n, FPGA_A); max_redirect_sim_debug_output(device, "printf_output.txt" ) ; max_stream_handle_t *in_x = max_get_pcie_stream(device, "x"); max_stream_handle_t *out_y = max_get_pcie_stream(device, "y"); printf("done!\n"); printf("Processing data in FPGA ... "); max_reset_device(device); max_queue_pcie_stream(device, in_x, x, n * sizeof(float), 1); max_queue_pcie_stream(device, out_y, res, n * sizeof(float), 1); max_sync_pcie_stream(device, out_y); printf("done!\n"); printf("Checking results...\n"); for (i = 0; i < n; i++) if (res[i] != 2 *i) printf("Error : %f at %d! [Expected %f] \n", res[i], i, 2 * i); printf("done\n"); printf("Shutting down ... "); max_close_device(device); max_destroy(maxfile); printf("done!\n"); free(x); free(res); return 0; }
static int v4l2_select_output_stream(void* user_ptr, int test_num) { v4l2_data* data = (v4l2_data*)user_ptr; int i=0; if (!open_device(data->device)) { BLTS_DEBUG("Can't open device %s\n", data->device->dev_name); return -1; } while(1) { errno = 0; if(-1 == has_output(data->device, i) && !i) goto force_testing; else if(errno == EINVAL) break; else if (errno) goto err; if(-1 == try_output(data->device, i)) if(errno != EINVAL) goto err; if(-1 == get_output(data->device, &i)) if(errno != EINVAL) goto err; i++; } close_device(data->device); return 0; force_testing: BLTS_DEBUG("No output device available, force testing IOCTL\n"); if(try_output(data->device, 0)) if(errno != EINVAL) goto err; if(get_output(data->device, &i)) if(errno != EINVAL) goto err; return 0; err: close_device(data->device); return -1; }
int CameraManager::initializeCamera(int _width, int _height) { width = _width; height = _height; std::cout << "Hej4" << std::endl; open_device(); init_device(); start_capturing(); std::cout << "Hej10" << std::endl; return 0; }
InputDeviceProvider_Win32Hid::InputDeviceProvider_Win32Hid(HANDLE rawinput_device) : rawinput_device(rawinput_device) { DataBuffer preparse_data = get_preparse_data(); HANDLE device = open_device(); try { find_names(device); find_button_names(device, preparse_data.get_data()); find_value_names(device, preparse_data.get_data()); CloseHandle(device); } catch (...) { CloseHandle(device); throw; } }
int ploop_balloon_complete(const char *device) { int fd, err; struct ploop_balloon_ctl b_ctl; fd = open_device(device); if (fd == -1) return SYSEXIT_OPEN; err = ioctl(fd, PLOOP_IOC_DISCARD_FINI); if (err && errno != EBUSY) { ploop_err(errno, "Can't finalize discard mode"); err = SYSEXIT_DEVIOC; goto out; } memset(&b_ctl, 0, sizeof(b_ctl)); b_ctl.keep_intact = 1; err = ioctl_device(fd, PLOOP_IOC_BALLOON, &b_ctl); if (err) goto out; switch (b_ctl.mntn_type) { case PLOOP_MNTN_BALLOON: case PLOOP_MNTN_MERGE: case PLOOP_MNTN_GROW: case PLOOP_MNTN_TRACK: case PLOOP_MNTN_OFF: ploop_log(0, "Nothing to complete: kernel is in \"%s\" state", mntn2str(b_ctl.mntn_type)); goto out; case PLOOP_MNTN_RELOC: case PLOOP_MNTN_FBLOADED: break; default: ploop_err(0, "Error: unknown mntn_type (%u)", b_ctl.mntn_type); err = SYSEXIT_PROTOCOL; goto out; } err = ploop_balloon_relocation(fd, &b_ctl, device); out: close(fd); return err; }
AccSensor::AccSensor() : SensorBase(DIR_DEV, INPUT_NAME_ACC), mEnabled(0), mFusionEnabled(0), mDelayCur(-1), mDelayAcc(-1), mDelayFus(-1), mInputReader(32), mHasPendingEvent(false) { mPendingEvent.version = sizeof(sensors_event_t); mPendingEvent.sensor = ID_A; mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER; memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data)); open_device(); }
int main(int argc, char* argv[]) { query_arg_t q; int state = process_args(argc, argv, &q); int fd = open_device(); if(state == D_READ) { print_err(ioctl(fd, MINDGEM_READ, &q)); printf("0x%X+%X: %X\n", q.address, q.offset, q.value); } else { print_err(ioctl(fd, MINDGEM_WRITE, &q)); } close(fd); return 0; }
int main(int argc, char **argv) { printf("*** 16 channel PWM/Servo test program 4 ***\n"); int file; char filename[20]; char wr_buf[10]; int addr = PWM_16CH; int c; file = open_device(filename); set_port(file, addr); printf("Enter an angel: "); scanf("%d",&c); while (c > 0) { if (c > 179 || c < 1) { c = 90; } // calculate the corresponding value for the entered angel float value = (240 - c) / 0.4; int int_val = (int)value; uint16_t val_hex = (uint16_t)int_val; // fix lo/hi byte uint8_t lo_byte = val_hex & 0xff; uint8_t hi_byte = val_hex>>8 & 0xff; // write to registers wr_buf[0] = LED0_OFF_L; wr_buf[1] = lo_byte; write_byte(file,wr_buf); wr_buf[0] = LED0_OFF_H; wr_buf[1] = hi_byte; write_byte(file,wr_buf); printf("Enter an angel: "); scanf("%d",&c); } return 0; }