1// -*- C++;indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*- 2/* 3 * get_resolution.cpp 4 * 5 * Note that this testcase fails if not run as root 6 * 7 * Test suite program for C++ bindings 8 */ 9 10#include <iostream> 11#include <iomanip> 12#include <usbpp.h> 13 14#define VENDOR_LOGITECH 0x046D 15 16using namespace std; 17 18int main(void) 19{ 20 USB::Busses buslist; 21 USB::Device *device; 22 list<USB::Device *> miceFound; 23 list<USB::Device *>::const_iterator iter; 24 unsigned char resolution[1]; 25 26 resolution[0] = 'Z'; 27 28 cout << "idVendor/idProduct/bcdDevice" << endl; 29 30 USB::DeviceIDList mouseList; 31 32 mouseList.push_back(USB::DeviceID(VENDOR_LOGITECH, 0xC00E)); // Wheel Mouse Optical 33 mouseList.push_back(USB::DeviceID(VENDOR_LOGITECH, 0xC012)); // MouseMan Dual Optical 34 mouseList.push_back(USB::DeviceID(VENDOR_LOGITECH, 0xC00F)); // MouseMan Traveler 35 mouseList.push_back(USB::DeviceID(VENDOR_LOGITECH, 0xC024)); // MX300 optical 36 mouseList.push_back(USB::DeviceID(VENDOR_LOGITECH, 0xC025)); // MX500 optical 37 mouseList.push_back(USB::DeviceID(VENDOR_LOGITECH, 0xC031)); // iFeel Mouse (silver) 38 39 miceFound = buslist.match(mouseList); 40 41 for (iter = miceFound.begin(); iter != miceFound.end(); iter++) { 42 device = *iter; 43 cout << hex << setw(4) << setfill('0') 44 << device->idVendor() << " / " 45 << hex << setw(4) << setfill('0') 46 << device->idProduct() << " / " 47 << hex << setw(4) << setfill('0') 48 << device->idRevision() << " " 49 << endl; 50 51 if ( 0 > device->controlTransfer(USB_TYPE_VENDOR | USB_ENDPOINT_IN, 52 0x01, 53 0x000E, 54 0x0000, 55 0x0001, 56 resolution) ) { 57 cout << "control transfer test failed: " << usb_strerror() << endl; 58 return EXIT_FAILURE; 59 } 60 61 if (3 == resolution[0]) { 62 cout << "Resolution is 400cpi" << endl; 63 } else if (4 == resolution[0]) { 64 cout << "Resolution is 800cpi" << endl; 65 } else { 66 cout << "Unexpected resolution result" << endl; 67 } 68 } 69 70 return 0; 71} 72