#include "mainclass.hh" #include #include #include #include #include MainClass::MainClass(int argc, char* argv[]) : argc_(argc) , argv_(argv) { } int MainClass::usage() { std::cerr << "Usage: " << basename(argv_[0]) << " [--device DEVICE|--device=DEVICE|-e DEVICE]" << " [--up OUTPUT|--up=OUTPUT|-u OUTPUT]" << " [--down OUTPUT|--down=OUPUT|-d OUTPUT]" << " [--sleep MS|--sleep=MS|-s MS]" << " [--help|-h]" << std::endl; std::cerr << std::endl << "Controls the output pins of a PiFace digital IO." << std::endl << std::endl; std::cerr << "--device \tSwitch to the provided device." << std::endl << "--up \t\tEnable the provided ouput pin." << std::endl << "--down \t\tDisable the provided output pin." << std::endl << "--sleep \tSleep for the provided amount of milliseconds." << std::endl << "--help \t\tDisplay this message." << std::endl << std::endl; std::cerr << "OUTPUT \t: The output pin to enable/disable. 0 <= OUTPUT <= 7." << std::endl << "MS \t: The number of milliseconds to sleep. 0 <= MS <= " << UINT_MAX << "." << std::endl << "DEVICE \t: The device number. Default is 0. " "0 <= DEVICE <= 4" << std::endl; return EX_USAGE; } bool MainClass::build_actions_() { option opts[] = { {"device", 1, 0, 'e'}, {"up", 1, 0, 'u'}, {"down", 1, 0, 'd'}, {"sleep", 1, 0, 's'}, {"help", 0, 0, 'h'}, {0, 0, 0, 0} }; int opt; extern int optind; while ((opt = getopt_long(argc_, argv_, "e:u:d:s:h", opts, 0)) != -1) { if (opt == 'e') { } else if (opt == 'u') { } else if (opt == 'd') { } else if (opt == 's') { } else return false; } return optind == argc_; } int MainClass::execute() { if (argc_ <= 2 || !build_actions_()) return usage(); return 0; }