-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
169 additions
and
18 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "api.h" | ||
|
||
class Piston { | ||
public: | ||
pros::ADIDigitalOut piston; | ||
Piston(int input_port, bool default_state = false); | ||
void set(bool input); | ||
bool get(); | ||
void button_toggle(int toggle); | ||
void button(int active, int deactive); | ||
|
||
private: | ||
bool reversed = false; | ||
bool current = false; | ||
int last_press = 0; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "EZ-Template/piston.hpp" | ||
|
||
class PistonGroup { | ||
public: | ||
std::vector<Piston> pistons; | ||
PistonGroup(std::vector<int> input_ports, bool default_state = false); | ||
void set(bool input); | ||
bool get(); | ||
void button_toggle(int toggle); | ||
void button(int active, int deactive); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "EZ-Template/piston.hpp" | ||
|
||
// Constructor for one piston | ||
Piston::Piston(int input_port, bool default_state) | ||
: piston(input_port, default_state) { | ||
reversed = default_state; | ||
} | ||
|
||
// Set piston | ||
void Piston::set(bool input) { | ||
piston.set_value(reversed ? !input : input); | ||
current = input; | ||
} | ||
|
||
// Get the current state | ||
bool Piston::get() { return current; } | ||
|
||
// Toggle for user control | ||
void Piston::button_toggle(int toggle) { | ||
if (toggle && !last_press) { | ||
set(!get()); | ||
} | ||
last_press = toggle; | ||
} | ||
|
||
// Two button control for piston | ||
void Piston::button(int active, int deactive) { | ||
if (active && !get()) | ||
set(true); | ||
else if (deactive && get()) | ||
set(false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "EZ-Template/piston_group.hpp" | ||
|
||
// Constructor for multiple pistons | ||
PistonGroup::PistonGroup(std::vector<int> input_ports, bool default_state) { | ||
for (auto i : input_ports) { | ||
Piston temp(i, default_state); | ||
pistons.push_back(temp); | ||
} | ||
} | ||
|
||
void PistonGroup::set(bool input) { | ||
for (auto i : pistons) { | ||
i.set(input); | ||
} | ||
} | ||
|
||
// Get the current state | ||
bool PistonGroup::get() { return pistons[0].get(); } | ||
|
||
// Toggle for user control | ||
void PistonGroup::button_toggle(int toggle) { | ||
for (auto i : pistons) { | ||
i.button_toggle(toggle); | ||
} | ||
} | ||
|
||
// Two button control for piston | ||
void PistonGroup::button(int active, int deactive) { | ||
for (auto i : pistons) { | ||
i.button(active, deactive); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters