Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop-pros-4' into pros-4/docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard-Stump committed Mar 29, 2023
2 parents 853cd4a + 23239c2 commit 74fe2af
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 117 deletions.
10 changes: 10 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ MFLAGS=-mcpu=cortex-a9 -mfpu=neon-fp16 -mfloat-abi=softfp -Os -g
CPPFLAGS=-D_POSIX_THREADS -D_UNIX98_THREAD_MUTEX_ATTRIBUTES -D_POSIX_TIMERS -D_POSIX_MONOTONIC_CLOCK
GCCFLAGS=-ffunction-sections -fdata-sections -fdiagnostics-color -funwind-tables

# Check if the llemu files in libvgl exist. If they do, define macros that the
# llemu headers in the kernel repo can use to conditionally include the libvgl
# versions
ifneq (,$(wildcard ./include/liblvgl/llemu.h))
CPPFLAGS += -D_PROS_INCLUDE_LIBLVGL_LLEMU_H
endif
ifneq (,$(wildcard ./include/liblvgl/llemu.hpp))
CPPFLAGS += -D_PROS_INCLUDE_LIBLVGL_LLEMU_HPP
endif

WARNFLAGS+=-Wno-psabi

SPACE := $() $()
Expand Down
2 changes: 2 additions & 0 deletions include/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "pros/gps.h"
#include "pros/imu.h"
#include "pros/link.h"
#include "pros/llemu.h"
#include "pros/misc.h"
#include "pros/motors.h"
#include "pros/optical.h"
Expand All @@ -69,6 +70,7 @@
#include "pros/gps.hpp"
#include "pros/imu.hpp"
#include "pros/link.hpp"
#include "pros/llemu.hpp"
#include "pros/misc.hpp"
#include "pros/motor_group.hpp"
#include "pros/motors.hpp"
Expand Down
55 changes: 55 additions & 0 deletions include/pros/llemu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef _PROS_LLEMU_H_
#define _PROS_LLEMU_H_

// TODO:? Should there be weak symbols for the C api in here as well?

#include "stdint.h"

#ifdef __cplusplus
extern "C" {
namespace pros {
namespace c {
#endif//__cplusplus

/**
* 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 lcd_initialize() first.
* EINVAL - The line number specified is not in the range [0-7]
*
* \param line
* The line on which to display the text [0-7]
* \param fmt
* Format string
* \param ...
* Optional list of arguments for the format string
*
* \return True if the operation was successful, or false otherwise, setting
* errno values as specified above.
*/
bool __attribute__((weak)) lcd_print(int16_t line, const char* fmt, ...) {
return false;
}

#ifdef __cplusplus
} // namespace c
} // namespace pros
} // extern "C"
#endif//__cplusplus


/******************************************************************************/
/** LLEMU Conditional Include **/
/** **/
/** When the libvgl versions of llemu.h is present, common.mk will **/
/** define a macro which lets this file know that liblvgl's llemu.h is **/
/** present. If it is, we conditionally include it so that it gets **/
/** included into api.h. **/
/******************************************************************************/
#ifdef _PROS_INCLUDE_LIBLVGL_LLEMU_H
#include "liblvgl/llemu.h"
#endif

#endif // _PROS_LLEMU_H_
154 changes: 154 additions & 0 deletions include/pros/llemu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#ifndef _PROS_LLEMU_HPP_
#define _PROS_LLEMU_HPP_

#include <cstdint>
#include <string>

