Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Added pros button support for piston::toggle #255

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion include/EZ-Template/piston.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
#pragma once

#include "api.h"
#include "pros/misc.h"

namespace ez {
class Piston {
Expand Down Expand Up @@ -61,15 +62,33 @@ class Piston {
*/
void button_toggle(int toggle);

/**
* One button toggle for the piston.
*
* \param toggle
* an input button
*/
void button_toggle(pros::controller_digital_e_t toggle);

/**
* Two buttons trigger the piston. Active is enabled, deactive is disabled.
*
* \param active
* sets piston to true
* \param active
* \param deactive
* sets piston to false
*/
void buttons(int active, int deactive);

/**
* Two buttons trigger the piston. Active is enabled, deactive is disabled.
*
* \param active
* sets piston to true
* \param deactive
* sets piston to false
*/
void buttons(pros::controller_digital_e_t active, pros::controller_digital_e_t deactive);

private:
bool reversed = false;
Expand Down
12 changes: 12 additions & 0 deletions src/EZ-Template/piston.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#include "EZ-Template/piston.hpp"
#include "pros/misc.h"
#include "util.hpp"

using namespace ez;

Expand Down Expand Up @@ -37,10 +39,20 @@ void Piston::button_toggle(int toggle) {
last_press = toggle;
}

// Toggle for user control, takes in a pros button
void Piston::button_toggle(pros::controller_digital_e_t toggle) {
button_toggle(master.get_digital(toggle));
}

// Two button control for piston
void Piston::buttons(int active, int deactive) {
if (active && !get())
set(true);
else if (deactive && get())
set(false);
}

// Two button control for piston, takes in pros buttons
void Piston::buttons(pros::controller_digital_e_t active, pros::controller_digital_e_t deactive) {
buttons(master.get_digital(active), master.get_digital(deactive));
}
Loading