finish wings logic

This commit is contained in:
ary 2023-10-16 18:25:18 -04:00
parent 68cd006814
commit 32c74df3fc
2 changed files with 34 additions and 2 deletions

View File

@ -12,9 +12,11 @@ class Wings {
void toggleLeft(int value);
void toggleRight(int value);
void openFor(double duration);
int getState();
private:
std::uint8_t wingsopen;
int left_wing_state;
int right_wing_state;
};
#endif

View File

@ -4,25 +4,33 @@
using namespace globals;
Wings::Wings() {
left_wing_state = 0;
right_wing_state = 0;
close();
};
void Wings::open() {
left_wing_piston.set_value(1);
left_wing_state = 1;
right_wing_piston.set_value(1);
right_wing_state = 1;
};
void Wings::close() {
left_wing_piston.set_value(0);
left_wing_state = 0;
right_wing_piston.set_value(0);
right_wing_state = 0;
};
void Wings::toggleLeft(int value) {
left_wing_piston.set_value(value);
left_wing_state = value;
};
void Wings::toggleRight(int value) {
right_wing_piston.set_value(value);
right_wing_state = value;
};
void Wings::openFor(double duration) {
@ -31,5 +39,27 @@ void Wings::openFor(double duration) {
close();
};
/*
returns int
0 -> Both wings closed
1 -> Right wing open
2 -> Left wing open
3 -> Both wings open
*/
int Wings::getState() {
if (left_wing_state == 0 && right_wing_state == 0) {
return 0;
} else if (left_wing_state == 0 && right_wing_state == 1) {
return 1;
} else if (left_wing_state == 1 && right_wing_state == 0) {
return 2;
} else if (left_wing_state == 1 && right_wing_state == 1) {
return 3;
} else {
return 0;
}
}