joyconfig.cpp
Go to the documentation of this file.
00001 /*
00002  * joyconfig.cpp
00003  *
00004  *  Created on: Oct 24, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 
00009 #include <telekyb_hid/Joystick.hpp>
00010 #include <telekyb_base/TeleKyb.hpp>
00011 
00012 #include <hidapi.h>
00013 
00014 using namespace telekyb;
00015 
00016 int main(int argc, char* argv[])
00017 {
00018         TeleKyb::init(argc, argv, "tJoyConfig");
00019 
00020         int res;
00021         unsigned char buf[256];
00022         #define MAX_STR 255
00023         //wchar_t wstr[MAX_STR];
00024         hid_device *handle;
00025         //int i;
00026 
00027         struct hid_device_info *devs, *cur_dev;
00028 
00029         devs = hid_enumerate(0x0, 0x0);
00030         cur_dev = devs;
00031         while (cur_dev) {
00032                 printf("Device Found\n  type: %04hx %04hx\n  path: %s\n  serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
00033                 printf("\n");
00034                 printf("  Manufacturer: %ls\n", cur_dev->manufacturer_string);
00035                 printf("  Product:      %ls\n", cur_dev->product_string);
00036                 printf("  Release:      %hx\n", cur_dev->release_number);
00037                 printf("  Interface:    %d\n",  cur_dev->interface_number);
00038                 printf("\n");
00039                 cur_dev = cur_dev->next;
00040         }
00041         hid_free_enumeration(devs);
00042 
00043 
00044         handle = hid_open(0x054c, 0x0268, NULL);
00045         //handle = hid_open(0x046d, 0xc218, NULL);
00046         if (!handle) {
00047                 printf("unable to open device\n");
00048                 return 1;
00049         }
00050 
00051         hid_set_nonblocking(handle, 1);
00052 
00053         while(ros::ok()) {
00054                 if ((res = hid_read(handle, buf, sizeof(buf))) > 0) {
00055                         for (int i = 0; i < res; i++) {
00056                                 printf("%02hhx ", buf[i]);
00057                         }
00058                         printf("\n");
00059                 }
00060                 usleep(1000);
00061         }
00062 
00063 
00064         TeleKyb::shutdown();
00065         return 0;
00066 }
00067 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


telekyb_hid
Author(s): mriedel
autogenerated on Mon Nov 11 2013 11:14:51