// Steering Wheel Remote // // Douglas Thrift // // $Id$ #include #include #include #include #include #include #include #include #include #include int Usage(const std::string &program) { std::cout << _B("Usage: ") << program << _B(" [-debug] [-device=device]") << std::endl; return 1; } int main(int argc, char *argv[]) { bool debug(false); std::string device; { Pcre::RegEx devicePath(_B("^-device=(/.+)$")); Pcre::RegEx deviceNumber(_B("^-device=([0-9]+)$")); Pcre::RegEx deviceName(_B("^-device=(.+)$")); _forall (int, index, 1, argc) if (argv[index] == _B("-debug")) debug = true; else if (Pcre::RegEx::Match match = devicePath(argv[index])) device = match[1]; else if (Pcre::RegEx::Match match = deviceNumber(argv[index])) device = _B("/dev/uhid") + match[1]; else if (Pcre::RegEx::Match match = deviceName(argv[index])) device = _B("/dev/") + match[1]; else return Usage(argv[0]); } if (device.empty()) return Usage(argv[0]); // if (!debug) // Posix::CheckError(::daemon(0, 0)); ext::ifdstream uhid(Posix::CheckError(::open(device.c_str(), O_RDONLY))); char buffer[8]; while (uhid.read(buffer, sizeof (buffer))) _forall (int, index, 0, 8) std::printf("0x%08x 0x%08x\n", buffer[3], ~buffer[4] - 0x4); return 0; }