Browse Source

added read argument; changed executable name; fixed makefile

tags/v1.1.0^0
Robin Thoni 6 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
 *.lib
3
 *.lib
4
 *.swp
4
 *.swp
5
 *~
5
 *~
6
-camotion-pifaceo
6
+camotion-piface

+ 3
- 3
Makefile View File

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

+ 23
- 4
src/mainclass.cpp View File

20
   std::cerr << "Usage: " << basename(argv_[0]) << std::endl <<
20
   std::cerr << "Usage: " << basename(argv_[0]) << std::endl <<
21
     " [--device DEVICE|--device=DEVICE|-e DEVICE]" << std::endl <<
21
     " [--device DEVICE|--device=DEVICE|-e DEVICE]" << std::endl <<
22
     " [--up OUTPUT|--up=OUTPUT|-u OUTPUT]" << std::endl <<
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
     " [--sleep MS|--sleep=MS|-s MS]" << std::endl <<
25
     " [--sleep MS|--sleep=MS|-s MS]" << std::endl <<
25
     " [--help|-h]" << std::endl <<
26
     " [--help|-h]" << std::endl <<
26
     " [--version|-v]" << std::endl;
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
     << std::endl << std::endl;
29
     << std::endl << std::endl;
29
   std::cerr << "--device \tSwitch to the provided device."
30
   std::cerr << "--device \tSwitch to the provided device."
30
     << std::endl << "--up \t\tEnable the provided ouput pin."
31
     << std::endl << "--up \t\tEnable the provided ouput pin."
31
     << std::endl << "--down \t\tDisable the provided output pin."
32
     << std::endl << "--down \t\tDisable the provided output pin."
33
+    << std::endl << "--read \t\tRead and print the provided input pin."
32
     << std::endl << "--sleep \tSleep for the provided amount of milliseconds."
34
     << std::endl << "--sleep \tSleep for the provided amount of milliseconds."
33
     << std::endl << "--help \t\tDisplay this message."
35
     << std::endl << "--help \t\tDisplay this message."
34
     << std::endl << "--version \tDisplay version."
36
     << std::endl << "--version \tDisplay version."
35
     << std::endl << std::endl;
37
     << std::endl << std::endl;
36
   std::cerr << "OUTPUT \t: The output pin to enable/disable. 0 <= OUTPUT <= 7."
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
     << std::endl << "MS \t: The number of milliseconds to sleep. 0 <= MS <= "
40
     << std::endl << "MS \t: The number of milliseconds to sleep. 0 <= MS <= "
38
     << UINT_MAX << "."
41
     << UINT_MAX << "."
39
     << std::endl << "DEVICE \t: The device number. Default is 0. "
42
     << std::endl << "DEVICE \t: The device number. Default is 0. "
56
     {"device", 1, 0, 'e'},
59
     {"device", 1, 0, 'e'},
57
     {"up", 1, 0, 'u'},
60
     {"up", 1, 0, 'u'},
58
     {"down", 1, 0, 'd'},
61
     {"down", 1, 0, 'd'},
62
+    {"read", 1, 0, 'r'},
59
     {"sleep", 1, 0, 's'},
63
     {"sleep", 1, 0, 's'},
60
     {"help", 0, 0, 'h'},
64
     {"help", 0, 0, 'h'},
61
     {"version", 0, 0, 'v'},
65
     {"version", 0, 0, 'v'},
65
   extern int optind;
69
   extern int optind;
66
   extern char* optarg;
70
   extern char* optarg;
67
   char* endptr;
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
     long int arg = optarg ? strtol(optarg, &endptr, 10) : 0;
74
     long int arg = optarg ? strtol(optarg, &endptr, 10) : 0;
71
     if (arg < 0)
75
     if (arg < 0)
96
           return true;
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
     else if (opt == 's')
118
     else if (opt == 's')
100
     {
119
     {
101
       if (arg > INT_MAX)
120
       if (arg > INT_MAX)
109
     }
128
     }
110
     else if (opt == 'v')
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
       actions_.clear();
132
       actions_.clear();
114
       return true;
133
       return true;
115
     }
134
     }

Loading…
Cancel
Save