/******************************************************************************/
/** LLEMU Weak Stubs **/
/** **/
/** These functions allow main.cpp to be compiled without LVGL present **/
/******************************************************************************/
namespace pros {
namespace lcd {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
namespace {
template <typename T>
T convert_args(T arg) {
return arg;
}
const char* convert_args(const std::string& arg) {
return arg.c_str();
}
} // namespace
#pragma GCC diagnostic pop

using lcd_btn_cb_fn_t = void (*)(void);

/**
* 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 lcd_initialize() first.
* EINVAL - The line number specified is not in the range [0-7]
*
* \param line
* The line on which to display the text [0-7]
* \param text
* The text to display
*
* \return True if the operation was successful, or false otherwise, setting
* errno values as specified above.
*/
extern __attribute__((weak)) bool set_text(std::int16_t line, std::string text);

/**
* Clears the contents of a line of 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 lcd_initialize() first.
* EINVAL - The line number specified is not in the range [0-7]
*
* \param line
* The line to clear
*
* \return True if the operation was successful, or false otherwise, setting
* errno values as specified above.
*/
extern __attribute__((weak)) bool clear_line(std::int16_t line);

/**
* Creates an emulation of the three-button, UART-based VEX LCD on the display.
*
* \return True if the LCD was successfully initialized, or false if it has
* already been initialized.
*/
extern __attribute__((weak)) bool initialize(void);

/**
* Gets the button status from the emulated three-button LCD.
*
* The value returned is a 3-bit 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.
*
* \return The buttons pressed as a bit mask
*/
extern __attribute__((weak)) std::uint8_t read_buttons(void);

/**
* Registers 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.
*
* \param cb
* A callback function of type lcd_btn_cb_fn_t(void (*cb)(void))
*/
extern __attribute__((weak)) void register_btn1_cb(lcd_btn_cb_fn_t cb);

/**
* Checks whether the emulated three-button LCD has already been initialized.
*
* \return True if the LCD has been initialized or false if not.
*/
extern __attribute__((weak)) bool is_initialized(void);

/**
* 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 lcd_initialize() first.
* EINVAL - The line number specified is not in the range [0-7]
*
* \param line
* The line on which to display the text [0-7]
* \param fmt
* Format string
* \param ...
* Optional list of arguments for the format string
*
* \return True if the operation was successful, or false otherwise, setting
* errno values as specified above.
*/
template <typename... Params>
bool print(std::int16_t line, const char* fmt, Params... args) {
return pros::c::lcd_print(line, fmt, convert_args(args)...);
}

#ifndef LCD_BTN_LEFT
#define LCD_BTN_LEFT 4
#endif

#ifndef LCD_BTN_CENTER
#define LCD_BTN_CENTER 2
#endif

#ifndef LCD_BTN_RIGHT
#define LCD_BTN_RIGHT 1
#endif
} // namespace lcd
} // namespace pros

/******************************************************************************/
/** LLEMU Conditional Include **/
/** **/
/** When the libvgl versions of llemu.hpp is present, common.mk will **/
/** define a macro which lets this file know that liblvgl's llemu.hpp is **/
/** present. If it is, we conditionally include it so that it gets **/
/** included into api.h. **/
/******************************************************************************/
#ifdef _PROS_INCLUDE_LIBLVGL_LLEMU_HPP
#include "liblvgl/llemu.hpp"
#endif

#endif // _PROS_LLEMU_HPP_
118 changes: 1 addition & 117 deletions include/pros/screen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,123 +422,7 @@ const char* convert_args(const std::string& arg) {

} // namespace screen

/******************************************************************************/
/** LLEMU Weak Stubs **/
/** **/
/** These functions allow main.cpp to be compiled without LVGL present **/
/******************************************************************************/
namespace lcd {
using lcd_btn_cb_fn_t = void (*)(void);

/**
* 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 lcd_initialize() first.
* EINVAL - The line number specified is not in the range [0-7]
*
* \param line
* The line on which to display the text [0-7]
* \param text
* The text to display
*
* \return True if the operation was successful, or false otherwise, setting
* errno values as specified above.
*/
extern __attribute__((weak)) bool set_text(std::int16_t line, std::string text);

/**
* Clears the contents of a line of 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 lcd_initialize() first.
* EINVAL - The line number specified is not in the range [0-7]
*
* \param line
* The line to clear
*
* \return True if the operation was successful, or false otherwise, setting
* errno values as specified above.
*/
extern __attribute__((weak)) bool clear_line(std::int16_t line);

/**
* Creates an emulation of the three-button, UART-based VEX LCD on the display.
*
* \return True if the LCD was successfully initialized, or false if it has
* already been initialized.
*/
extern __attribute__((weak)) bool initialize(void);

/**
* Gets the button status from the emulated three-button LCD.
*
* The value returned is a 3-bit 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.
*
* \return The buttons pressed as a bit mask
*/
extern __attribute__((weak)) std::uint8_t read_buttons(void);

/**
* Registers 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.
*
* \param cb
* A callback function of type lcd_btn_cb_fn_t(void (*cb)(void))
*/
extern __attribute__((weak)) void register_btn1_cb(lcd_btn_cb_fn_t cb);

/**
* Checks whether the emulated three-button LCD has already been initialized.
*
* \return True if the LCD has been initialized or false if not.
*/
extern __attribute__((weak)) bool is_initialized(void);

/**
* 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 lcd_initialize() first.
* EINVAL - The line number specified is not in the range [0-7]
*
* \param line
* The line on which to display the text [0-7]
* \param fmt
* Format string
* \param ...
* Optional list of arguments for the format string
*
* \return True if the operation was successful, or false otherwise, setting
* errno values as specified above.
*/
template <typename... Params>
extern __attribute__((weak)) bool print(std::int16_t line, const char* fmt, Params... args);

#ifndef LCD_BTN_LEFT
#define LCD_BTN_LEFT 4
#endif

#ifndef LCD_BTN_CENTER
#define LCD_BTN_CENTER 2
#endif

#ifndef LCD_BTN_RIGHT
#define LCD_BTN_RIGHT 1
#endif
} // namespace LCD

} // namespace pros

extern __attribute__((weak)) void lvgl_init() {}
Expand Down

0 comments on commit 74fe2af

Please sign in to comment.