1#include "electronic/controller.h"
10void Controller::notifier() {
13 if (
partner.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_Y)) {
17 if (
partner.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_X)) {
21 if (
partner.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_UP)) {
25 if (
partner.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_RIGHT)) {
30 if (
partner.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_R1)) {
35void Controller::switchControl() {
37 if (
controller.get_digital_new_press(pros::E_CONTROLLER_DIGITAL_LEFT) &&
partner.is_connected()) {
47 partner.print(0, 0,
"Partner Controller");
51void Controller::notify_motor_disconnect(
void *param) {
52 std::vector<pros::Motor> all_motors = pros::Motor::get_all_devices();
53 std::vector<unsigned char> disconnected;
54 std::vector<unsigned char> last_disconnected;
55 bool is_notified =
false;
56 uint32_t now = pros::millis();
58 constexpr int TASK_DELAY_MILLIS = 1000;
59 constexpr int CONTROLLER_DELAY_MILLIS = 50;
62 std::string disc_motors =
"MD: ";
63 bool are_motors_disconnected =
false;
65 for (pros::Motor i : all_motors) {
66 if (!i.is_installed()) {
67 unsigned char port = i.get_port();
68 disconnected.push_back(port);
69 disc_motors = disc_motors +
" " + std::to_string(port);
70 are_motors_disconnected =
true;
74 if (are_motors_disconnected) {
76 pros::delay(CONTROLLER_DELAY_MILLIS);
79 pros::delay(CONTROLLER_DELAY_MILLIS);
81 if (disconnected.size() > last_disconnected.size()) {
83 }
else if (disconnected.size() < last_disconnected.size()) {
85 }
else if (!are_motors_disconnected && is_notified) {
89 last_disconnected = disconnected;
91 pros::Task::delay_until(&now, TASK_DELAY_MILLIS);
95Controller::Controller() { ; }
pros::Controller controller(pros::E_CONTROLLER_MASTER)
pros::Controller partner(pros::E_CONTROLLER_PARTNER)