-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🚧 Start work on automatic motor-controller bindings
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#pragma once | ||
|
||
#include "gamepad/event_handler.hpp" // IWYU pragma: export | ||
#include "gamepad/bindings.hpp" // IWYU pragma: export | ||
#include "gamepad/controller.hpp" // IWYU pragma: export |
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,9 @@ | ||
#pragma once | ||
|
||
#include "controller.hpp" | ||
|
||
namespace Gamepad::Bindings { | ||
|
||
bool motorTwoButton(std::string name, pros::Motor motor, Button& fwd_button, Button& rev_button); | ||
bool motorOneButton(std::string name, pros::Motor motor, Button& toggle_button, uint32_t speed = 127); | ||
} // namespace Gamepad::Bindings |
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,45 @@ | ||
#include <memory> | ||
|
||
#include "bindings.hpp" | ||
#include "controller.hpp" | ||
|
||
namespace Gamepad::Bindings { | ||
bool motorTwoButton(std::string name, pros::Motor motor, Button& fwd_button, Button& rev_button) { | ||
enum states { FWD, REV, NONE }; | ||
|
||
bool ret_val = true; | ||
auto state = std::make_shared<states>(NONE); | ||
ret_val &= fwd_button.onPress("Bindings" + name, [=]() { | ||
*state = FWD; | ||
motor.move(127); | ||
}); | ||
ret_val &= fwd_button.onRelease("Bindings" + name, [=]() { | ||
if (*state == FWD) { | ||
*state = NONE; | ||
motor.move(0); | ||
} | ||
}); | ||
ret_val &= rev_button.onPress("Bindings" + name, [=]() { | ||
*state = REV; | ||
motor.move(-127); | ||
}); | ||
ret_val &= rev_button.onRelease("Bindings" + name, [=]() { | ||
if (*state == REV) { | ||
*state = NONE; | ||
motor.move(0); | ||
} | ||
}); | ||
return ret_val; | ||
} | ||
|
||
bool motorOneButton(std::string name, pros::Motor motor, Button& toggle_button, uint32_t speed) { | ||
bool ret_val = true; | ||
auto state = std::make_shared<bool>(false); | ||
ret_val &= toggle_button.onPress("Bindings" + name, [=]() { | ||
if (*state) motor.move(speed); | ||
else motor.move(0); | ||
*state = !*state; | ||
}); | ||
return ret_val; | ||
} | ||
} // namespace Gamepad::Bindings |