Bladeren bron

fixed opening wring device

tags/v1.0^0
Robin Thoni 9 jaren geleden
bovenliggende
commit
154710e500
2 gewijzigde bestanden met toevoegingen van 5 en 27 verwijderingen
  1. 5
    22
      src/mainclass.cpp
  2. 0
    5
      src/mainclass.hh

+ 5
- 22
src/mainclass.cpp Bestand weergeven

@@ -8,7 +8,6 @@
8 8
 #include <pifacedigital.h>
9 9
 
10 10
 int MainClass::current_device_ = -1;
11
-uint8_t MainClass::pins_ = 0;
12 11
 
13 12
 MainClass::MainClass(int argc, char* argv[])
14 13
   : argc_(argc)
@@ -88,13 +87,12 @@ bool MainClass::build_actions_()
88 87
       actions_.push_back([arg, opt]() -> bool
89 88
           {
90 89
           if (get_current_device() == -1 &&
91
-            !set_current_device(arg))
90
+            !set_current_device(0))
92 91
             return false;
92
+          std::cout << "Setting pin " << arg << " " <<
93
+            (opt == 'u' ? "up" : "down") << std::endl;
93 94
           pifacedigital_write_bit(opt == 'u', arg, OUTPUT,
94 95
             get_current_device());
95
-          /*pifacedigital_write_reg(opt == 'u' ? up_pin(arg) : down_pin(arg),
96
-            OUTPUT, get_current_device());
97
-          std::cout << std::hex << (int)get_pins() << std::endl;*/
98 96
           return true;
99 97
           });
100 98
     }
@@ -104,6 +102,7 @@ bool MainClass::build_actions_()
104 102
         return bad_value_();
105 103
       actions_.push_back([arg]() -> bool
106 104
           {
105
+          std::cout << "Sleeping " << (arg * 1000) << " ms" << std::endl;
107 106
           usleep(arg * 1000);
108 107
           return true;
109 108
           });
@@ -143,27 +142,11 @@ int MainClass::get_current_device()
143 142
 
144 143
 bool MainClass::set_current_device(int c)
145 144
 {
145
+  std::cout << "Switching to device " << c << std::endl;
146 146
   if (pifacedigital_open((current_device_ = c)) == -1)
147 147
   {
148 148
     std::cerr << std::endl;
149 149
     return false;
150 150
   }
151
-  pifacedigital_enable_interrupts();
152
-  pins_ = pifacedigital_read_reg(c, OUTPUT);
153 151
   return true;
154 152
 }
155
-
156
-uint8_t MainClass::get_pins()
157
-{
158
-  return pins_;
159
-}
160
-
161
-uint8_t MainClass::up_pin(uint8_t pin)
162
-{
163
-  return (pins_ |= (1 << pin));
164
-}
165
-
166
-uint8_t MainClass::down_pin(uint8_t pin)
167
-{
168
-  return (pins_ &= ~(1 << pin));
169
-}

+ 0
- 5
src/mainclass.hh Bestand weergeven

@@ -13,10 +13,6 @@ class MainClass
13 13
     static int get_current_device();
14 14
     static bool set_current_device(int c);
15 15
 
16
-    static uint8_t get_pins();
17
-    static uint8_t up_pin(uint8_t pin);
18
-    static uint8_t down_pin(uint8_t pin);
19
-
20 16
   private:
21 17
     bool build_actions_();
22 18
     bool bad_value_();
@@ -25,6 +21,5 @@ class MainClass
25 21
     std::vector<std::function<bool()>> actions_;
26 22
 
27 23
     static int current_device_;
28
-    static uint8_t pins_;
29 24
 };
30 25
 #endif /* !MAINCLASS_HH */

Laden…
Annuleren
Opslaan