ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/SteeringWheelRemote/SteeringWheelRemote.cpp
Revision: 2
Committed: 2007-04-25T21:28:10-07:00 (15 years, 7 months ago) by douglas
File size: 1478 byte(s)
Log Message:
Woo!

File Contents

# Content
1 // Steering Wheel Remote
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #include <cassert>
8 #include <iostream>
9 #include <set>
10 #include <sstream>
11 #include <string>
12
13 #include <dev/usb/usb.h>
14 #include <dev/usb/usbhid.h>
15 #include <err.h>
16 #include <fcntl.h>
17 #include <sys/ioctl.h>
18 #include <usbhid.h>
19
20 #include <foreach.hpp>
21 #include <posix.hpp>
22
23 inline std::ostream &operator <<(std::ostream &output, uint8_t number)
24 {
25 return output << unsigned(number);
26 }
27
28 std::set<std::string> AirClicks()
29 {
30 std::set<std::string> airclicks;
31
32 _forall (unsigned, number, 0, 10)
33 {
34 std::ostringstream device_;
35
36 device_ << "/dev/usb" << number;
37
38 const std::string &device(device_.str());
39
40 try
41 {
42 int usb(Posix::CheckError(::open(device.c_str(), O_RDONLY)));
43
44 _forall (uint8_t, address, 1, USB_MAX_DEVICES)
45 {
46 usb_device_info info;
47
48 info.udi_addr = address;
49
50 try
51 {
52 Posix::CheckError(::ioctl(usb, USB_DEVICEINFO, &info));
53 }
54 catch (const Posix::Error &error)
55 {
56 if (error.GetCode() != ENXIO)
57 ::warn("%s: address %u", device.c_str(), address);
58
59 continue;
60 }
61
62 std::cout << info.udi_product << std::endl;
63 }
64
65 Posix::CheckError(::close(usb));
66 }
67 catch (const Posix::Error &error)
68 {
69 switch (error.GetCode())
70 {
71 case ENOENT:
72 case ENXIO:
73 continue;
74 default:
75 ::warn("%s", device.c_str());
76 }
77 }
78 }
79
80 return airclicks;
81 }
82
83 int main(int argc, char *argv[])
84 {
85 std::set<std::string> airclicks(AirClicks());
86
87 return 0;
88 }

Properties

Name Value
svn:keywords Id