|
@@ -78,32 +78,21 @@ bool MainClass::build_actions_()
|
78
|
78
|
actions_.push_back([arg]() -> bool
|
79
|
79
|
{
|
80
|
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
|
86
|
if (arg > 7)
|
87
|
87
|
return bad_value_();
|
88
|
|
- actions_.push_back([arg]() -> bool
|
|
88
|
+ actions_.push_back([arg, opt]() -> bool
|
89
|
89
|
{
|
90
|
90
|
if (get_current_device() == -1 &&
|
91
|
|
- pifacedigital_open(set_current_device(arg)) == -1)
|
|
91
|
+ !set_current_device(arg))
|
92
|
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
|
96
|
return true;
|
108
|
97
|
});
|
109
|
98
|
}
|
|
@@ -150,9 +139,15 @@ int MainClass::get_current_device()
|
150
|
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
|
153
|
uint8_t MainClass::get_pins()
|