LLEMU (Legacy LCD Emulator) C++ API¶
Note
Additional example code for this module can be found in its Tutorial.
pros::lcd¶
clear¶
Clear the text on the emulated three-button LCD screen.
This function uses the following values of errno
when an error state is reached:
ENXIO
- The LCD has not been initialized. Call initialize first.
Analogous to lcd_clear.
bool pros::lcd::clear ( )
1 2 3 4 5 | void initialize() { pros::lcd::initialize(); pros::lcd::set_text(1, "Hello World!"); pros::lcd::clear(); // No more text will be displayed } |
Returns: true
if the operation was successful, or false
otherwise, setting
errno
values as specified above.
clear_line¶
Clears a line on the emulated three-button LCD screen.
This function uses the following values of errno
when an error state is reached:
ENXIO
- The LCD has not been initialized. Call initialize first.EINVAL
- The line number specified is not in the range [0-7]
Analogous to lcd_clear_line.
bool pros::lcd::clear_line ( std::int16_t line )
1 2 3 4 5 | void initialize() { pros::lcd::initialize(); pros::lcd::set_text(1, "Hello World!"); pros::lcd::clear_line(1); // No more text will be displayed } |
Parameters | |
---|---|
line | The line to clear |
Returns: true
if the operation was successful, or false
otherwise, setting
errno
values as specified above.
initialize¶
Initialize the display to be an emulation of the three-button, UART-based VEX LCD.
Analogous to lcd_initialize.
bool pros::lcd::initialize ( )
void initialize() {
pros::lcd::initialize();
pros::lcd::set_text(1, "Hello World!");
}
Returns: true
if the LCD was successfully initialized, or false
if it has already been initialized.
is_initialized¶
Determines whether the emulated three-button LCD has already been initialized.
Analogous to lcd_is_initialized.
bool pros::lcd::is_initialized ( )
1 2 3 4 5 | void initialize() { pros::lcd::initialize(); std::cout << "Is the LCD initialized?" << pros::is_initialized(); // Will Display True } |
Returns: True if the LCD has been initialized or false if not.
print¶
Displays a formatted string on the emulated three-button LCD screen
This function uses the following values of errno
when an error state is
reached:
ENXIO
- The LCD has not been initialized. Call initialize first.EINVAL
- The line number specified is not in the range [0-7]
Analogous to lcd_print.
template <typename... Params> bool pros::lcd::print( std::int16_t line,
const char* fmt,
Params... args )
1 2 3 4 5 6 7 8 9 10 | void initialize() { pros::lcd::initialize(); } void opcontrol { while (true) { pros::lcd::print(0, "Buttons Bitmap: %d\n", pros::lcd::read_buttons()); delay(20); } } |
Parameters | |
---|---|
line | The line on which to display the text [0-7] |
fmt | Format string |
args | Optional list of arguments for the format string |
Returns: true
if the operation was successful, or false
otherwise, setting
errno
values as specified above.
read_buttons¶
Reads the button status from the emulated three-button LCD.
The value returned is a 3-bit std::integer where 1 0 0
indicates the left button
is pressed, 0 1 0
indicates the center button is pressed, and 0 0 1
indicates the right button is pressed. 0
is returned if no buttons are
currently being pressed.
Note that this function is provided for legacy API compatibility purposes, with the caveat that the V5 touch screen does not actually support pressing multiple points on the screen at the same time.
Analogous to lcd_read_buttons.
std::uint8_t pros::lcd::read_buttons ( )
1 2 3 4 5 6 7 8 9 10 | void initialize() { pros::lcd::initialize(); } void opcontrol() { while (true) { printf("Buttons Bitmap: %d\n", pros::lcd::read_buttons()); delay(20); } } |
Returns: The buttons pressed as a bit mask.
register_btn0_cb¶
Register a callback function for the leftmost button.
When the leftmost button on the emulated three-button LCD is pressed, the user-provided callback function will be invoked.
Analogous to lcd_register_btn0_cb.
void pros::lcd::register_btn0_cb ( lcd_btn_cb_fn_t cb )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | void on_center_button() { static bool pressed = false; pressed = !pressed; if (pressed) { pros::lcd::set_text(2, "I was pressed!"); } else { pros::lcd::clear_line(2); } } void initialize() { pros::lcd::initialize(); pros::lcd::register_btn0_cb(on_center_button); } |
Parameters | |
---|---|
cb | An LCD callback function to be executed by this button press |
register_btn1_cb¶
Register a callback function for the center button.
When the center button on the emulated three-button LCD is pressed, the user-provided callback function will be invoked.
Analogous to lcd_register_btn1_cb.
void pros::lcd::register_btn1_cb ( lcd_btn_cb_fn_t cb )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | void on_center_button() { static bool pressed = false; pressed = !pressed; if (pressed) { pros::lcd::set_text(2, "I was pressed!"); } else { pros::lcd::clear_line(2); } } void initialize() { pros::lcd::initialize(); pros::lcd::register_btn1_cb(on_center_button); } |
Parameters | |
---|---|
cb | An LCD callback function to be executed by this button press |
register_btn2_cb¶
Register a callback function for the rightmost button.
When the rightmost button on the emulated three-button LCD is pressed, the user-provided callback function will be invoked.
Analogous to lcd_register_btn2_cb.
void pros::lcd::register_btn2_cb ( lcd_btn_cb_fn_t cb )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | void on_center_button() { static bool pressed = false; pressed = !pressed; if (pressed) { pros::lcd::set_text(2, "I was pressed!"); } else { pros::lcd::clear_line(2); } } void initialize() { pros::lcd::initialize(); pros::lcd::register_btn2_cb(on_center_button); } |
Parameters | |
---|---|
cb | An LCD callback function to be executed by this button press |
set_text¶
Displays a string on the emulated three-button LCD screen
This function uses the following values of errno
when an error state is reached:
ENXIO
- The LCD has not been initialized. Call initialize first.EINVAL
- The line number specified is not in the range [0-7]
Analogous to lcd_set_text.
bool pros::lcd::set_text ( std::int16_t line,
std::string text )
void initialize() {
pros::lcd::initialize();
pros::lcd::set_text(1, "Hello World!");
}
Parameters | |
---|---|
line | The line on which to display the text [0-7] |
text | The text to display |
Returns: true
if the operation was successful, or false
otherwise, setting
errno
values as specified above.
shutdown¶
Turn off the Legacy LCD Emulator
Calling this function will clear the entire display, and you will not be able to call any further LLEMU functions until another call to initialize.
This function uses the following values of errno
when an error state is reached:
ENXIO
- The LCD has not been initialized. Call initialize first.
Analogous to lcd_shutdown.
bool pros::lcd::shutdown ( )
1 2 3 4 5 | void initialize() { pros::lcd::initialize(); pros::lcd::set_text(1, "Hello World!"); pros::lcd::shutdown(); // All done with the LCD } |
Returns: true
if the operation was successful, or false
otherwise, setting
errno
values as specified above.
set_background_color¶
Changes the color of the LCD background to a provided color expressed in type lv_color_t, or as three values of type uint8_t.
Analogous to lcd_set_background_color.
void set_background_color( lv_color_t color )
set_background_color( std::uint8_t r, std::uint8_t g, std::uint8_t b )
void initialize() {
pros::lcd::initialize();
pros::lcd::set_background_color(COLOR_GOLD);
}
Parameters | |
---|---|
color | A color of type lv_color_t |
r | A value of type uint8_t, with a range of 0 to 255, representing the red value of a color |
g | A value of type uint8_t, with a range of 0 to 255, representing the green value of a color |
b | A value of type uint8_t, with a range of 0 to 255, representing the blue value of a color |
set_text_color¶
Changes the text color of the LCD to a provided color expressed in type lv_color_t, or as three values of type uint8_t.
Analogous to lcd_set_text_color.
void set_text_color( lv_color_t color )
set_text_color( std::uint8_t r, std::uint8_t g, std::uint8_t b )
1 2 3 4 5 | void initialize() { pros::lcd::initialize(); pros::lcd::set_text_color(COLOR_GOLD); pros::lcd::set_text(1, "Hello World!"); } |
Parameters | |
---|---|
color | A color of type lv_color_t |
r | A value of type uint8_t, with a range of 0 to 255, representing the red value of a color |
g | A value of type uint8_t, with a range of 0 to 255, representing the green value of a color |
b | A value of type uint8_t, with a range of 0 to 255, representing the blue value of a color |
Macros¶
LCD_BTN_CENTER¶
Use LCD_BTN_CENTER as a bitmask for determining if the center LCD button was pressed from lcd_read_buttons.
Value: 2
LCD_BTN_LEFT¶
Use LCD_BTN_LEFT as a bitmask for determining if the left LCD button was pressed from lcd_read_buttons.
Value: 4
LCD_BTN_RIGHT¶
Use LCD_BTN_RIGHT as a bitmask for determining if the right LCD button was pressed from lcd_read_buttons.
Value: 1
Typedefs¶
pros::lcd_btn_cb_fn_t¶
typedef void (*lcd_btn_cb_fn_t)(void);
A callback function for a button on the LCD.
This will be called each time its corresponding button is pressed.