Browse Source

code facto; debug code

tags/v1.0
Robin Thoni 10 years ago
parent
commit
aa93895278
2 changed files with 16 additions and 21 deletions
  1. 15
    20
      src/mainclass.cpp
  2. 1
    1
      src/mainclass.hh

+ 15
- 20
src/mainclass.cpp View File

78
       actions_.push_back([arg]() -> bool
78
       actions_.push_back([arg]() -> bool
79
           {
79
           {
80
           pifacedigital_close(get_current_device());
80
           pifacedigital_close(get_current_device());
81
-          return pifacedigital_open(set_current_device(arg)) != -1;
81
+          return set_current_device(arg);
82
           });
82
           });
83
     }
83
     }
84
-    else if (opt == 'u')
84
+    else if (opt == 'u' || opt == 'd')
85
     {
85
     {
86
       if (arg > 7)
86
       if (arg > 7)
87
         return bad_value_();
87
         return bad_value_();
88
-      actions_.push_back([arg]() -> bool
88
+      actions_.push_back([arg, opt]() -> bool
89
           {
89
           {
90
           if (get_current_device() == -1 &&
90
           if (get_current_device() == -1 &&
91
-            pifacedigital_open(set_current_device(arg)) == -1)
91
+            !set_current_device(arg))
92
             return false;
92
             return false;
93
-          pifacedigital_write_reg(up_pin(arg), OUTPUT, get_current_device());
94
-          return true;
95
-          });
96
-    }
97
-    else if (opt == 'd')
98
-    {
99
-      if (arg > 7)
100
-        return bad_value_();
101
-      actions_.push_back([arg]() -> bool
102
-          {
103
-          if (get_current_device() == -1 &&
104
-            pifacedigital_open(set_current_device(arg)) == -1)
105
-            return false;
106
-          pifacedigital_write_reg(down_pin(arg), OUTPUT, get_current_device());
93
+          pifacedigital_write_reg(opt == 'u' ? up_pin(arg) : down_pin(arg),
94
+            OUTPUT, get_current_device());
95
+          std::cout << get_pins() << std::endl;
107
           return true;
96
           return true;
108
           });
97
           });
109
     }
98
     }
150
   return current_device_;
139
   return current_device_;
151
 }
140
 }
152
 
141
 
153
-int MainClass::set_current_device(int c)
142
+bool MainClass::set_current_device(int c)
154
 {
143
 {
155
-  return (current_device_ = c);
144
+  if (pifacedigital_open((current_device_ = c)) == -1)
145
+  {
146
+    std::cerr << std::endl;
147
+    return false;
148
+  }
149
+  pins_ = pifacedigital_read_reg(c, OUTPUT);
150
+  return true;
156
 }
151
 }
157
 
152
 
158
 uint8_t MainClass::get_pins()
153
 uint8_t MainClass::get_pins()

+ 1
- 1
src/mainclass.hh View File

11
     int execute();
11
     int execute();
12
 
12
 
13
     static int get_current_device();
13
     static int get_current_device();
14
-    static int set_current_device(int c);
14
+    static bool set_current_device(int c);
15
 
15
 
16
     static uint8_t get_pins();
16
     static uint8_t get_pins();
17
     static uint8_t up_pin(uint8_t pin);
17
     static uint8_t up_pin(uint8_t pin);

Loading…
Cancel
Save