Skip to content

Commit

Permalink
fix: 🐛 screen not being cleared first print
Browse files Browse the repository at this point in the history
i initialized screen cleared to the wrong value, and i forgot to clear it
  • Loading branch information
PA055 committed Oct 12, 2024
1 parent c357038 commit a1c3f15
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions include/gamepad/gamepad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Gamepad {
private:
Gamepad(pros::controller_id_e_t id)
: controller(id) {
screens.push_back(defaultScreen);
this->add_screen(defaultScreen);
}

Button m_L1 {}, m_L2 {}, m_R1 {}, m_R2 {}, m_Up {}, m_Down {}, m_Left {}, m_Right {}, m_X {}, m_B {}, m_Y {},
Expand Down Expand Up @@ -142,7 +142,7 @@ class Gamepad {
uint8_t last_printed_line = 0;
uint last_print_time = 0;
uint last_update_time = 0;
bool screenCleared = true;
bool screenCleared = false;
pros::Mutex mut {};
};

Expand Down
8 changes: 4 additions & 4 deletions include/gamepad/screens/abstractScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <optional>
#include <set>
#include <string>
#include <sys/types.h>
#include "pros/misc.h"

namespace gamepad {
Expand All @@ -16,17 +17,16 @@ typedef std::array<std::optional<std::string>, 4> ScreenBuffer;

class AbstractScreen {
public:
AbstractScreen(uint priority)
: priority(priority) {}
AbstractScreen(uint priority) : priority(priority) {}

virtual void update(uint delta_time) {}

virtual ScreenBuffer get_screen(std::set<uint8_t> visible_lines) = 0;

virtual void handle_events(std::set<pros::controller_digital_e_t> button_events) {}

const uint get_priority() { return this->priority; }
private:
uint get_priority() { return this->priority; }
protected:
const uint priority;
};

Expand Down
2 changes: 0 additions & 2 deletions include/gamepad/screens/alertScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class AlertScreen : public AbstractScreen {
void update(uint delta_time);
ScreenBuffer get_screen(std::set<uint8_t> visible_lines);

void handle_events(std::set<pros::controller_digital_e_t> button_events) {}

void add_alerts(uint8_t line, std::string strs, uint32_t duration, std::string rumble = "");
private:
struct AlertBuffer {
Expand Down
6 changes: 3 additions & 3 deletions include/gamepad/screens/defaultScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace gamepad {

class DefaultScreen : public AbstractScreen {
public:
DefaultScreen();
ScreenBuffer get_screen(std::set<uint8_t> visible_lines);
DefaultScreen()
: AbstractScreen(1) {}

void handle_events(std::set<pros::controller_digital_e_t> button_events) {}
ScreenBuffer get_screen(std::set<uint8_t> visible_lines);

void print_line(uint8_t line, std::string str);
void rumble(std::string rumble_pattern);
Expand Down
3 changes: 2 additions & 1 deletion src/gamepad/gamepad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ void Gamepad::updateScreens() {
// theres nothing on this line so we can skip it
if (!this->nextBuffer[line].has_value()) continue;

if (!this->screenCleared) {
if (!this->screenCleared && line != 3) {
this->controller.clear();
screenCleared = true;
this->last_print_time = pros::millis();
return;
}
Expand Down
4 changes: 0 additions & 4 deletions src/gamepad/screens/defaultScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

namespace gamepad {

DefaultScreen::DefaultScreen()
: AbstractScreen(1),
currentBuffer({}) {}

ScreenBuffer DefaultScreen::get_screen(std::set<uint8_t> visible_lines) {
ScreenBuffer output;
const std::lock_guard<pros::Mutex> guard(this->mut);
Expand Down
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "gamepad/gamepad.hpp"
#include "gamepad/screens/alertScreen.hpp"
#include "pros/rtos.hpp"
#include <cstdio>
#include <memory>
#include <string>

Expand All @@ -15,8 +16,9 @@ std::shared_ptr<gamepad::AlertScreen> alerts{};
* to keep execution time for this mode under a few seconds.
*/
void initialize() {
gamepad::master.add_screen(alerts);
gamepad::master.A.onPress("alert", []() { alerts->add_alerts(0, "a very\nimportant\nalert", 3000, "-.-"); });
printf("alert priority: %i\n", alerts->get_priority());
// gamepad::master.add_screen(alerts);
// gamepad::master.A.onPress("alert", []() { alerts->add_alerts(0, "a very\nimportant\nalert", 3000, "-.-"); });
gamepad::master.B.onPress(
"print02", []() { gamepad::master.print_line(0, "the time is\n\n" + std::to_string(pros::millis()) + " ms"); });
gamepad::master.X.onPress("rumble", []() { gamepad::master.rumble("..."); });
Expand Down

0 comments on commit a1c3f15

Please sign in to comment.