Browse Source

added read argument; changed executable name; fixed makefile

tags/v1.1.0^0
Robin Thoni 7 years ago
parent
commit
c5a7562640
3 changed files with 27 additions and 8 deletions
  1. 1
    1
      .gitignore
  2. 3
    3
      Makefile
  3. 23
    4
      src/mainclass.cpp

+ 1
- 1
.gitignore View File

@@ -3,4 +3,4 @@
3 3
 *.lib
4 4
 *.swp
5 5
 *~
6
-camotion-pifaceo
6
+camotion-piface

+ 3
- 3
Makefile View File

@@ -5,14 +5,14 @@ LDLIBS = -lpifacedigital -lmcp23s17
5 5
 OBJ = $(addprefix src/, $(SRC:.cpp=.o))
6 6
 
7 7
 
8
-all: camotion-pifaceo
8
+all: camotion-piface
9 9
 
10 10
 install: all
11 11
 	cp camotion-pifaceo /usr/local/bin/
12 12
 
13
-camotion-pifaceo: $(OBJ)
13
+camotion-piface: $(OBJ)
14 14
 	$(LINK.cpp) $(OBJ) $(OUTPUT_OPTION) $(LDLIBS)
15 15
 
16 16
 clean:
17 17
 	rm -f $(OBJ)
18
-	rm -f camotion-pifaceo
18
+	rm -f camotion-piface

+ 23
- 4
src/mainclass.cpp View File

@@ -20,20 +20,23 @@ int MainClass::usage()
20 20
   std::cerr << "Usage: " << basename(argv_[0]) << std::endl <<
21 21
     " [--device DEVICE|--device=DEVICE|-e DEVICE]" << std::endl <<
22 22
     " [--up OUTPUT|--up=OUTPUT|-u OUTPUT]" << std::endl <<
23
-    " [--down OUTPUT|--down=OUPUT|-d OUTPUT]" << std::endl <<
23
+    " [--down OUTPUT|--down=OUTPUT|-d OUTPUT]" << std::endl <<
24
+    " [--read INPUT|--read=INPUT|-r INPUT]" << std::endl <<
24 25
     " [--sleep MS|--sleep=MS|-s MS]" << std::endl <<
25 26
     " [--help|-h]" << std::endl <<
26 27
     " [--version|-v]" << std::endl;
27
-  std::cerr << std::endl << "Controls the output pins of a PiFace digital IO."
28
+  std::cerr << std::endl << "Controls the output pins and read pins of a PiFace digital IO."
28 29
     << std::endl << std::endl;
29 30
   std::cerr << "--device \tSwitch to the provided device."
30 31
     << std::endl << "--up \t\tEnable the provided ouput pin."
31 32
     << std::endl << "--down \t\tDisable the provided output pin."
33
+    << std::endl << "--read \t\tRead and print the provided input pin."
32 34
     << std::endl << "--sleep \tSleep for the provided amount of milliseconds."
33 35
     << std::endl << "--help \t\tDisplay this message."
34 36
     << std::endl << "--version \tDisplay version."
35 37
     << std::endl << std::endl;
36 38
   std::cerr << "OUTPUT \t: The output pin to enable/disable. 0 <= OUTPUT <= 7."
39
+    << std::endl << "INPUT \t: The input pin to read. 0 <= INPUT <= 7."
37 40
     << std::endl << "MS \t: The number of milliseconds to sleep. 0 <= MS <= "
38 41
     << UINT_MAX << "."
39 42
     << std::endl << "DEVICE \t: The device number. Default is 0. "
@@ -56,6 +59,7 @@ bool MainClass::build_actions_()
56 59
     {"device", 1, 0, 'e'},
57 60
     {"up", 1, 0, 'u'},
58 61
     {"down", 1, 0, 'd'},
62
+    {"read", 1, 0, 'r'},
59 63
     {"sleep", 1, 0, 's'},
60 64
     {"help", 0, 0, 'h'},
61 65
     {"version", 0, 0, 'v'},
@@ -65,7 +69,7 @@ bool MainClass::build_actions_()
65 69
   extern int optind;
66 70
   extern char* optarg;
67 71
   char* endptr;
68
-  while ((opt = getopt_long(argc_, argv_, "e:u:d:s:hv", opts, 0)) != -1)
72
+  while ((opt = getopt_long(argc_, argv_, "e:u:d:r:s:hv", opts, 0)) != -1)
69 73
   {
70 74
     long int arg = optarg ? strtol(optarg, &endptr, 10) : 0;
71 75
     if (arg < 0)
@@ -96,6 +100,21 @@ bool MainClass::build_actions_()
96 100
           return true;
97 101
           });
98 102
     }
103
+    else if (opt == 'r')
104
+    {
105
+      if (arg > 7)
106
+        return bad_value_();
107
+      actions_.push_back([arg, opt]() -> bool
108
+          {
109
+          if (get_current_device() == -1 &&
110
+            !set_current_device(0))
111
+            return false;
112
+          uint8_t status = pifacedigital_read_bit(arg, INPUT, get_current_device());
113
+          std::cout << "Pin " << arg << " value: " <<
114
+            (int) status << std::endl;
115
+          return true;
116
+          });
117
+    }
99 118
     else if (opt == 's')
100 119
     {
101 120
       if (arg > INT_MAX)
@@ -109,7 +128,7 @@ bool MainClass::build_actions_()
109 128
     }
110 129
     else if (opt == 'v')
111 130
     {
112
-      std::cout << "camotion-piface 1.0" << std::endl;
131
+      std::cout << "camotion-piface 1.1" << std::endl;
113 132
       actions_.clear();
114 133
       return true;
115 134
     }

Loading…
Cancel
Save