Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

mainclass.cpp 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "mainclass.hh"
  2. #include <iostream>
  3. #include <libgen.h>
  4. #include <sysexits.h>
  5. #include <climits>
  6. #include <getopt.h>
  7. MainClass::MainClass(int argc, char* argv[])
  8. : argc_(argc)
  9. , argv_(argv)
  10. {
  11. }
  12. int MainClass::usage()
  13. {
  14. std::cerr << "Usage: " << basename(argv_[0]) <<
  15. " [--device DEVICE|--device=DEVICE|-e DEVICE]" <<
  16. " [--up OUTPUT|--up=OUTPUT|-u OUTPUT]" <<
  17. " [--down OUTPUT|--down=OUPUT|-d OUTPUT]" <<
  18. " [--sleep MS|--sleep=MS|-s MS]" <<
  19. " [--help|-h]" << std::endl;
  20. std::cerr << std::endl << "Controls the output pins of a PiFace digital IO."
  21. << std::endl << std::endl;
  22. std::cerr << "--device \tSwitch to the provided device."
  23. << std::endl << "--up \t\tEnable the provided ouput pin."
  24. << std::endl << "--down \t\tDisable the provided output pin."
  25. << std::endl << "--sleep \tSleep for the provided amount of milliseconds."
  26. << std::endl << "--help \t\tDisplay this message."
  27. << std::endl << std::endl;
  28. std::cerr << "OUTPUT \t: The output pin to enable/disable. 0 <= OUTPUT <= 7."
  29. << std::endl << "MS \t: The number of milliseconds to sleep. 0 <= MS <= "
  30. << UINT_MAX << "."
  31. << std::endl << "DEVICE \t: The device number. Default is 0. "
  32. "0 <= DEVICE <= 4" << std::endl;
  33. return EX_USAGE;
  34. }
  35. bool MainClass::build_actions_()
  36. {
  37. option opts[] = {
  38. {"device", 1, 0, 'e'},
  39. {"up", 1, 0, 'u'},
  40. {"down", 1, 0, 'd'},
  41. {"sleep", 1, 0, 's'},
  42. {"help", 0, 0, 'h'},
  43. {0, 0, 0, 0}
  44. };
  45. int opt;
  46. extern int optind;
  47. while ((opt = getopt_long(argc_, argv_, "e:u:d:s:h", opts, 0)) != -1)
  48. {
  49. if (opt == 'e')
  50. {
  51. }
  52. else if (opt == 'u')
  53. {
  54. }
  55. else if (opt == 'd')
  56. {
  57. }
  58. else if (opt == 's')
  59. {
  60. }
  61. else
  62. return false;
  63. }
  64. return optind == argc_;
  65. }
  66. int MainClass::execute()
  67. {
  68. if (argc_ <= 2 || !build_actions_())
  69. return usage();
  70. return 0;
  71. }