From 21da73308b1e0403b31ab96238c3dfd29cafc253 Mon Sep 17 00:00:00 2001 From: HakopZarikyan <39071041+HakopZ@users.noreply.github.com> Date: Fri, 7 Jan 2022 00:42:29 -0800 Subject: [PATCH] Added limit switch for lcd --- include/EZ-Template/api.hpp | 1 + include/EZ-Template/pre_auto_selector.hpp | 22 +++++++++++++ src/EZ-Template/pre_auto_selector.cpp | 38 +++++++++++++++++++++++ src/main.cpp | 11 +++---- 4 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 include/EZ-Template/pre_auto_selector.hpp create mode 100644 src/EZ-Template/pre_auto_selector.cpp diff --git a/include/EZ-Template/api.hpp b/include/EZ-Template/api.hpp index 71bb03ef..18648270 100644 --- a/include/EZ-Template/api.hpp +++ b/include/EZ-Template/api.hpp @@ -12,3 +12,4 @@ file, You can obtain one at http://mozilla.org/MPL/2.0/. #include "EZ-Template/drive/drive.hpp" #include "EZ-Template/sdcard.hpp" #include "EZ-Template/util.hpp" +#include "EZ-Template/pre_auto_selector.hpp" diff --git a/include/EZ-Template/pre_auto_selector.hpp b/include/EZ-Template/pre_auto_selector.hpp new file mode 100644 index 00000000..f55e017d --- /dev/null +++ b/include/EZ-Template/pre_auto_selector.hpp @@ -0,0 +1,22 @@ +#pragma once +#include "main.h" + +namespace ez +{ +extern pros::ADIDigitalIn* left_limit_switch; +extern pros::ADIDigitalIn* right_limit_switch; +/** +* Initialize two limitswithces to change pages on the lcd +* +* @param left_limit_port +* port for the left limit switch +* @param right_limit_port +* port for the right limit switch +*/ +void limit_switch_lcd_initialize(int left_limit_port, int right_limit_port); + +/** +* pre_auto_task +*/ +extern pros::Task limit_switch_task; +} diff --git a/src/EZ-Template/pre_auto_selector.cpp b/src/EZ-Template/pre_auto_selector.cpp new file mode 100644 index 00000000..22292db2 --- /dev/null +++ b/src/EZ-Template/pre_auto_selector.cpp @@ -0,0 +1,38 @@ +#include "pre_auto_selector.hpp" + +namespace ez +{ + pros::ADIDigitalIn* left_limit_switch = nullptr; + pros::ADIDigitalIn* right_limit_switch = nullptr; + void limit_switch_lcd_initialize(int left_limit_port, int right_limit_port) + { + if(left_limit_port == -1 || right_limit_port == -1) + { + limit_switch_task.suspend(); + return; + } + left_limit_switch = new pros::ADIDigitalIn(left_limit_port); + right_limit_switch = new pros::ADIDigitalIn(right_limit_port); + limit_switch_task.resume(); + } + + void limitSwitchTask() + { + while(true) + { + if(left_limit_switch || right_limit_switch) + { + if(left_limit_switch->get_new_press()) + { + ez::as::page_down(); + } + else if(right_limit_switch->get_new_press()) + { + ez::as::page_up(); + } + } + pros::delay(20); + } + } + pros::Task limit_switch_task(limitSwitchTask, nullptr); +} diff --git a/src/main.cpp b/src/main.cpp index eacf234e..0d5913dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,7 @@ Drive chassis ( // eg. if your drive is 84:36 where the 36t is powered, your RATIO would be 2.333. // eg. if your drive is 36:60 where the 60t is powered, your RATIO would be 0.6. ,2 - + // Uncomment if using tracking wheels /* @@ -56,9 +56,8 @@ Drive chassis ( void initialize() { // Print our branding over your terminal :D ez::print_ez_template(); - pros::delay(500); // Stop the user from doing anything while legacy ports configure. - + ez::limit_switch_lcd_initialize(-1, -1); //limit switch for lcd // Configure your chassis controls chassis.toggle_modify_curve_with_controller(true); // Enables modifying the controller curve with buttons on the joysticks chassis.set_active_brake(0); // Sets the active brake kP. We recommend 0.1. @@ -127,9 +126,9 @@ void competition_initialize() { void autonomous() { chassis.reset_gyro(); // Reset gyro position to 0 chassis.reset_drive_sensor(); // Reset drive sensors to 0 - chassis.set_drive_brake(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency. + chassis.set_drive_brake(MOTOR_BRAKE_HOLD); // Set motors to hold. This helps autonomous consistency. - ez::as::auton_selector.call_selected_auton(); // Calls selected auton from autonomous selector. + ez::as::auton_selector.call_selected_auton(); // Calls selected auton from autonomous selector. } @@ -152,7 +151,7 @@ void opcontrol() { chassis.set_drive_brake(MOTOR_BRAKE_COAST); while (true) { - + chassis.tank(); // Tank control // chassis.arcade_standard(ez::SPLIT); // Standard split arcade // chassis.arcade_standard(ez::SINGLE); // Standard single arcade