ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/SteeringWheelRemote/SteeringWheelRemote.cpp
Revision: 4
Committed: 2007-04-26T05:19:05-07:00 (15 years, 7 months ago) by douglas
File size: 1411 byte(s)
Log Message:
For certain definitions!

File Contents

# User Rev Content
1 douglas 1 // Steering Wheel Remote
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #include <iostream>
8     #include <string>
9    
10 douglas 2 #include <err.h>
11 douglas 1 #include <fcntl.h>
12 douglas 4 #include <sys/ioctl.h>
13 douglas 1
14 douglas 3 #include <common.hpp>
15 douglas 4 #include <fdstream.hpp>
16 douglas 2 #include <foreach.hpp>
17     #include <posix.hpp>
18 douglas 3 #include <regex.hpp>
19 douglas 2
20 douglas 3 int Usage(const std::string &program)
21 douglas 1 {
22 douglas 3 std::cout << _B("Usage: ") << program << _B(" [-debug] [-device=device]") << std::endl;
23    
24     return 1;
25 douglas 2 }
26    
27 douglas 3 int main(int argc, char *argv[])
28 douglas 2 {
29 douglas 3 bool debug(false);
30     std::string device;
31 douglas 2
32 douglas 1 {
33 douglas 3 Pcre::RegEx devicePath(_B("^-device=(/.+)$"));
34     Pcre::RegEx deviceNumber(_B("^-device=([0-9]+)$"));
35     Pcre::RegEx deviceName(_B("^-device=(.+)$"));
36 douglas 1
37 douglas 3 _forall (int, index, 1, argc)
38     if (argv[index] == _B("-debug"))
39     debug = true;
40     else if (Pcre::RegEx::Match match = devicePath(argv[index]))
41     device = match[1];
42     else if (Pcre::RegEx::Match match = deviceNumber(argv[index]))
43     device = _B("/dev/uhid") + match[1];
44     else if (Pcre::RegEx::Match match = deviceName(argv[index]))
45     device = _B("/dev/") + match[1];
46     else
47     return Usage(argv[0]);
48 douglas 1 }
49    
50 douglas 3 if (device.empty())
51     return Usage(argv[0]);
52 douglas 2
53 douglas 4 // if (!debug)
54     // Posix::CheckError(::daemon(0, 0));
55 douglas 2
56 douglas 4 ext::ifdstream uhid(Posix::CheckError(::open(device.c_str(), O_RDONLY)));
57     char buffer[8];
58    
59     while (uhid.read(buffer, sizeof (buffer)))
60     _forall (int, index, 0, 8)
61     std::printf("0x%08x 0x%08x\n", buffer[3], ~buffer[4] - 0x4);
62    
63 douglas 1 return 0;
64     }

Properties

Name Value
svn:keywords Id