From 0cf7a6f53dbbb41d47872669d2380332bfd57aef Mon Sep 17 00:00:00 2001 From: Jess Zarchi Date: Sun, 8 Sep 2024 00:08:30 -0700 Subject: [PATCH] Added page blank remove #174 --- include/EZ-Template/sdcard.hpp | 26 +++++++++++++++++++ src/EZ-Template/sdcard.cpp | 47 ++++++++++++++++++++++------------ src/main.cpp | 4 +++ 3 files changed, 60 insertions(+), 17 deletions(-) diff --git a/include/EZ-Template/sdcard.hpp b/include/EZ-Template/sdcard.hpp index 85ea9951..bdad016b 100644 --- a/include/EZ-Template/sdcard.hpp +++ b/include/EZ-Template/sdcard.hpp @@ -70,8 +70,34 @@ void limit_switch_lcd_initialize(pros::adi::DigitalIn* right_limit, pros::adi::D */ void limitSwitchTask(); +/** + * Returns the current blank page that is on. Negative value means the current page isn't blank. + */ int page_blank_current(); + +/** + * Checks if this blank page is open. If this page doesn't exist, this will create it. + */ bool page_blank_is_on(int page); + +/** + * Removes the blank page if it exists, and previous ones. + */ +void page_blank_remove(int page); + +/** + * Removes all blank pages. + */ +void page_blank_remove_all(); + +/** + * Removes the current amount of blank pages. + */ +int page_blank_amount(); + +/** + * Current amount of blank pages. + */ extern int amount_of_blank_pages; } // namespace as } // namespace ez diff --git a/src/EZ-Template/sdcard.cpp b/src/EZ-Template/sdcard.cpp index 6a324f0d..3f877981 100644 --- a/src/EZ-Template/sdcard.cpp +++ b/src/EZ-Template/sdcard.cpp @@ -50,12 +50,7 @@ void auton_selector_initialize() { } } -void page_up() { - auton_selector.last_auton_page_current = auton_selector.auton_page_current; - if (auton_selector.auton_page_current == auton_selector.auton_count - 1) - auton_selector.auton_page_current = 0; - else - auton_selector.auton_page_current++; +void print_page() { if (((auton_selector.auton_count - 1 - amount_of_blank_pages) - auton_selector.auton_page_current) >= 0) { auto_sd_update(); auton_selector.selected_auton_print(); @@ -68,22 +63,22 @@ void page_up() { auton_selector.last_auton_page_current = auton_selector.auton_page_current; } +void page_up() { + if (util::sgn(page_blank_current()) == -1) auton_selector.last_auton_page_current = auton_selector.auton_page_current; + if (auton_selector.auton_page_current == auton_selector.auton_count - 1) + auton_selector.auton_page_current = 0; + else + auton_selector.auton_page_current++; + print_page(); +} + void page_down() { - auton_selector.last_auton_page_current = auton_selector.auton_page_current; + if (util::sgn(page_blank_current()) == -1) auton_selector.last_auton_page_current = auton_selector.auton_page_current; if (auton_selector.auton_page_current == 0) auton_selector.auton_page_current = auton_selector.auton_count - 1; else auton_selector.auton_page_current--; - if (((auton_selector.auton_count - 1 - amount_of_blank_pages) - auton_selector.auton_page_current) >= 0) { - auto_sd_update(); - auton_selector.selected_auton_print(); - } else { - for (int i = 0; i < 8; i++) - pros::lcd::clear_line(i); - screen_print("Page " + std::to_string(auton_selector.auton_page_current + 1) + " - Blank page " + std::to_string(page_blank_current() + 1)); - } - if (page_blank_current() < 0) - auton_selector.last_auton_page_current = auton_selector.auton_page_current; + print_page(); } int page_blank_current() { @@ -102,6 +97,24 @@ bool page_blank_is_on(int page) { return false; } +void page_blank_remove(int page) { + if (amount_of_blank_pages >= page + 1) { + auton_selector.auton_count -= amount_of_blank_pages; + amount_of_blank_pages -= page + 1; + auton_selector.auton_count += amount_of_blank_pages; + } + auton_selector.auton_page_current = auton_selector.last_auton_page_current; + print_page(); +} + +void page_blank_remove_all() { + page_blank_remove(amount_of_blank_pages - 1); +} + +int page_blank_amount() { + return amount_of_blank_pages; +} + void initialize() { // Initialize auto selector and LLEMU pros::lcd::initialize(); diff --git a/src/main.cpp b/src/main.cpp index 79352bff..e0a3b885 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -193,6 +193,10 @@ void ez_template_etxras() { } chassis.pid_tuner_iterate(); // Allow PID Tuner to iterate + } else { + // Remove all blank pages when connected to a comp switch + if (ez::as::page_blank_amount() > 0) + ez::as::page_blank_remove_all(); } }