-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from PA055/text
feat ✨ Add controller text support
- Loading branch information
Showing
12 changed files
with
584 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,6 @@ temp.errors | |
|
||
# MacOS | ||
.DS_Store | ||
|
||
# Linux | ||
debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#pragma once | ||
|
||
#include "gamepad/event_handler.hpp" // IWYU pragma: export | ||
#include "gamepad/controller.hpp" // IWYU pragma: export | ||
#include "gamepad/gamepad.hpp" // IWYU pragma: export | ||
#include "gamepad/screens/alertScreen.hpp" // IWYU pragma: export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#include <array> | ||
#include <cstdint> | ||
#include <optional> | ||
#include <set> | ||
#include <string> | ||
#include "pros/misc.h" | ||
|
||
namespace gamepad { | ||
|
||
/** | ||
* @brief type for conveying a full screen with the first 3 being the lines | ||
* of text on the controller screen and the last being a rumble pattern | ||
*/ | ||
typedef std::array<std::optional<std::string>, 4> ScreenBuffer; | ||
|
||
/** | ||
* @brief The abstract class for interacting with the controller screen | ||
* | ||
*/ | ||
class AbstractScreen { | ||
public: | ||
AbstractScreen(uint32_t priority) | ||
: priority(priority) {} | ||
|
||
/** | ||
* @brief runs every time the controller's update function is called | ||
* use this if you need to update somthing regardless of if there is an | ||
* available slot in the screen | ||
* | ||
* @param delta_time the time since the last update in milliseconds | ||
*/ | ||
virtual void update(uint32_t delta_time) {} | ||
|
||
/** | ||
* @brief runs if there is an empty line that is available to print | ||
* | ||
* @param visible_lines a set that contains the line numbers of all lines that | ||
* are empty and available for printing | ||
* | ||
* @returns a the lines to be printed, any lines that are not available will be ignored | ||
*/ | ||
virtual ScreenBuffer get_screen(std::set<uint8_t> visible_lines) = 0; | ||
|
||
/** | ||
* @brief a function where button events are pushed, use this to handle button events. | ||
* | ||
* @param button_events a set of the button events that happened this update | ||
*/ | ||
virtual void handle_events(std::set<pros::controller_digital_e_t> button_events) {} | ||
|
||
/** | ||
* @brief returns the priority of the screen | ||
* | ||
* @important it is not reccomended to override this function | ||
*/ | ||
uint32_t get_priority() { return this->priority; } | ||
protected: | ||
const uint32_t priority; | ||
}; | ||
|
||
} // namespace gamepad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <deque> | ||
#include <optional> | ||
#include <string> | ||
#include "abstractScreen.hpp" | ||
#include "pros/rtos.hpp" | ||
#include "gamepad/screens/abstractScreen.hpp" | ||
|
||
namespace gamepad { | ||
|
||
/** | ||
* @brief a screen that sends alerts to the controller, duration of alerts can be customized | ||
* | ||
* @note priority: UINT32_MAX - 100 | ||
*/ | ||
class AlertScreen : public AbstractScreen { | ||
public: | ||
AlertScreen() | ||
: AbstractScreen(UINT32_MAX - 100) {} | ||
|
||
/** | ||
* @brief updates the alert loop | ||
* | ||
* @param delta_time the time since the last update | ||
*/ | ||
void update(uint32_t delta_time); | ||
|
||
/** | ||
* @brief return the next alert to print if there is space for it on the screen | ||
* | ||
* @param visible_lines a set that contains the line numbers of all lines that | ||
* are empty and available for printing | ||
* | ||
* @returns a the lines to be printed, any lines that are not available will be ignored | ||
*/ | ||
ScreenBuffer get_screen(std::set<uint8_t> visible_lines); | ||
|
||
/** | ||
* @brief add an alert to the alert queue, to be printed as soon as there is an available space | ||
* | ||
* @param line the line number to print the alert at (0-2) | ||
* @param strs the string to print on the controller, "\n" to go to the next line | ||
* lines that go over 2 will be cropped out | ||
* @param duration how long the alert should persist on the screen | ||
* @param rumble A string consisting of the characters '.', '-', and ' ', where dots are short rumbles, | ||
* dashes are long rumbles, and spaces are pauses. Maximum supported length is 8 characters. | ||
*/ | ||
void add_alerts(uint8_t line, std::string strs, uint32_t duration, std::string rumble = ""); | ||
private: | ||
struct AlertBuffer { | ||
ScreenBuffer screen; | ||
uint32_t duration; | ||
}; | ||
|
||
std::deque<AlertBuffer> screen_buffer {}; | ||
std::optional<AlertBuffer> screen_contents {}; | ||
uint32_t line_set_time = 0; | ||
pros::Mutex mut {}; | ||
}; | ||
|
||
} // namespace gamepad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include "gamepad/screens/abstractScreen.hpp" | ||
#include "pros/rtos.hpp" | ||
|
||
namespace gamepad { | ||
|
||
/** | ||
* @brief A basic screen that allows basic prints, similar to pros controller api | ||
* | ||
* @note The gamepad class has wrappers around this class | ||
* @note priority: 1 | ||
*/ | ||
class DefaultScreen : public AbstractScreen { | ||
public: | ||
DefaultScreen() | ||
: AbstractScreen(1) {} | ||
|
||
/** | ||
* @brief returns any lines that have space to print on the controller | ||
* | ||
* @param visible_lines a set that contains the line numbers of all lines that | ||
* are empty and available for printing | ||
* | ||
* @returns a the lines to be printed, any lines that are not available will be ignored | ||
*/ | ||
ScreenBuffer get_screen(std::set<uint8_t> visible_lines); | ||
|
||
/** | ||
* @brief print a line to the console like pros | ||
* | ||
* @param line the line number to print the string on (0-2) | ||
* @param str the string to print onto the controller (\n to go to the next line) | ||
*/ | ||
void print_line(uint8_t line, std::string str); | ||
|
||
/** | ||
* makes the controller rumble like pros | ||
* | ||
* @param rumble_pattern A string consisting of the characters '.', '-', and ' ', where dots are short rumbles, | ||
* dashes are long rumbles, and spaces are pauses. Maximum supported length is 8 characters. | ||
*/ | ||
void rumble(std::string rumble_pattern); | ||
private: | ||
ScreenBuffer currentBuffer {}; | ||
pros::Mutex mut {}; | ||
}; | ||
|
||
} // namespace gamepad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.