Skip to content

Commit

Permalink
Added page blank remove #174
Browse files Browse the repository at this point in the history
  • Loading branch information
ssejrog committed Sep 8, 2024
1 parent a22b831 commit 0cf7a6f
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
26 changes: 26 additions & 0 deletions include/EZ-Template/sdcard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 30 additions & 17 deletions src/EZ-Template/sdcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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() {
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit 0cf7a6f

Please sign in to comment.