Browse Source

fixed opening wring device

tags/v1.0^0
Robin Thoni 9 years ago
parent
commit
154710e500
2 changed files with 5 additions and 27 deletions
  1. 5
    22
      src/mainclass.cpp
  2. 0
    5
      src/mainclass.hh

+ 5
- 22
src/mainclass.cpp View File

8
 #include <pifacedigital.h>
8
 #include <pifacedigital.h>
9
 
9
 
10
 int MainClass::current_device_ = -1;
10
 int MainClass::current_device_ = -1;
11
-uint8_t MainClass::pins_ = 0;
12
 
11
 
13
 MainClass::MainClass(int argc, char* argv[])
12
 MainClass::MainClass(int argc, char* argv[])
14
   : argc_(argc)
13
   : argc_(argc)
88
       actions_.push_back([arg, opt]() -> bool
87
       actions_.push_back([arg, opt]() -> bool
89
           {
88
           {
90
           if (get_current_device() == -1 &&
89
           if (get_current_device() == -1 &&
91
-            !set_current_device(arg))
90
+            !set_current_device(0))
92
             return false;
91
             return false;
92
+          std::cout << "Setting pin " << arg << " " <<
93
+            (opt == 'u' ? "up" : "down") << std::endl;
93
           pifacedigital_write_bit(opt == 'u', arg, OUTPUT,
94
           pifacedigital_write_bit(opt == 'u', arg, OUTPUT,
94
             get_current_device());
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
           return true;
96
           return true;
99
           });
97
           });
100
     }
98
     }
104
         return bad_value_();
102
         return bad_value_();
105
       actions_.push_back([arg]() -> bool
103
       actions_.push_back([arg]() -> bool
106
           {
104
           {
105
+          std::cout << "Sleeping " << (arg * 1000) << " ms" << std::endl;
107
           usleep(arg * 1000);
106
           usleep(arg * 1000);
108
           return true;
107
           return true;
109
           });
108
           });
143
 
142
 
144
 bool MainClass::set_current_device(int c)
143
 bool MainClass::set_current_device(int c)
145
 {
144
 {
145
+  std::cout << "Switching to device " << c << std::endl;
146
   if (pifacedigital_open((current_device_ = c)) == -1)
146
   if (pifacedigital_open((current_device_ = c)) == -1)
147
   {
147
   {
148
     std::cerr << std::endl;
148
     std::cerr << std::endl;
149
     return false;
149
     return false;
150
   }
150
   }
151
-  pifacedigital_enable_interrupts();
152
-  pins_ = pifacedigital_read_reg(c, OUTPUT);
153
   return true;
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 View File

13
     static int get_current_device();
13
     static int get_current_device();
14
     static bool set_current_device(int c);
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
   private:
16
   private:
21
     bool build_actions_();
17
     bool build_actions_();
22
     bool bad_value_();
18
     bool bad_value_();
25
     std::vector<std::function<bool()>> actions_;
21
     std::vector<std::function<bool()>> actions_;
26
 
22
 
27
     static int current_device_;
23
     static int current_device_;
28
-    static uint8_t pins_;
29
 };
24
 };
30
 #endif /* !MAINCLASS_HH */
25
 #endif /* !MAINCLASS_HH */

Loading…
Cancel
Save